1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Add method for loading relative edges

Summary:
More and more relations are going under edges and I can't work with them from Relatives framework.

This doesn't have the nice transitive property of normal relatives (loading relative objects from relatives loads all of them at once) but I can add it when I need it.

I plan to use it in D3085 (after converting relationships to edges).

Test Plan:
  $task = id(new ManiphestTask())
    ->loadOneWhere('phid = %s', $phid);
  print_r($task->loadRelativeEdges(4));

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3344
This commit is contained in:
vrana 2012-08-20 17:52:44 -07:00
parent 8fc5817f65
commit 45e93495e4
3 changed files with 43 additions and 0 deletions

View file

@ -873,6 +873,10 @@ abstract class LiskDAO {
return $this;
}
final protected function getInSet() {
return $this->inSet;
}
/* -( Examining Objects )-------------------------------------------------- */

View file

@ -39,9 +39,13 @@
final class LiskDAOSet {
private $daos = array();
private $relatives = array();
private $edges = array();
private $subsets = array();
public function addToSet(LiskDAO $dao) {
if ($this->relatives || $this->edges) {
throw new Exception("Don't call addToSet() after loading data!");
}
$this->daos[] = $dao;
$dao->putInSet($this);
return $this;
@ -54,6 +58,7 @@ final class LiskDAOSet {
final public function clearSet() {
$this->daos = array();
$this->relatives = array();
$this->edges = array();
foreach ($this->subsets as $set) {
$set->clearSet();
}
@ -99,4 +104,26 @@ final class LiskDAOSet {
return $relatives;
}
public function loadRelativeEdges($type) {
$edges = &$this->edges[$type];
if ($edges === null) {
if (!$this->daos) {
$edges = array();
} else {
assert_instances_of($this->daos, 'PhabricatorLiskDAO');
$phids = mpull($this->daos, 'getPHID', 'getPHID');
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($phids)
->withEdgeTypes(array($type))
->execute();
foreach ($this->daos as $dao) {
$dao->attachEdges($edges[$dao->getPHID()]);
}
}
}
return $edges;
}
}

View file

@ -52,6 +52,18 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
}
/**
* @task edges
*/
public function loadRelativeEdges($type) {
if (!$this->getInSet()) {
id(new LiskDAOSet())->addToSet($this);
}
$this->getInSet()->loadRelativeEdges($type);
return $this->getEdges($type);
}
/**
* @task edges
*/