Add an Atom controller to Diviner
Summary: Ref T988. Lots of rough edges still, but this pulls the right data and dumps it into a reasonable-looking shell.
Test Plan: {F44883}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D6104
This commit is contained in:
@@ -5,6 +5,13 @@ final class DivinerAtomQuery
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $bookPHIDs;
|
||||
private $names;
|
||||
private $types;
|
||||
private $contexts;
|
||||
private $indexes;
|
||||
|
||||
private $needAtoms;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
@@ -16,6 +23,36 @@ final class DivinerAtomQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withBookPHIDs(array $phids) {
|
||||
$this->bookPHIDs = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withTypes(array $types) {
|
||||
$this->types = $types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNames(array $names) {
|
||||
$this->names = $names;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withContexts(array $contexts) {
|
||||
$this->contexts = $contexts;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withIndexes(array $indexes) {
|
||||
$this->indexes = $indexes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needAtoms($need) {
|
||||
$this->needAtoms = $need;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new DivinerLiveSymbol();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
@@ -53,6 +90,22 @@ final class DivinerAtomQuery
|
||||
$atom->attachBook($book);
|
||||
}
|
||||
|
||||
if ($this->needAtoms) {
|
||||
$atom_data = id(new DivinerLiveAtom())->loadAllWhere(
|
||||
'symbolPHID IN (%Ls)',
|
||||
mpull($atoms, 'getPHID'));
|
||||
$atom_data = mpull($atom_data, null, 'getSymbolPHID');
|
||||
|
||||
foreach ($atoms as $key => $atom) {
|
||||
$data = idx($atom_data, $atom->getPHID());
|
||||
if (!$data) {
|
||||
unset($atoms[$key]);
|
||||
continue;
|
||||
}
|
||||
$atom->attachAtom($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $atoms;
|
||||
}
|
||||
|
||||
@@ -73,6 +126,62 @@ final class DivinerAtomQuery
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->bookPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'bookPHID IN (%Ls)',
|
||||
$this->bookPHIDs);
|
||||
}
|
||||
|
||||
if ($this->types) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'type IN (%Ls)',
|
||||
$this->types);
|
||||
}
|
||||
|
||||
if ($this->names) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'name IN (%Ls)',
|
||||
$this->names);
|
||||
}
|
||||
|
||||
if ($this->contexts) {
|
||||
$with_null = false;
|
||||
$contexts = $this->contexts;
|
||||
foreach ($contexts as $key => $value) {
|
||||
if ($value === null) {
|
||||
unset($contexts[$key]);
|
||||
$with_null = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($contexts && $with_null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'context IN (%Ls) OR context IS NULL',
|
||||
$contexts);
|
||||
} else if ($contexts) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'context IN (%Ls)',
|
||||
$contexts);
|
||||
} else if ($with_null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'context IS NULL');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->indexes) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'atomIndex IN (%Ld)',
|
||||
$this->indexes);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
||||
Reference in New Issue
Block a user