Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / calendar / query / PhabricatorCalendarImportLogQuery.php
blob81f309bdcaaf22e48439779dc5cf43d95beb75e2
1 <?php
3 final class PhabricatorCalendarImportLogQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $importPHIDs;
10 public function withIDs(array $ids) {
11 $this->ids = $ids;
12 return $this;
15 public function withPHIDs(array $phids) {
16 $this->phids = $phids;
17 return $this;
20 public function withImportPHIDs(array $phids) {
21 $this->importPHIDs = $phids;
22 return $this;
25 public function newResultObject() {
26 return new PhabricatorCalendarImportLog();
29 protected function loadPage() {
30 return $this->loadStandardPage($this->newResultObject());
33 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
34 $where = parent::buildWhereClauseParts($conn);
36 if ($this->ids !== null) {
37 $where[] = qsprintf(
38 $conn,
39 'log.id IN (%Ld)',
40 $this->ids);
43 if ($this->phids !== null) {
44 $where[] = qsprintf(
45 $conn,
46 'log.phid IN (%Ls)',
47 $this->phids);
50 if ($this->importPHIDs !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'log.importPHID IN (%Ls)',
54 $this->importPHIDs);
58 return $where;
61 protected function willFilterPage(array $page) {
62 $viewer = $this->getViewer();
64 $type_map = PhabricatorCalendarImportLogType::getAllLogTypes();
65 foreach ($page as $log) {
66 $type_constant = $log->getParameter('type');
68 $type_object = idx($type_map, $type_constant);
69 if (!$type_object) {
70 $type_object = new PhabricatorCalendarImportDefaultLogType();
73 $type_object = clone $type_object;
74 $log->attachLogType($type_object);
77 $import_phids = mpull($page, 'getImportPHID');
79 if ($import_phids) {
80 $imports = id(new PhabricatorCalendarImportQuery())
81 ->setViewer($viewer)
82 ->withPHIDs($import_phids)
83 ->execute();
84 $imports = mpull($imports, null, 'getPHID');
85 } else {
86 $imports = array();
89 foreach ($page as $key => $log) {
90 $import = idx($imports, $log->getImportPHID());
91 if (!$import) {
92 $this->didRejectResult($import);
93 unset($page[$key]);
94 continue;
97 $log->attachImport($import);
100 return $page;
103 protected function getPrimaryTableAlias() {
104 return 'log';
107 public function getQueryApplicationClass() {
108 return 'PhabricatorCalendarApplication';