@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class ProjectCreateConduitAPIMethod extends ProjectConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'project.create';
7 }
8
9 public function getMethodDescription() {
10 return pht('Create a project.');
11 }
12
13 public function getMethodStatus() {
14 return self::METHOD_STATUS_FROZEN;
15 }
16
17 public function getMethodStatusDescription() {
18 return pht(
19 'This method is frozen and will eventually be deprecated. New code '.
20 'should use "project.edit" instead.');
21 }
22
23 protected function defineParamTypes() {
24 return array(
25 'name' => 'required string',
26 'members' => 'optional list<phid>',
27 'icon' => 'optional string',
28 'color' => 'optional string',
29 'tags' => 'optional list<string>',
30 );
31 }
32
33 protected function defineReturnType() {
34 return 'dict';
35 }
36
37 protected function execute(ConduitAPIRequest $request) {
38 $user = $request->getUser();
39
40 $this->requireApplicationCapability(
41 ProjectCreateProjectsCapability::CAPABILITY,
42 $user);
43
44 $project = PhabricatorProject::initializeNewProject($user);
45 $type_name = PhabricatorProjectNameTransaction::TRANSACTIONTYPE;
46 $members = $request->getValue('members');
47 $xactions = array();
48
49 $xactions[] = id(new PhabricatorProjectTransaction())
50 ->setTransactionType($type_name)
51 ->setNewValue($request->getValue('name'));
52
53 if ($request->getValue('icon')) {
54 $xactions[] = id(new PhabricatorProjectTransaction())
55 ->setTransactionType(
56 PhabricatorProjectIconTransaction::TRANSACTIONTYPE)
57 ->setNewValue($request->getValue('icon'));
58 }
59
60 if ($request->getValue('color')) {
61 $xactions[] = id(new PhabricatorProjectTransaction())
62 ->setTransactionType(
63 PhabricatorProjectColorTransaction::TRANSACTIONTYPE)
64 ->setNewValue($request->getValue('color'));
65 }
66
67 if ($request->getValue('tags')) {
68 $xactions[] = id(new PhabricatorProjectTransaction())
69 ->setTransactionType(
70 PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE)
71 ->setNewValue($request->getValue('tags'));
72 }
73
74 $xactions[] = id(new PhabricatorProjectTransaction())
75 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
76 ->setMetadataValue(
77 'edge:type',
78 PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
79 ->setNewValue(
80 array(
81 '+' => array_fuse($members),
82 ));
83
84 $editor = id(new PhabricatorProjectTransactionEditor())
85 ->setActor($user)
86 ->setContinueOnNoEffect(true)
87 ->setContentSource($request->newContentSource());
88
89 $editor->applyTransactions($project, $xactions);
90
91 return $this->buildProjectInfoDictionary($project);
92 }
93
94}