Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / project / conduit / ProjectCreateConduitAPIMethod.php
blob5ada64006d21940536956c76738d168b9c480d52
1 <?php
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() {
18 return pht(
19 'This method is frozen and will eventually be deprecated. New code '.
20 'should use "project.edit" instead.');
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>',
33 protected function defineReturnType() {
34 return 'dict';
37 protected function execute(ConduitAPIRequest $request) {
38 $user = $request->getUser();
40 $this->requireApplicationCapability(
41 ProjectCreateProjectsCapability::CAPABILITY,
42 $user);
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) {
54 $members = array();
56 $xactions = array();
58 $xactions[] = id(new PhabricatorProjectTransaction())
59 ->setTransactionType($type_name)
60 ->setNewValue($name);
62 if ($request->getValue('icon')) {
63 $xactions[] = id(new PhabricatorProjectTransaction())
64 ->setTransactionType(
65 PhabricatorProjectIconTransaction::TRANSACTIONTYPE)
66 ->setNewValue($request->getValue('icon'));
69 if ($request->getValue('color')) {
70 $xactions[] = id(new PhabricatorProjectTransaction())
71 ->setTransactionType(
72 PhabricatorProjectColorTransaction::TRANSACTIONTYPE)
73 ->setNewValue($request->getValue('color'));
76 if ($request->getValue('tags')) {
77 $xactions[] = id(new PhabricatorProjectTransaction())
78 ->setTransactionType(
79 PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE)
80 ->setNewValue($request->getValue('tags'));
83 $xactions[] = id(new PhabricatorProjectTransaction())
84 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
85 ->setMetadataValue(
86 'edge:type',
87 PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
88 ->setNewValue(
89 array(
90 '+' => array_fuse($members),
91 ));
93 $editor = id(new PhabricatorProjectTransactionEditor())
94 ->setActor($user)
95 ->setContinueOnNoEffect(true)
96 ->setContentSource($request->newContentSource());
98 $editor->applyTransactions($project, $xactions);
100 return $this->buildProjectInfoDictionary($project);