/** * Partial re-order of backlog items plus update of children * * Define the priorities of some children of a given Backlog Item * * <br> * Example: * <pre> * "order": { * "ids" : [123, 789, 1001], * "direction": "before", * "compared_to": 456 * } * </pre> * * <br> * Resulting order will be: <pre>[…, 123, 789, 1001, 456, …]</pre> * * <br> * Add example: * <pre> * "add": [ * { * "id": 34 * "remove_from": 56 * }, * ... * ] * </pre> * * <br> * Will remove element id 34 from 56 children and add it to current backlog_items children * * @url PATCH {id}/children * * @param int $id Id of the Backlog Item * @param \Tuleap\AgileDashboard\REST\v1\OrderRepresentation $order Order of the children {@from body} * @param array $add Ids to add to backlog_items content {@from body} * * @throws 400 * @throws 404 * @throws 409 */ protected function patch($id, OrderRepresentation $order = null, array $add = null) { $artifact = $this->getArtifact($id); $user = $this->getCurrentUser(); try { $indexed_children_ids = $this->getChildrenArtifactIds($user, $artifact); if ($add) { $this->resources_patcher->startTransaction(); $to_add = $this->resources_patcher->removeArtifactFromSource($user, $add); if (count($to_add)) { $validator = new PatchAddRemoveValidator($indexed_children_ids, new PatchAddBacklogItemsValidator($this->artifact_factory, $this->tracker_factory->getPossibleChildren($artifact->getTracker()), $id)); $backlog_items_ids = $validator->validate($id, array(), $to_add); $this->artifactlink_updater->updateArtifactLinks($user, $artifact, $backlog_items_ids, array()); $indexed_children_ids = array_flip($backlog_items_ids); } $this->resources_patcher->commit(); } if ($order) { $order->checkFormat($order); $order_validator = new OrderValidator($indexed_children_ids); $order_validator->validate($order); $this->resources_patcher->updateArtifactPriorities($order, $id, null); } } catch (IdsFromBodyAreNotUniqueException $exception) { throw new RestException(409, $exception->getMessage()); } catch (OrderIdOutOfBoundException $exception) { throw new RestException(409, $exception->getMessage()); } catch (ArtifactCannotBeChildrenOfException $exception) { throw new RestException(409, $exception->getMessage()); } catch (Tracker_Artifact_Exception_CannotRankWithMyself $exception) { throw new RestException(400, $exception->getMessage()); } catch (\Exception $exception) { throw new RestException(400, $exception->getMessage()); } }
public function getValidatedArtifactsIdsToAddOrRemoveFromContent(PFUser $user, Planning_Milestone $milestone, $remove, $add) { $validator = new PatchAddRemoveValidator($this->getIndexedLinkedArtifactIds($user, $milestone), new PatchAddContentValidator($this, $milestone, $user)); return $validator->validate($milestone->getArtifactId(), $remove, $add); }