diff --git a/src/deepclone/controller/DeepcloneController.php b/src/deepclone/controller/DeepcloneController.php --- a/src/deepclone/controller/DeepcloneController.php +++ b/src/deepclone/controller/DeepcloneController.php @@ -12,9 +12,11 @@ return new Aphront404Response(); } - $task = id(new ManiphestTaskQuery()) + $query = new ManiphestTaskQuery(); + $task = $query ->setViewer($viewer) ->withPHIDs(array($task_id)) + ->withOpenSubtasks(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, @@ -29,83 +31,14 @@ return new Aphront404Response(); } + $transactions = id(new ManiphestTransactionQuery()) + ->setViewer($request->getUser()) + ->withObjectPHIDs(mpull([$task], 'getPHID')) + ->needComments(true) + ->execute(); + if ($request->isFormPost()) { - return $this->triggerTransaction($request, $task); - // $properties = $provider->readFormValuesFromRequest($request); - // list($errors, $issues, $properties) = $provider->processEditForm( - // $request, - // $properties); - - // $xactions = array(); - - // if (!$errors) { - // if ($is_new) { - // if (!phutil_nonempty_string($config->getProviderType())) { - // $config->setProviderType($provider->getProviderType()); - // } - // if (!phutil_nonempty_string($config->getProviderDomain())) { - // $config->setProviderDomain($provider->getProviderDomain()); - // } - // } - - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN) - // ->setNewValue($request->getInt('allowLogin', 0)); - - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION) - // ->setNewValue($request->getInt('allowRegistration', 0)); - - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_LINK) - // ->setNewValue($request->getInt('allowLink', 0)); - - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK) - // ->setNewValue($request->getInt('allowUnlink', 0)); - - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS) - // ->setNewValue($request->getInt('trustEmails', 0)); - - // if ($provider->supportsAutoLogin()) { - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN) - // ->setNewValue($request->getInt('autoLogin', 0)); - // } - - // foreach ($properties as $key => $value) { - // $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) - // ->setTransactionType( - // PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY) - // ->setMetadataValue('auth:property', $key) - // ->setNewValue($value); - // } - - // if ($is_new) { - // $config->save(); - // } - - // $editor = id(new PhabricatorAuthProviderConfigEditor()) - // ->setActor($viewer) - // ->setContentSourceFromRequest($request) - // ->setContinueOnNoEffect(true); - - // try { - // $editor->applyTransactions($config, $xactions); - // $next_uri = $config->getURI(); - - // return id(new AphrontRedirectResponse())->setURI($next_uri); - // } catch (Exception $ex) { - // $validation_exception = $ex; - // } - // } + return $this->triggerTransaction($request, $task, $transactions); } else { return $this->buildForm($task); } @@ -121,8 +54,7 @@ ->addCheckbox( 'copy_comments', 1, - pht('Copy all the comments of the task/s to the new task/s'), - ) + pht('Copy all the comments of the task/s to the new task/s')) ) ->appendChild( id(new AphrontFormCheckboxControl()) @@ -130,8 +62,7 @@ ->addCheckbox( 'deep_clone', 1, - 'Create a clone of all the sub tasks of this task', - ) + 'Create a clone of all the sub tasks of this task') ); $handle = $this->getHandle($task); @@ -178,12 +109,58 @@ return $handle; } - private function triggerTransaction(AphrontRequest $request, ManiphestTask $task) { + private function triggerTransaction(AphrontRequest $request, ManiphestTask $task, array $transactions) { $deepCloneRaw = $request->getStr('deep_clone'); $deepClone = $deepCloneRaw === '1'; $copyCommentsRaw = $request->getStr('copy_comments'); $copyComments = $copyCommentsRaw === '1'; - throw new Exception("Deep Clone $deepClone $deepCloneRaw Copy Comments $copyComments $copyCommentsRaw"); + $taskClone = new ManiphestTask(); + + $taskClone->setTitle($task->getTitle()); + $taskClone->setDescription($task->getDescription()); + $taskClone->setAuthorPHID($task->getAuthorPHID()); + $taskClone->setOwnerPHID($task->getOwnerPHID()); + $taskClone->setStatus($task->getStatus()); + $taskClone->setPriority(ManiphestTaskPriority::getDefaultPriority()); + $taskClone->setSubtype($task->getSubtype()); + $taskClone->setViewPolicy($task->getViewPolicy()); + $taskClone->setEditPolicy($task->getEditPolicy()); + + $taskClone->save(); + + $xactions[] = id(new ManiphestTransaction()) + ->setTransactionType(PhabricatorCoreCreateTransaction::TRANSACTIONTYPE); + $xactions[] = id(new ManiphestTransaction()) + ->setTransactionType(ManiphestTaskPriorityTransaction::TRANSACTIONTYPE) + ->setNewValue( + $task->getPriorityKeyword()); + + foreach ($transactions as &$transaction) { + if ($transaction->getTransactionType() !== 'core:comment') { + continue; + } + + if ($copyComments === false) { + continue; + } + + $transactionClone = id(new ManiphestTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT); + + $transactionClone->attachComment( + id(new ManiphestTransactionComment()) + ->setContent($transaction->getComment()->getContent())); + + $xactions[] = $transactionClone; + } + + id(new ManiphestTransactionEditor()) + ->setActor($this->getViewer()) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->applyTransactions($taskClone, $xactions); + + return id(new AphrontRedirectResponse())->setURI($taskClone->getURI()); } }