forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectCreateConduitAPIMethod.php
103 lines (82 loc) · 2.91 KB
/
ProjectCreateConduitAPIMethod.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
final class ProjectCreateConduitAPIMethod extends ProjectConduitAPIMethod {
public function getAPIMethodName() {
return 'project.create';
}
public function getMethodDescription() {
return pht('Create a project.');
}
public function getMethodStatus() {
return self::METHOD_STATUS_FROZEN;
}
public function getMethodStatusDescription() {
return pht(
'This method is frozen and will eventually be deprecated. New code '.
'should use "project.edit" instead.');
}
protected function defineParamTypes() {
return array(
'name' => 'required string',
'members' => 'optional list<phid>',
'icon' => 'optional string',
'color' => 'optional string',
'tags' => 'optional list<string>',
);
}
protected function defineReturnType() {
return 'dict';
}
protected function execute(ConduitAPIRequest $request) {
$user = $request->getUser();
$this->requireApplicationCapability(
ProjectCreateProjectsCapability::CAPABILITY,
$user);
$project = PhabricatorProject::initializeNewProject($user);
$type_name = PhabricatorProjectNameTransaction::TRANSACTIONTYPE;
$name = $request->getValue('name');
if ($name === null || !strlen(name)) {
throw new Exception(pht('Field "name" must be non-empty.'));
}
$members = $request->getValue('members');
if ($members === null) {
$members = array();
}
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType($type_name)
->setNewValue($name);
if ($request->getValue('icon')) {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(
PhabricatorProjectIconTransaction::TRANSACTIONTYPE)
->setNewValue($request->getValue('icon'));
}
if ($request->getValue('color')) {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(
PhabricatorProjectColorTransaction::TRANSACTIONTYPE)
->setNewValue($request->getValue('color'));
}
if ($request->getValue('tags')) {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(
PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE)
->setNewValue($request->getValue('tags'));
}
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue(
'edge:type',
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
->setNewValue(
array(
'+' => array_fuse($members),
));
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSource($request->newContentSource());
$editor->applyTransactions($project, $xactions);
return $this->buildProjectInfoDictionary($project);
}
}