Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15425521
D10036.id24123.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10036.id24123.diff
View Options
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 @@
+<?php
+
+/**
+ * @group conduit
+ */
+final class ConduitAPI_project_create_Method extends ConduitAPI_project_Method {
+
+ public function getMethodDescription() {
+ return 'Create a project.';
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'name' => 'required string',
+ 'members' => 'optional list<phid>',
+ );
+ }
+
+ 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);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 24, 4:51 AM (1 w, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7716486
Default Alt Text
D10036.id24123.diff (2 KB)
Attached To
Mode
D10036: First stab at a conduit method for creating projects.
Attached
Detach File
Event Timeline
Log In to Comment