diff --git a/src/applications/project/conduit/ConduitAPI_project_create_Method.php b/src/applications/project/conduit/ConduitAPI_project_create_Method.php new file mode 100644 --- /dev/null +++ b/src/applications/project/conduit/ConduitAPI_project_create_Method.php @@ -0,0 +1,80 @@ + 'required string', + 'members' => 'optional list', + ); + } + + public function defineReturnType() { + return 'dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR_VALIDATION' => 'Error validating transaction.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + + $user = $request->getUser(); + + $this->requireApplicationCapability( + ProjectCapabilityCreateProjects::CAPABILITY); + + $project = PhabricatorProject::initializeNewProject($user); + + $e_name = true; + $type_name = PhabricatorProjectTransaction::TYPE_NAME; + $v_name = $project->getName(); + $validation_exception = null; + + $xactions = array(); + $v_name = $request->getValue('name'); + + $xactions[] = id(new PhabricatorProjectTransaction()) + ->setTransactionType($type_name) + ->setNewValue($v_name); + + $members = array($user->getPHID()) + $request->getValue('members'); + + // add all the members, beginning with the creator + foreach ($members as $member) { + $project->setIsUserMember($member, true); + + $xactions[] = id(new PhabricatorProjectTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) + ->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER) + ->setNewValue( + array( + '+' => array($member => $member), + )); + } + + $editor = id(new PhabricatorProjectTransactionEditor()) + ->setActor($user) + ->setContinueOnNoEffect(true) + ->setContentSourceFromRequest($request); + try { + $editor->applyTransactions($project, $xactions); + } catch (PhabricatorApplicationTransactionValidationException $ex) { + $validation_exception = $ex; + $e_name = $ex->getShortMessage($type_name); + throw new ConduitException('ERR_VALIDATION'); + } + + return $this->buildProjectInfoDictionary($project); + } + +}