3 final class ProjectCreateConduitAPIMethod
extends ProjectConduitAPIMethod
{
5 public function getAPIMethodName() {
6 return 'project.create';
9 public function getMethodDescription() {
10 return pht('Create a project.');
13 public function getMethodStatus() {
14 return self
::METHOD_STATUS_FROZEN
;
17 public function getMethodStatusDescription() {
19 'This method is frozen and will eventually be deprecated. New code '.
20 'should use "project.edit" instead.');
23 protected function defineParamTypes() {
25 'name' => 'required string',
26 'members' => 'optional list<phid>',
27 'icon' => 'optional string',
28 'color' => 'optional string',
29 'tags' => 'optional list<string>',
33 protected function defineReturnType() {
37 protected function execute(ConduitAPIRequest
$request) {
38 $user = $request->getUser();
40 $this->requireApplicationCapability(
41 ProjectCreateProjectsCapability
::CAPABILITY
,
44 $project = PhabricatorProject
::initializeNewProject($user);
45 $type_name = PhabricatorProjectNameTransaction
::TRANSACTIONTYPE
;
47 $name = $request->getValue('name');
48 if ($name === null ||
!strlen(name
)) {
49 throw new Exception(pht('Field "name" must be non-empty.'));
52 $members = $request->getValue('members');
53 if ($members === null) {
58 $xactions[] = id(new PhabricatorProjectTransaction())
59 ->setTransactionType($type_name)
62 if ($request->getValue('icon')) {
63 $xactions[] = id(new PhabricatorProjectTransaction())
65 PhabricatorProjectIconTransaction
::TRANSACTIONTYPE
)
66 ->setNewValue($request->getValue('icon'));
69 if ($request->getValue('color')) {
70 $xactions[] = id(new PhabricatorProjectTransaction())
72 PhabricatorProjectColorTransaction
::TRANSACTIONTYPE
)
73 ->setNewValue($request->getValue('color'));
76 if ($request->getValue('tags')) {
77 $xactions[] = id(new PhabricatorProjectTransaction())
79 PhabricatorProjectSlugsTransaction
::TRANSACTIONTYPE
)
80 ->setNewValue($request->getValue('tags'));
83 $xactions[] = id(new PhabricatorProjectTransaction())
84 ->setTransactionType(PhabricatorTransactions
::TYPE_EDGE
)
87 PhabricatorProjectProjectHasMemberEdgeType
::EDGECONST
)
90 '+' => array_fuse($members),
93 $editor = id(new PhabricatorProjectTransactionEditor())
95 ->setContinueOnNoEffect(true)
96 ->setContentSource($request->newContentSource());
98 $editor->applyTransactions($project, $xactions);
100 return $this->buildProjectInfoDictionary($project);