Slightly simplify SearchAttach controller

Summary:
I want clean this up enough that I can land D595 without making a complete mess,
here's a small simplification.

Move object load logic into PhabricatorObjectHandleData.

Test Plan: Attached tasks and revisions, merged tasks.
Reviewed By: aran
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran
Differential Revision: 724
This commit is contained in:
epriestley
2011-07-25 09:42:26 -07:00
parent 0de2e03cc2
commit 29e3a7dae3
3 changed files with 25 additions and 35 deletions

View File

@@ -67,6 +67,24 @@ class PhabricatorObjectHandleData {
} }
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$task_dao = newv('ManiphestTask', array());
$tasks = $task_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
foreach ($tasks as $task) {
$objects[$task->getPHID()] = $task;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$revision_dao = newv('DifferentialRevision', array());
$revisions = $revision_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
foreach ($revisions as $revision) {
$objects[$revision->getPHID()] = $revision;
}
break;
} }
} }

View File

@@ -36,30 +36,16 @@ class PhabricatorSearchAttachController extends PhabricatorSearchController {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$handles = id(new PhabricatorObjectHandleData(array($this->phid))) $handle_data = new PhabricatorObjectHandleData(array($this->phid));
->loadHandles(); $handles = $handle_data->loadHandles();
$handle = $handles[$this->phid]; $handle = $handles[$this->phid];
$object_phid = $this->phid; $object_phid = $this->phid;
$object_type = $handle->getType(); $object_type = $handle->getType();
$attach_type = $this->type; $attach_type = $this->type;
// Load the object we're going to attach/detach stuff from. This is the $objects = $handle_data->loadObjects();
// object that triggered the action, e.g. the revision you clicked $object = idx($objects, $this->phid);
// "Edit Maniphest Tasks" on.
$object = null;
switch ($object_type) {
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$object = id(new DifferentialRevision())->loadOneWhere(
'phid = %s',
$this->phid);
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$object = id(new ManiphestTask())->loadOneWhere(
'phid = %s',
$this->phid);
break;
}
if (!$object) { if (!$object) {
return new Aphront404Response(); return new Aphront404Response();
@@ -89,22 +75,9 @@ class PhabricatorSearchAttachController extends PhabricatorSearchController {
if (($phids || $old_phids) && ($phids !== $old_phids)) { if (($phids || $old_phids) && ($phids !== $old_phids)) {
// Load all the objects we're attaching or detaching from the main $all_phids = array_merge($phids, $old_phids);
// object. $attach_objs = id(new PhabricatorObjectHandleData($all_phids))
switch ($attach_type) { ->loadObjects();
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$attach_objs = id(new DifferentialRevision())->loadAllWhere(
'phid IN (%Ls)',
array_merge($phids, $old_phids));
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$attach_objs = id(new ManiphestTask())->loadAllWhere(
'phid IN (%Ls)',
array_merge($phids, $old_phids));
break;
}
$attach_objs = mpull($attach_objs, null, 'getPHID');
// Remove PHIDs which don't actually exist, to prevent silliness. // Remove PHIDs which don't actually exist, to prevent silliness.
$phids = array_keys(array_select_keys($attach_objs, $phids)); $phids = array_keys(array_select_keys($attach_objs, $phids));

View File

@@ -9,7 +9,6 @@
phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/dialog'); phutil_require_module('phabricator', 'aphront/response/dialog');
phutil_require_module('phabricator', 'aphront/response/reload'); phutil_require_module('phabricator', 'aphront/response/reload');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/maniphest/constants/status'); phutil_require_module('phabricator', 'applications/maniphest/constants/status');
phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype');
phutil_require_module('phabricator', 'applications/maniphest/editor/transaction'); phutil_require_module('phabricator', 'applications/maniphest/editor/transaction');