1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 19:01:03 +01:00

Stop reads and writes to projectPHIDs property on ManiphestTask

Summary: Ref T5245. This property predates edges and is unusual in modern applications. Stop writes to it and populate it implicitly from edges when querying.

Test Plan:
  - Viewed task list.
  - Created a task.
  - Added and removed projects from tasks.

Reviewers: joshuaspence, chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5245

Differential Revision: https://secure.phabricator.com/D9851
This commit is contained in:
epriestley 2014-07-17 15:42:53 -07:00
parent aa79539789
commit b8b59895ee
5 changed files with 39 additions and 14 deletions

View file

@ -81,7 +81,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$default_projects = mpull($default_projects, 'getPHID'); $default_projects = mpull($default_projects, 'getPHID');
if ($default_projects) { if ($default_projects) {
$task->setProjectPHIDs($default_projects); $task->attachProjectPHIDs($default_projects);
} }
} }
} }
@ -215,7 +215,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$task->setPriority($request->getInt('priority')); $task->setPriority($request->getInt('priority'));
$task->setOwnerPHID($owner_phid); $task->setOwnerPHID($owner_phid);
$task->setCCPHIDs($request->getArr('cc')); $task->setCCPHIDs($request->getArr('cc'));
$task->setProjectPHIDs($request->getArr('projects')); $task->attachProjectPHIDs($request->getArr('projects'));
} else { } else {
if ($can_edit_priority) { if ($can_edit_priority) {
@ -438,7 +438,7 @@ final class ManiphestTaskEditController extends ManiphestController {
->executeOne(); ->executeOne();
if ($template_task) { if ($template_task) {
$task->setCCPHIDs($template_task->getCCPHIDs()); $task->setCCPHIDs($template_task->getCCPHIDs());
$task->setProjectPHIDs($template_task->getProjectPHIDs()); $task->attachProjectPHIDs($template_task->getProjectPHIDs());
$task->setOwnerPHID($template_task->getOwnerPHID()); $task->setOwnerPHID($template_task->getOwnerPHID());
$task->setPriority($template_task->getPriority()); $task->setPriority($template_task->getPriority());
$task->setViewPolicy($template_task->getViewPolicy()); $task->setViewPolicy($template_task->getViewPolicy());

View file

@ -150,8 +150,9 @@ final class ManiphestTransactionEditor
case ManiphestTransaction::TYPE_CCS: case ManiphestTransaction::TYPE_CCS:
return $object->setCCPHIDs($xaction->getNewValue()); return $object->setCCPHIDs($xaction->getNewValue());
case ManiphestTransaction::TYPE_PROJECTS: case ManiphestTransaction::TYPE_PROJECTS:
$object->setProjectPHIDs($xaction->getNewValue()); ManiphestTaskProject::updateTaskProjects(
ManiphestTaskProject::updateTaskProjects($object); $object,
$xaction->getNewValue());
return $object; return $object;
case ManiphestTransaction::TYPE_SUBPRIORITY: case ManiphestTransaction::TYPE_SUBPRIORITY:
$data = $xaction->getNewValue(); $data = $xaction->getNewValue();

View file

@ -331,6 +331,27 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $tasks; return $tasks;
} }
protected function didFilterPage(array $tasks) {
// TODO: Eventually, we should make this optional and introduce a
// needProjectPHIDs() method, but for now there's a lot of code which
// assumes the data is always populated.
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($tasks, 'getPHID'))
->withEdgeTypes(
array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
));
$edge_query->execute();
foreach ($tasks as $task) {
$phids = $edge_query->getDestinationPHIDs(array($task->getPHID()));
$task->attachProjectPHIDs($phids);
}
return $tasks;
}
private function buildTaskIDsWhereClause(AphrontDatabaseConnection $conn) { private function buildTaskIDsWhereClause(AphrontDatabaseConnection $conn) {
if (!$this->taskIDs) { if (!$this->taskIDs) {
return null; return null;

View file

@ -37,6 +37,7 @@ final class ManiphestTask extends ManiphestDAO
private $groupByProjectPHID = self::ATTACHABLE; private $groupByProjectPHID = self::ATTACHABLE;
private $customFields = self::ATTACHABLE; private $customFields = self::ATTACHABLE;
private $edgeProjectPHIDs = self::ATTACHABLE;
public static function initializeNewTask(PhabricatorUser $actor) { public static function initializeNewTask(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery()) $app = id(new PhabricatorApplicationQuery())
@ -52,7 +53,8 @@ final class ManiphestTask extends ManiphestDAO
->setPriority(ManiphestTaskPriority::getDefaultPriority()) ->setPriority(ManiphestTaskPriority::getDefaultPriority())
->setAuthorPHID($actor->getPHID()) ->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy) ->setViewPolicy($view_policy)
->setEditPolicy($edit_policy); ->setEditPolicy($edit_policy)
->attachProjectPHIDs(array());
} }
public function getConfiguration() { public function getConfiguration() {
@ -90,13 +92,13 @@ final class ManiphestTask extends ManiphestDAO
return array_values(nonempty($this->ccPHIDs, array())); return array_values(nonempty($this->ccPHIDs, array()));
} }
public function setProjectPHIDs(array $phids) { public function getProjectPHIDs() {
$this->projectPHIDs = array_values($phids); return $this->assertAttached($this->edgeProjectPHIDs);
return $this;
} }
public function getProjectPHIDs() { public function attachProjectPHIDs(array $phids) {
return array_values(nonempty($this->projectPHIDs, array())); $this->edgeProjectPHIDs = $phids;
return $this;
} }
public function setCCPHIDs(array $phids) { public function setCCPHIDs(array $phids) {

View file

@ -19,13 +19,15 @@ final class ManiphestTaskProject extends ManiphestDAO {
); );
} }
public static function updateTaskProjects(ManiphestTask $task) { public static function updateTaskProjects(
ManiphestTask $task,
array $new_phids) {
$edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$task->getPHID(), $task->getPHID(),
$edge_type); $edge_type);
$new_phids = $task->getProjectPHIDs();
$add_phids = array_diff($new_phids, $old_phids); $add_phids = array_diff($new_phids, $old_phids);
$rem_phids = array_diff($old_phids, $new_phids); $rem_phids = array_diff($old_phids, $new_phids);
@ -34,7 +36,6 @@ final class ManiphestTaskProject extends ManiphestDAO {
return; return;
} }
$editor = new PhabricatorEdgeEditor(); $editor = new PhabricatorEdgeEditor();
foreach ($add_phids as $phid) { foreach ($add_phids as $phid) {
$editor->addEdge($task->getPHID(), $edge_type, $phid); $editor->addEdge($task->getPHID(), $edge_type, $phid);