From 2bea542920abd2edd6d89784b877ecc2218e3f82 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Jan 2011 11:36:53 -0800 Subject: [PATCH] Conduit: user.find --- src/__phutil_library_map__.php | 4 ++ .../PhabricatorConduitConsoleController.php | 8 ++- .../user/find/ConduitAPI_user_find_Method.php | 49 +++++++++++++++++++ .../conduit/method/user/find/__init__.php | 15 ++++++ .../changeset/DifferentialChangeset.php | 37 +++++++------- .../storage/diff/DifferentialDiff.php | 31 +++++++++--- .../differential/storage/diff/__init__.php | 1 + src/storage/lisk/dao/LiskDAO.php | 2 +- .../markup/AphrontFormMarkupControl.php | 29 +++++++++++ src/view/form/control/markup/__init__.php | 12 +++++ 10 files changed, 155 insertions(+), 33 deletions(-) create mode 100644 src/applications/conduit/method/user/find/ConduitAPI_user_find_Method.php create mode 100644 src/applications/conduit/method/user/find/__init__.php create mode 100755 src/view/form/control/markup/AphrontFormMarkupControl.php create mode 100644 src/view/form/control/markup/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 322f926759..7c1876956f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -20,6 +20,7 @@ phutil_register_library_map(array( 'AphrontFileResponse' => 'aphront/response/file', 'AphrontFormControl' => 'view/form/control/base', 'AphrontFormFileControl' => 'view/form/control/file', + 'AphrontFormMarkupControl' => 'view/form/control/markup', 'AphrontFormSelectControl' => 'view/form/control/select', 'AphrontFormStaticControl' => 'view/form/control/static', 'AphrontFormSubmitControl' => 'view/form/control/submit', @@ -50,6 +51,7 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_connect_Method' => 'applications/conduit/method/conduit/connect', 'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/creatediff', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', + 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', 'ConduitException' => 'applications/conduit/protocol/exception', 'DifferentialAction' => 'applications/differential/constants/action', 'DifferentialChangeType' => 'applications/differential/constants/changetype', @@ -129,6 +131,7 @@ phutil_register_library_map(array( 'AphrontFileResponse' => 'AphrontResponse', 'AphrontFormControl' => 'AphrontView', 'AphrontFormFileControl' => 'AphrontFormControl', + 'AphrontFormMarkupControl' => 'AphrontFormControl', 'AphrontFormSelectControl' => 'AphrontFormControl', 'AphrontFormStaticControl' => 'AphrontFormControl', 'AphrontFormSubmitControl' => 'AphrontFormControl', @@ -152,6 +155,7 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_connect_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', + 'ConduitAPI_user_find_Method' => 'ConduitAPIMethod', 'DifferentialChangeset' => 'DifferentialDAO', 'DifferentialDAO' => 'PhabricatorLiskDAO', 'DifferentialDiff' => 'DifferentialDAO', diff --git a/src/applications/conduit/controller/console/PhabricatorConduitConsoleController.php b/src/applications/conduit/controller/console/PhabricatorConduitConsoleController.php index 8af6ac3b6f..3e8aa0befb 100644 --- a/src/applications/conduit/controller/console/PhabricatorConduitConsoleController.php +++ b/src/applications/conduit/controller/console/PhabricatorConduitConsoleController.php @@ -59,15 +59,13 @@ class PhabricatorConduitConsoleController ->appendChild( id(new AphrontFormStaticControl()) ->setLabel('Description') - ->setValue( - phutil_escape_html($method_object->getMethodDescription()))) + ->setValue($method_object->getMethodDescription())) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel('Returns') - ->setValue( - phutil_escape_html($method_object->defineReturnType()))) + ->setValue($method_object->defineReturnType())) ->appendChild( - id(new AphrontFormStaticControl()) + id(new AphrontFormMarkupControl()) ->setLabel('Errors') ->setValue($error_description)) ->appendChild( diff --git a/src/applications/conduit/method/user/find/ConduitAPI_user_find_Method.php b/src/applications/conduit/method/user/find/ConduitAPI_user_find_Method.php new file mode 100644 index 0000000000..4659e0d570 --- /dev/null +++ b/src/applications/conduit/method/user/find/ConduitAPI_user_find_Method.php @@ -0,0 +1,49 @@ + 'required nonempty list' + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $users = id(new PhabricatorUser())->loadAllWhere( + 'username in (%Ls)', + $request->getValue('aliases')); + + return mpull($users, 'getPHID', 'getUsername'); + } + +} diff --git a/src/applications/conduit/method/user/find/__init__.php b/src/applications/conduit/method/user/find/__init__.php new file mode 100644 index 0000000000..7b55082078 --- /dev/null +++ b/src/applications/conduit/method/user/find/__init__.php @@ -0,0 +1,15 @@ + array( @@ -60,27 +62,11 @@ class DifferentialChangeset extends DifferentialDAO { return $name; } - public function addHunk(DifferentialHunk $hunk) { - if (!isset($this->_hunks)) { - $this->_hunks = array(); - } - $this->_hunks[] = $hunk; - + public function addUnsavedHunk(DifferentialHunk $hunk) { + $this->unsavedHunks[] = $hunk; return $this; } - public function attachHunks(array $hunks) { - $this->_hunks = $hunks; - return $this; - } - - public function getHunks() { - if (!isset($this->_hunks)) { - throw new Exception("You must load hunks before accessing them."); - } - return $this->_hunks; - } - public function loadHunks() { if (!$this->getID()) { return array(); @@ -90,15 +76,26 @@ class DifferentialChangeset extends DifferentialDAO { $this->getID()); } + public function save() { +// TODO: Sort out transactions +// $this->openTransaction(); + $ret = parent::save(); + foreach ($this->unsavedHunks as $hunk) { + $hunk->setChangesetID($this->getID()); + $hunk->save(); + } +// $this->saveTransaction(); + return $ret; + } public function delete() { - $this->openTransaction(); +// $this->openTransaction(); foreach ($this->loadHunks() as $hunk) { $hunk->delete(); } $this->_hunks = array(); $ret = parent::delete(); - $this->saveTransaction(); +// $this->saveTransaction(); return $ret; } diff --git a/src/applications/differential/storage/diff/DifferentialDiff.php b/src/applications/differential/storage/diff/DifferentialDiff.php index b38f57e808..7728ac19b3 100644 --- a/src/applications/differential/storage/diff/DifferentialDiff.php +++ b/src/applications/differential/storage/diff/DifferentialDiff.php @@ -39,6 +39,13 @@ class DifferentialDiff extends DifferentialDAO { protected $arcanistProject; protected $creationMethod; + private $unsavedChangesets = array(); + + public function addUnsavedChangeset(DifferentialChangeset $changeset) { + $this->unsavedChangesets[] = $changeset; + return $this; + } + public function loadChangesets() { if (!$this->getID()) { return array(); @@ -48,13 +55,25 @@ class DifferentialDiff extends DifferentialDAO { $this->getID()); } + public function save() { +// TODO: sort out transactions +// $this->openTransaction(); + $ret = parent::save(); + foreach ($this->unsavedChangesets as $changeset) { +// $changeset->setDiffID($this->getID()); +// $changeset->save(); + } +// $this->saveTransaction(); + return $ret; + } + public function delete() { - $this->openTransaction(); +// $this->openTransaction(); foreach ($this->loadChangesets() as $changeset) { $changeset->delete(); } $ret = parent::delete(); - $this->saveTransaction(); +// $this->saveTransaction(); return $ret; } @@ -67,21 +86,19 @@ class DifferentialDiff extends DifferentialDAO { $add_lines = 0; $del_lines = 0; foreach ($change->getHunks() as $hunk) { - $dhunk = new Hunk(); + $dhunk = new DifferentialHunk(); $dhunk->setOldOffset($hunk->getOldOffset()); $dhunk->setOldLen($hunk->getOldLength()); $dhunk->setNewOffset($hunk->getNewOffset()); $dhunk->setNewLen($hunk->getNewLength()); $dhunk->setChanges($hunk->getCorpus()); - $changeset->addHunk($dhunk); + $changeset->addUnsavedHunk($dhunk); $add_lines += $hunk->getAddLines(); $del_lines += $hunk->getDelLines(); $lines += $add_lines + $del_lines; } - $changeset->setHunkCount(count($change->getHunks())); $changeset->setOldFile($change->getOldPath()); - $changeset->setNewFile($change->getCurrentPath()); $changeset->setFilename($change->getCurrentPath()); $changeset->setChangeType($change->getType()); @@ -93,7 +110,7 @@ class DifferentialDiff extends DifferentialDAO { $changeset->setAddLines($add_lines); $changeset->setDelLines($del_lines); - $diff->addChangeset($changeset); + $diff->addUnsavedChangeset($changeset); } $diff->setLineCount($lines); diff --git a/src/applications/differential/storage/diff/__init__.php b/src/applications/differential/storage/diff/__init__.php index 95814ba1f3..f4588f3dd8 100644 --- a/src/applications/differential/storage/diff/__init__.php +++ b/src/applications/differential/storage/diff/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/differential/storage/base'); phutil_require_module('phabricator', 'applications/differential/storage/changeset'); +phutil_require_module('phabricator', 'applications/differential/storage/hunk'); phutil_require_module('phutil', 'utils'); diff --git a/src/storage/lisk/dao/LiskDAO.php b/src/storage/lisk/dao/LiskDAO.php index 226c89d4fd..ab6e88496b 100644 --- a/src/storage/lisk/dao/LiskDAO.php +++ b/src/storage/lisk/dao/LiskDAO.php @@ -534,7 +534,7 @@ abstract class LiskDAO { if (!isset($properties)) { $class = new ReflectionClass(get_class($this)); $properties = array(); - foreach ($class->getProperties() as $p) { + foreach ($class->getProperties(ReflectionProperty::IS_PROTECTED) as $p) { $properties[strtolower($p->getName())] = $p->getName(); } diff --git a/src/view/form/control/markup/AphrontFormMarkupControl.php b/src/view/form/control/markup/AphrontFormMarkupControl.php new file mode 100755 index 0000000000..e85e1c416a --- /dev/null +++ b/src/view/form/control/markup/AphrontFormMarkupControl.php @@ -0,0 +1,29 @@ +getValue(); + } + +} diff --git a/src/view/form/control/markup/__init__.php b/src/view/form/control/markup/__init__.php new file mode 100644 index 0000000000..7ffd7914dd --- /dev/null +++ b/src/view/form/control/markup/__init__.php @@ -0,0 +1,12 @@ +