@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 105 lines 2.3 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorWorkerBulkJob> 5 */ 6final class PhabricatorWorkerBulkJobQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $authorPHIDs; 12 private $bulkJobTypes; 13 private $statuses; 14 15 public function withIDs(array $ids) { 16 $this->ids = $ids; 17 return $this; 18 } 19 20 public function withPHIDs(array $phids) { 21 $this->phids = $phids; 22 return $this; 23 } 24 25 public function withAuthorPHIDs(array $author_phids) { 26 $this->authorPHIDs = $author_phids; 27 return $this; 28 } 29 30 public function withBulkJobTypes(array $job_types) { 31 $this->bulkJobTypes = $job_types; 32 return $this; 33 } 34 35 public function withStatuses(array $statuses) { 36 $this->statuses = $statuses; 37 return $this; 38 } 39 40 public function newResultObject() { 41 return new PhabricatorWorkerBulkJob(); 42 } 43 44 protected function willFilterPage(array $page) { 45 $map = PhabricatorWorkerBulkJobType::getAllJobTypes(); 46 47 foreach ($page as $key => $job) { 48 $implementation = idx($map, $job->getJobTypeKey()); 49 if (!$implementation) { 50 $this->didRejectResult($job); 51 unset($page[$key]); 52 continue; 53 } 54 $job->attachJobImplementation($implementation); 55 } 56 57 return $page; 58 } 59 60 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 61 $where = parent::buildWhereClauseParts($conn); 62 63 if ($this->ids !== null) { 64 $where[] = qsprintf( 65 $conn, 66 'id IN (%Ld)', 67 $this->ids); 68 } 69 70 if ($this->phids !== null) { 71 $where[] = qsprintf( 72 $conn, 73 'phid IN (%Ls)', 74 $this->phids); 75 } 76 77 if ($this->authorPHIDs !== null) { 78 $where[] = qsprintf( 79 $conn, 80 'authorPHID IN (%Ls)', 81 $this->authorPHIDs); 82 } 83 84 if ($this->bulkJobTypes !== null) { 85 $where[] = qsprintf( 86 $conn, 87 'bulkJobType IN (%Ls)', 88 $this->bulkJobTypes); 89 } 90 91 if ($this->statuses !== null) { 92 $where[] = qsprintf( 93 $conn, 94 'status IN (%Ls)', 95 $this->statuses); 96 } 97 98 return $where; 99 } 100 101 public function getQueryApplicationClass() { 102 return PhabricatorDaemonsApplication::class; 103 } 104 105}