mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +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:
parent
8fc5817f65
commit
45e93495e4
3 changed files with 43 additions and 0 deletions
|
@ -873,6 +873,10 @@ abstract class LiskDAO {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final protected function getInSet() {
|
||||||
|
return $this->inSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Examining Objects )-------------------------------------------------- */
|
/* -( Examining Objects )-------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,13 @@
|
||||||
final class LiskDAOSet {
|
final class LiskDAOSet {
|
||||||
private $daos = array();
|
private $daos = array();
|
||||||
private $relatives = array();
|
private $relatives = array();
|
||||||
|
private $edges = array();
|
||||||
private $subsets = array();
|
private $subsets = array();
|
||||||
|
|
||||||
public function addToSet(LiskDAO $dao) {
|
public function addToSet(LiskDAO $dao) {
|
||||||
|
if ($this->relatives || $this->edges) {
|
||||||
|
throw new Exception("Don't call addToSet() after loading data!");
|
||||||
|
}
|
||||||
$this->daos[] = $dao;
|
$this->daos[] = $dao;
|
||||||
$dao->putInSet($this);
|
$dao->putInSet($this);
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -54,6 +58,7 @@ final class LiskDAOSet {
|
||||||
final public function clearSet() {
|
final public function clearSet() {
|
||||||
$this->daos = array();
|
$this->daos = array();
|
||||||
$this->relatives = array();
|
$this->relatives = array();
|
||||||
|
$this->edges = array();
|
||||||
foreach ($this->subsets as $set) {
|
foreach ($this->subsets as $set) {
|
||||||
$set->clearSet();
|
$set->clearSet();
|
||||||
}
|
}
|
||||||
|
@ -99,4 +104,26 @@ final class LiskDAOSet {
|
||||||
return $relatives;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* @task edges
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue