wiki:CloneBuild

Version 7 (modified by 233051, 37 hours ago) ( diff )

--

Clone an existing build

Actors

User, Admin

Scenario

  1. The user opens the completed builds page, opens the details popup for a build

  1. The user clicks on the "CLONE & EDIT" button and is redirected to the forge page

  1. The forge is populated with identical data as the build that was cloned
BEGIN;

SELECT b.id
  b.id,
  b.name,
  b.description,
  b.total_price,
  b.is_approved
FROM builds b
WHERE id = $buildId
LIMIT 1;

INSERT INTO builds (user_id, name, created_at, description, total_price, is_approved)
VALUES (
  $userId,
  $buildToClone_name || ' (copy)',
  CURRENT_TIMESTAMP,
  $buildToClone.description,
  $buildToClone.total_price,
  false
)
RETURNING id AS $new_build_id;

SELECT component_id
FROM build_components
WHERE build_id = $buildId;

INSERT INTO build_components (build_id, component_id)
VALUES ($new_build_id, $existing_component_id);

COMMIT;
BEGIN;

SELECT
  b.id,
  b.user_id,
  b.is_approved,
  b.name,
  b.description,
  b.total_price,
FROM builds b
WHERE b.id = $1
  AND b.user_id = $userId
LIMIT 1;

SELECT
  bc.component_id
FROM build_components bc
WHERE bc.build_id = $buildId;

COMMIT;

Attachments (3)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.