@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 114 lines 2.6 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorRepositorySyncEvent> 5 */ 6final class PhabricatorRepositorySyncEventQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $repositoryPHIDs; 12 private $epochMin; 13 private $epochMax; 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 withRepositoryPHIDs(array $repository_phids) { 26 $this->repositoryPHIDs = $repository_phids; 27 return $this; 28 } 29 30 public function withEpochBetween($min, $max) { 31 $this->epochMin = $min; 32 $this->epochMax = $max; 33 return $this; 34 } 35 36 public function newResultObject() { 37 return new PhabricatorRepositorySyncEvent(); 38 } 39 40 protected function willFilterPage(array $events) { 41 $repository_phids = mpull($events, 'getRepositoryPHID'); 42 $repository_phids = array_filter($repository_phids); 43 44 if ($repository_phids) { 45 $repositories = id(new PhabricatorRepositoryQuery()) 46 ->setViewer($this->getViewer()) 47 ->withPHIDs($repository_phids) 48 ->execute(); 49 $repositories = mpull($repositories, null, 'getPHID'); 50 } else { 51 $repositories = array(); 52 } 53 54 foreach ($events as $key => $event) { 55 $phid = $event->getRepositoryPHID(); 56 57 if (empty($repositories[$phid])) { 58 unset($events[$key]); 59 $this->didRejectResult($event); 60 continue; 61 } 62 63 $event->attachRepository($repositories[$phid]); 64 } 65 66 return $events; 67 } 68 69 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 70 $where = parent::buildWhereClauseParts($conn); 71 72 if ($this->ids !== null) { 73 $where[] = qsprintf( 74 $conn, 75 'id IN (%Ld)', 76 $this->ids); 77 } 78 79 if ($this->phids !== null) { 80 $where[] = qsprintf( 81 $conn, 82 'phid IN (%Ls)', 83 $this->phids); 84 } 85 86 if ($this->repositoryPHIDs !== null) { 87 $where[] = qsprintf( 88 $conn, 89 'repositoryPHID IN (%Ls)', 90 $this->repositoryPHIDs); 91 } 92 93 if ($this->epochMin !== null) { 94 $where[] = qsprintf( 95 $conn, 96 'epoch >= %d', 97 $this->epochMin); 98 } 99 100 if ($this->epochMax !== null) { 101 $where[] = qsprintf( 102 $conn, 103 'epoch <= %d', 104 $this->epochMax); 105 } 106 107 return $where; 108 } 109 110 public function getQueryApplicationClass() { 111 return PhabricatorDiffusionApplication::class; 112 } 113 114}