mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 17:30:59 +01:00
Use Edges to store dependencies between tasks in Maniphest
Summary: - Use edges to store "X depends on Y" information in Maniphest. - Show both "Depends On" and "Dependent Tasks". - Migrate all the old edges. Test Plan: - Added some relationships, migrated, verified they were preserved. - Added some new valid relationships, verified tasks got updated with sensible transactions and sent reasonable emails. - Tried to add a cycle, got an ugly but effective error. Reviewers: vrana, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1162 Differential Revision: https://secure.phabricator.com/D3006
This commit is contained in:
parent
409974fbd6
commit
9196a6bd9f
11 changed files with 285 additions and 170 deletions
42
resources/sql/patches/migrate-maniphest-dependencies.php
Normal file
42
resources/sql/patches/migrate-maniphest-dependencies.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "Migrating task dependencies to edges...\n";
|
||||||
|
foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
|
||||||
|
$id = $task->getID();
|
||||||
|
echo "Task {$id}: ";
|
||||||
|
|
||||||
|
$deps = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_TASK);
|
||||||
|
if (!$deps) {
|
||||||
|
echo "-\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = new PhabricatorEdgeEditor();
|
||||||
|
$editor->setSuppressEvents(true);
|
||||||
|
foreach ($deps as $dep) {
|
||||||
|
$editor->addEdge(
|
||||||
|
$task->getPHID(),
|
||||||
|
PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK,
|
||||||
|
$dep);
|
||||||
|
}
|
||||||
|
$editor->save();
|
||||||
|
echo "OKAY\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Done.\n";
|
|
@ -815,7 +815,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorOAuthServerTokenController' => 'applications/oauthserver/controller/PhabricatorOAuthServerTokenController.php',
|
'PhabricatorOAuthServerTokenController' => 'applications/oauthserver/controller/PhabricatorOAuthServerTokenController.php',
|
||||||
'PhabricatorOAuthUnlinkController' => 'applications/auth/controller/PhabricatorOAuthUnlinkController.php',
|
'PhabricatorOAuthUnlinkController' => 'applications/auth/controller/PhabricatorOAuthUnlinkController.php',
|
||||||
'PhabricatorObjectAttachmentEditor' => 'applications/search/editor/PhabricatorObjectAttachmentEditor.php',
|
'PhabricatorObjectAttachmentEditor' => 'applications/search/editor/PhabricatorObjectAttachmentEditor.php',
|
||||||
'PhabricatorObjectGraph' => 'applications/phid/PhabricatorObjectGraph.php',
|
|
||||||
'PhabricatorObjectHandle' => 'applications/phid/PhabricatorObjectHandle.php',
|
'PhabricatorObjectHandle' => 'applications/phid/PhabricatorObjectHandle.php',
|
||||||
'PhabricatorObjectHandleConstants' => 'applications/phid/handle/const/PhabricatorObjectHandleConstants.php',
|
'PhabricatorObjectHandleConstants' => 'applications/phid/handle/const/PhabricatorObjectHandleConstants.php',
|
||||||
'PhabricatorObjectHandleData' => 'applications/phid/handle/PhabricatorObjectHandleData.php',
|
'PhabricatorObjectHandleData' => 'applications/phid/handle/PhabricatorObjectHandleData.php',
|
||||||
|
@ -1824,7 +1823,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorOAuthServerTestController' => 'PhabricatorOAuthServerController',
|
'PhabricatorOAuthServerTestController' => 'PhabricatorOAuthServerController',
|
||||||
'PhabricatorOAuthServerTokenController' => 'PhabricatorAuthController',
|
'PhabricatorOAuthServerTokenController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorOAuthUnlinkController' => 'PhabricatorAuthController',
|
'PhabricatorOAuthUnlinkController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorObjectGraph' => 'AbstractDirectedGraph',
|
|
||||||
'PhabricatorObjectHandleStatus' => 'PhabricatorObjectHandleConstants',
|
'PhabricatorObjectHandleStatus' => 'PhabricatorObjectHandleConstants',
|
||||||
'PhabricatorOffsetPagedQuery' => 'PhabricatorQuery',
|
'PhabricatorOffsetPagedQuery' => 'PhabricatorQuery',
|
||||||
'PhabricatorOwnersController' => 'PhabricatorController',
|
'PhabricatorOwnersController' => 'PhabricatorController',
|
||||||
|
|
|
@ -51,11 +51,28 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||||
'taskID = %d ORDER BY id ASC',
|
'taskID = %d ORDER BY id ASC',
|
||||||
$task->getID());
|
$task->getID());
|
||||||
|
|
||||||
$commit_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
$e_commit = PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT;
|
||||||
$task->getPHID(),
|
$e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
|
||||||
PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT);
|
$e_dep_by = PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK;
|
||||||
|
|
||||||
|
$phid = $task->getPHID();
|
||||||
|
|
||||||
|
$query = id(new PhabricatorEdgeQuery())
|
||||||
|
->withSourcePHIDs(array($phid))
|
||||||
|
->withEdgeTypes(
|
||||||
|
array(
|
||||||
|
$e_commit,
|
||||||
|
$e_dep_on,
|
||||||
|
$e_dep_by,
|
||||||
|
));
|
||||||
|
$edges = $query->execute();
|
||||||
|
|
||||||
|
$commit_phids = array_keys($edges[$phid][$e_commit]);
|
||||||
|
$dep_on_tasks = array_keys($edges[$phid][$e_dep_on]);
|
||||||
|
$dep_by_tasks = array_keys($edges[$phid][$e_dep_by]);
|
||||||
|
|
||||||
|
$phids = array_fill_keys($query->getDestinationPHIDs(), true);
|
||||||
|
|
||||||
$phids = array_fill_keys($commit_phids, true);
|
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
foreach ($transaction->extractPHIDs() as $phid) {
|
foreach ($transaction->extractPHIDs() as $phid) {
|
||||||
$phids[$phid] = true;
|
$phids[$phid] = true;
|
||||||
|
@ -150,33 +167,25 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dtasks = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_TASK);
|
if ($dep_by_tasks) {
|
||||||
if ($dtasks) {
|
$dict['Dependent Tasks'] = $this->renderHandleList(
|
||||||
$dtask_links = array();
|
array_select_keys($handles, $dep_by_tasks));
|
||||||
foreach ($dtasks as $dtask => $info) {
|
}
|
||||||
$dtask_links[] = $handles[$dtask]->renderLink();
|
|
||||||
}
|
if ($dep_on_tasks) {
|
||||||
$dtask_links = implode('<br />', $dtask_links);
|
$dict['Depends On'] = $this->renderHandleList(
|
||||||
$dict['Depends On'] = $dtask_links;
|
array_select_keys($handles, $dep_on_tasks));
|
||||||
}
|
}
|
||||||
|
|
||||||
$revs = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
$revs = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||||
if ($revs) {
|
if ($revs) {
|
||||||
$rev_links = array();
|
$dict['Revisions'] = $this->renderHandleList(
|
||||||
foreach ($revs as $rev => $info) {
|
array_select_keys($handles, $revs));
|
||||||
$rev_links[] = $handles[$rev]->renderLink();
|
|
||||||
}
|
|
||||||
$rev_links = implode('<br />', $rev_links);
|
|
||||||
$dict['Revisions'] = $rev_links;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($commit_phids) {
|
if ($commit_phids) {
|
||||||
$commit_links = array();
|
$dict['Commits'] = $this->renderHandleList(
|
||||||
foreach ($commit_phids as $phid) {
|
array_select_keys($handles, $commit_phids));
|
||||||
$commit_links[] = $handles[$phid]->renderLink();
|
|
||||||
}
|
|
||||||
$commit_links = implode('<br />', $commit_links);
|
|
||||||
$dict['Commits'] = $commit_links;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE);
|
$file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE);
|
||||||
|
@ -534,4 +543,12 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function renderHandleList(array $handles) {
|
||||||
|
$links = array();
|
||||||
|
foreach ($handles as $handle) {
|
||||||
|
$links[] = $handle->renderLink();
|
||||||
|
}
|
||||||
|
return implode('<br />', $links);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,18 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadDependsOnTaskPHIDs() {
|
||||||
|
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
|
$this->getPHID(),
|
||||||
|
PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadDependedOnByTaskPHIDs() {
|
||||||
|
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
|
$this->getPHID(),
|
||||||
|
PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK);
|
||||||
|
}
|
||||||
|
|
||||||
public function getAttachedPHIDs($type) {
|
public function getAttachedPHIDs($type) {
|
||||||
return array_keys(idx($this->attached, $type, array()));
|
return array_keys(idx($this->attached, $type, array()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -657,8 +657,16 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @task strings
|
||||||
|
*/
|
||||||
private function getEdgeEmailTitle($type, $count) {
|
private function getEdgeEmailTitle($type, $count) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('DEPENDS ON %d TASK(S)', $count);
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('DEPENDENT %d TASK(s)', $count);
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('ATTACHED %d COMMIT(S)', $count);
|
return pht('ATTACHED %d COMMIT(S)', $count);
|
||||||
default:
|
default:
|
||||||
|
@ -672,6 +680,10 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
*/
|
*/
|
||||||
private function getEdgeAddVerb($type) {
|
private function getEdgeAddVerb($type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('Added Dependency');
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('Added Dependent Task');
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('Added Commit');
|
return pht('Added Commit');
|
||||||
default:
|
default:
|
||||||
|
@ -685,6 +697,10 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
*/
|
*/
|
||||||
private function getEdgeRemVerb($type) {
|
private function getEdgeRemVerb($type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('Removed Dependency');
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('Removed Dependent Task');
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('Removed Commit');
|
return pht('Removed Commit');
|
||||||
default:
|
default:
|
||||||
|
@ -698,6 +714,10 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
*/
|
*/
|
||||||
private function getEdgeEditVerb($type) {
|
private function getEdgeEditVerb($type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('Changed Dependencies');
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('Changed Dependent Tasks');
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('Changed Commits');
|
return pht('Changed Commits');
|
||||||
default:
|
default:
|
||||||
|
@ -713,6 +733,10 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
$list = $this->renderHandles(array_keys($add));
|
$list = $this->renderHandles(array_keys($add));
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('added %d dependencie(s): %s', $add, $list);
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('added %d dependent task(s): %s', $add, $list);
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('added %d commit(s): %s', $add, $list);
|
return pht('added %d commit(s): %s', $add, $list);
|
||||||
default:
|
default:
|
||||||
|
@ -728,6 +752,10 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
$list = $this->renderHandles(array_keys($rem));
|
$list = $this->renderHandles(array_keys($rem));
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht('removed %d dependencie(s): %s', $rem, $list);
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht('removed %d dependent task(s): %s', $rem, $list);
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht('removed %d commit(s): %s', $rem, $list);
|
return pht('removed %d commit(s): %s', $rem, $list);
|
||||||
default:
|
default:
|
||||||
|
@ -744,6 +772,22 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
$rem_list = $this->renderHandles(array_keys($rem));
|
$rem_list = $this->renderHandles(array_keys($rem));
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK:
|
||||||
|
return pht(
|
||||||
|
'changed %d dependencie(s), added %d: %s; removed %d: %s',
|
||||||
|
count($add) + count($rem),
|
||||||
|
$add,
|
||||||
|
$add_list,
|
||||||
|
$rem,
|
||||||
|
$rem_list);
|
||||||
|
case PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK:
|
||||||
|
return pht(
|
||||||
|
'changed %d dependent task(s), added %d: %s; removed %d: %s',
|
||||||
|
count($add) + count($rem),
|
||||||
|
$add,
|
||||||
|
$add_list,
|
||||||
|
$rem,
|
||||||
|
$rem_list);
|
||||||
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
case PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT:
|
||||||
return pht(
|
return pht(
|
||||||
'changed %d commit(s), added %d: %s; removed %d: %s',
|
'changed %d commit(s), added %d: %s; removed %d: %s',
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2011 Facebook, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
final class PhabricatorObjectGraph extends AbstractDirectedGraph {
|
|
||||||
|
|
||||||
private $edgeType;
|
|
||||||
|
|
||||||
public function setEdgeType($edge_type) {
|
|
||||||
$this->edgeType = $edge_type;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function loadEdges(array $nodes) {
|
|
||||||
if (!$this->edgeType) {
|
|
||||||
throw new Exception("Set edge type before loading graph!");
|
|
||||||
}
|
|
||||||
|
|
||||||
$handle_data = new PhabricatorObjectHandleData($nodes);
|
|
||||||
$objects = $handle_data->loadObjects();
|
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach ($nodes as $phid) {
|
|
||||||
$object = idx($objects, $phid);
|
|
||||||
if ($object) {
|
|
||||||
$result[$phid] = $object->getAttachedPHIDs($this->edgeType);
|
|
||||||
} else {
|
|
||||||
$result[$phid] = array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -56,74 +56,76 @@ final class PhabricatorSearchAttachController
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$edge_type = null;
|
||||||
|
switch ($this->action) {
|
||||||
|
case self::ACTION_EDGE:
|
||||||
|
case self::ACTION_DEPENDENCIES:
|
||||||
|
$edge_type = $this->getEdgeType($object_type, $attach_type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$phids = explode(';', $request->getStr('phids'));
|
$phids = explode(';', $request->getStr('phids'));
|
||||||
$phids = array_filter($phids);
|
$phids = array_filter($phids);
|
||||||
$phids = array_values($phids);
|
$phids = array_values($phids);
|
||||||
|
|
||||||
switch ($this->action) {
|
if ($edge_type) {
|
||||||
case self::ACTION_MERGE:
|
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
return $this->performMerge($object, $handle, $phids);
|
$this->phid,
|
||||||
|
$edge_type);
|
||||||
|
$add_phids = $phids;
|
||||||
|
$rem_phids = array_diff($old_phids, $add_phids);
|
||||||
|
|
||||||
case self::ACTION_EDGE:
|
$editor = id(new PhabricatorEdgeEditor());
|
||||||
$edge_type = $this->getEdgeType($object_type, $attach_type);
|
$editor->setUser($user);
|
||||||
|
foreach ($add_phids as $phid) {
|
||||||
|
$editor->addEdge($this->phid, $edge_type, $phid);
|
||||||
|
}
|
||||||
|
foreach ($rem_phids as $phid) {
|
||||||
|
$editor->removeEdge($this->phid, $edge_type, $phid);
|
||||||
|
}
|
||||||
|
|
||||||
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
try {
|
||||||
$this->phid,
|
|
||||||
$edge_type);
|
|
||||||
$add_phids = $phids;
|
|
||||||
$rem_phids = array_diff($old_phids, $add_phids);
|
|
||||||
$editor = id(new PhabricatorEdgeEditor());
|
|
||||||
$editor->setUser($user);
|
|
||||||
foreach ($add_phids as $phid) {
|
|
||||||
$editor->addEdge($this->phid, $edge_type, $phid);
|
|
||||||
}
|
|
||||||
foreach ($rem_phids as $phid) {
|
|
||||||
$editor->removeEdge($this->phid, $edge_type, $phid);
|
|
||||||
}
|
|
||||||
$editor->save();
|
$editor->save();
|
||||||
|
} catch (PhabricatorEdgeCycleException $ex) {
|
||||||
|
$this->raiseGraphCycleException($ex);
|
||||||
|
}
|
||||||
|
|
||||||
return id(new AphrontReloadResponse())->setURI($handle->getURI());
|
return id(new AphrontReloadResponse())->setURI($handle->getURI());
|
||||||
case self::ACTION_DEPENDENCIES:
|
} else {
|
||||||
case self::ACTION_ATTACH:
|
switch ($this->action) {
|
||||||
$two_way = true;
|
case self::ACTION_MERGE:
|
||||||
if ($this->action == self::ACTION_DEPENDENCIES) {
|
return $this->performMerge($object, $handle, $phids);
|
||||||
$two_way = false;
|
case self::ACTION_ATTACH:
|
||||||
$this->detectGraphCycles(
|
$editor = new PhabricatorObjectAttachmentEditor(
|
||||||
$object,
|
$object_type,
|
||||||
|
$object);
|
||||||
|
$editor->setUser($this->getRequest()->getUser());
|
||||||
|
$editor->attachObjects(
|
||||||
$attach_type,
|
$attach_type,
|
||||||
$phids);
|
$phids,
|
||||||
}
|
$two_way = false);
|
||||||
|
|
||||||
$editor = new PhabricatorObjectAttachmentEditor(
|
return id(new AphrontReloadResponse())->setURI($handle->getURI());
|
||||||
$object_type,
|
default:
|
||||||
$object);
|
throw new Exception("Unsupported attach action.");
|
||||||
$editor->setUser($this->getRequest()->getUser());
|
}
|
||||||
$editor->attachObjects(
|
|
||||||
$attach_type,
|
|
||||||
$phids,
|
|
||||||
$two_way);
|
|
||||||
|
|
||||||
return id(new AphrontReloadResponse())->setURI($handle->getURI());
|
|
||||||
default:
|
|
||||||
throw new Exception("Unsupported attach action.");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch ($this->action) {
|
if ($edge_type) {
|
||||||
case self::ACTION_ATTACH:
|
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
case self::ACTION_DEPENDENCIES:
|
$this->phid,
|
||||||
$phids = $object->getAttachedPHIDs($attach_type);
|
$edge_type);
|
||||||
break;
|
} else {
|
||||||
case self::ACTION_EDGE:
|
switch ($this->action) {
|
||||||
$edge_type = $this->getEdgeType($object_type, $attach_type);
|
case self::ACTION_ATTACH:
|
||||||
|
case self::ACTION_DEPENDENCIES:
|
||||||
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
$phids = $object->getAttachedPHIDs($attach_type);
|
||||||
$this->phid,
|
break;
|
||||||
$edge_type);
|
default:
|
||||||
break;
|
$phids = array();
|
||||||
default:
|
break;
|
||||||
$phids = array();
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,41 +271,6 @@ final class PhabricatorSearchAttachController
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function detectGraphCycles(
|
|
||||||
$object,
|
|
||||||
$attach_type,
|
|
||||||
array $phids) {
|
|
||||||
|
|
||||||
// Detect graph cycles.
|
|
||||||
$graph = new PhabricatorObjectGraph();
|
|
||||||
$graph->setEdgeType($attach_type);
|
|
||||||
$graph->addNodes(array(
|
|
||||||
$object->getPHID() => $phids,
|
|
||||||
));
|
|
||||||
$graph->loadGraph();
|
|
||||||
|
|
||||||
foreach ($phids as $phid) {
|
|
||||||
$cycle = $graph->detectCycles($phid);
|
|
||||||
if (!$cycle) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Improve this behavior so it's not all-or-nothing?
|
|
||||||
|
|
||||||
$handles = id(new PhabricatorObjectHandleData($cycle))
|
|
||||||
->loadHandles();
|
|
||||||
$names = array();
|
|
||||||
foreach ($cycle as $cycle_phid) {
|
|
||||||
$names[] = $handles[$cycle_phid]->getFullName();
|
|
||||||
}
|
|
||||||
$names = implode(" \xE2\x86\x92 ", $names);
|
|
||||||
$which = $handles[$phid]->getFullName();
|
|
||||||
throw new Exception(
|
|
||||||
"You can not create a dependency on '{$which}' because it ".
|
|
||||||
"would create a circular dependency: {$names}.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getEdgeType($src_type, $dst_type) {
|
private function getEdgeType($src_type, $dst_type) {
|
||||||
$t_cmit = PhabricatorPHIDConstants::PHID_TYPE_CMIT;
|
$t_cmit = PhabricatorPHIDConstants::PHID_TYPE_CMIT;
|
||||||
$t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
|
$t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
|
||||||
|
@ -314,14 +281,30 @@ final class PhabricatorSearchAttachController
|
||||||
),
|
),
|
||||||
$t_task => array(
|
$t_task => array(
|
||||||
$t_cmit => PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT,
|
$t_cmit => PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT,
|
||||||
|
$t_task => PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (empty($map[$src_type][$dst_type])) {
|
if (empty($map[$src_type][$dst_type])) {
|
||||||
throw new Exception("Unknown edge type!");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map[$src_type][$dst_type];
|
return $map[$src_type][$dst_type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function raiseGraphCycleException(PhabricatorEdgeCycleException $ex) {
|
||||||
|
$cycle = $ex->getCycle();
|
||||||
|
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($cycle))
|
||||||
|
->loadHandles();
|
||||||
|
$names = array();
|
||||||
|
foreach ($cycle as $cycle_phid) {
|
||||||
|
$names[] = $handles[$cycle_phid]->getFullName();
|
||||||
|
}
|
||||||
|
$names = implode(" \xE2\x86\x92 ", $names);
|
||||||
|
throw new Exception(
|
||||||
|
"You can not create that dependency, because it would create a ".
|
||||||
|
"circular dependency: {$names}.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,20 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
||||||
const TABLE_NAME_EDGE = 'edge';
|
const TABLE_NAME_EDGE = 'edge';
|
||||||
const TABLE_NAME_EDGEDATA = 'edgedata';
|
const TABLE_NAME_EDGEDATA = 'edgedata';
|
||||||
|
|
||||||
const TYPE_TASK_HAS_COMMIT = 1;
|
const TYPE_TASK_HAS_COMMIT = 1;
|
||||||
const TYPE_COMMIT_HAS_TASK = 2;
|
const TYPE_COMMIT_HAS_TASK = 2;
|
||||||
|
const TYPE_TASK_DEPENDS_ON_TASK = 3;
|
||||||
|
const TYPE_TASK_DEPENDED_ON_BY_TASK = 4;
|
||||||
|
|
||||||
const TYPE_TEST_NO_CYCLE = 9000;
|
const TYPE_TEST_NO_CYCLE = 9000;
|
||||||
|
|
||||||
public static function getInverse($edge_type) {
|
public static function getInverse($edge_type) {
|
||||||
static $map = array(
|
static $map = array(
|
||||||
self::TYPE_TASK_HAS_COMMIT => self::TYPE_COMMIT_HAS_TASK,
|
self::TYPE_TASK_HAS_COMMIT => self::TYPE_COMMIT_HAS_TASK,
|
||||||
self::TYPE_COMMIT_HAS_TASK => self::TYPE_TASK_HAS_COMMIT,
|
self::TYPE_COMMIT_HAS_TASK => self::TYPE_TASK_HAS_COMMIT,
|
||||||
|
|
||||||
|
self::TYPE_TASK_DEPENDS_ON_TASK => self::TYPE_TASK_DEPENDED_ON_BY_TASK,
|
||||||
|
self::TYPE_TASK_DEPENDED_ON_BY_TASK => self::TYPE_TASK_DEPENDS_ON_TASK,
|
||||||
);
|
);
|
||||||
|
|
||||||
return idx($map, $edge_type);
|
return idx($map, $edge_type);
|
||||||
|
@ -37,7 +42,8 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
||||||
|
|
||||||
public static function shouldPreventCycles($edge_type) {
|
public static function shouldPreventCycles($edge_type) {
|
||||||
static $map = array(
|
static $map = array(
|
||||||
self::TYPE_TEST_NO_CYCLE => true,
|
self::TYPE_TEST_NO_CYCLE => true,
|
||||||
|
self::TYPE_TASK_DEPENDS_ON_TASK => true,
|
||||||
);
|
);
|
||||||
return isset($map[$edge_type]);
|
return isset($map[$edge_type]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ final class PhabricatorEdgeEditor {
|
||||||
private $remEdges = array();
|
private $remEdges = array();
|
||||||
private $openTransactions = array();
|
private $openTransactions = array();
|
||||||
private $user;
|
private $user;
|
||||||
|
private $suppressEvents;
|
||||||
|
|
||||||
public function setUser(PhabricatorUser $user) {
|
public function setUser(PhabricatorUser $user) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -370,7 +371,26 @@ final class PhabricatorEdgeEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suppress edge edit events. This prevents listeners from making updates in
|
||||||
|
* response to edits, and is primarily useful when performing migrations. You
|
||||||
|
* should not normally need to use it.
|
||||||
|
*
|
||||||
|
* @param bool True to supress events related to edits.
|
||||||
|
* @return this
|
||||||
|
* @task internal
|
||||||
|
*/
|
||||||
|
public function setSuppressEvents($suppress) {
|
||||||
|
$this->suppressEvents = $suppress;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function sendEvent($edit_id, $event_type) {
|
private function sendEvent($edit_id, $event_type) {
|
||||||
|
if ($this->suppressEvents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$event = new PhabricatorEvent(
|
$event = new PhabricatorEvent(
|
||||||
$event_type,
|
$event_type,
|
||||||
array(
|
array(
|
||||||
|
@ -436,4 +456,5 @@ final class PhabricatorEdgeEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,43 @@ abstract class PhabricatorBaseEnglishTranslation
|
||||||
'ATTACHED COMMITS',
|
'ATTACHED COMMITS',
|
||||||
'ATTACHED COMMIT',
|
'ATTACHED COMMIT',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'added %d dependencie(s): %s' => array(
|
||||||
|
'added dependencies: %2$s',
|
||||||
|
'added dependency: %2$s',
|
||||||
|
),
|
||||||
|
|
||||||
|
'added %d dependent task(s): %s' => array(
|
||||||
|
'added dependent tasks: %2$s',
|
||||||
|
'added dependent task: %2$s',
|
||||||
|
),
|
||||||
|
|
||||||
|
'removed %d dependencie(s): %s' => array(
|
||||||
|
'removed dependencies: %2$s',
|
||||||
|
'removed dependency: %2$s',
|
||||||
|
),
|
||||||
|
|
||||||
|
'removed %d dependent task(s): %s' => array(
|
||||||
|
'removed dependent tasks: %2$s',
|
||||||
|
'removed dependent task: %2$s',
|
||||||
|
),
|
||||||
|
|
||||||
|
'changed %d dependencie(s), added %d: %s; removed %d: %s' =>
|
||||||
|
'changed dependencies, added: %3$s; removed: %5$s',
|
||||||
|
|
||||||
|
'changed %d dependent task(s), added %d: %s; removed %d: %s',
|
||||||
|
'changed dependent tasks, added: %3$s; removed: %5$s',
|
||||||
|
|
||||||
|
'DEPENDENT %d TASK(s)' => array(
|
||||||
|
'DEPENDENT TASKS',
|
||||||
|
'DEPENDENT TASK',
|
||||||
|
),
|
||||||
|
|
||||||
|
'DEPENDS ON %d TASK(S)' => array(
|
||||||
|
'DEPENDS ON TASKS',
|
||||||
|
'DEPENDS ON TASK',
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -915,6 +915,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('maniphestxcache.sql'),
|
'name' => $this->getPatchPath('maniphestxcache.sql'),
|
||||||
),
|
),
|
||||||
|
'migrate-maniphest-dependencies.php' => array(
|
||||||
|
'type' => 'php',
|
||||||
|
'name' => $this->getPatchPath('migrate-maniphest-dependencies.php'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue