Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/query/HeraldRuleQuery.php
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public function needAppliedToPHIDs(array $phids) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needValidateAuthors($need) { | public function needValidateAuthors($need) { | ||||
$this->needValidateAuthors = $need; | $this->needValidateAuthors = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function newResultObject() { | ||||
$table = new HeraldRule(); | return new HeraldRule(); | ||||
$conn_r = $table->establishConnection('r'); | } | ||||
$data = queryfx_all( | |||||
$conn_r, | |||||
'SELECT rule.* FROM %T rule %Q %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $table->loadAllFromArray($data); | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | } | ||||
protected function willFilterPage(array $rules) { | protected function willFilterPage(array $rules) { | ||||
$rule_ids = mpull($rules, 'getID'); | $rule_ids = mpull($rules, 'getID'); | ||||
// Filter out any rules that have invalid adapters, or have adapters the | // Filter out any rules that have invalid adapters, or have adapters the | ||||
// viewer isn't permitted to see or use (for example, Differential rules | // viewer isn't permitted to see or use (for example, Differential rules | ||||
// if the user can't use Differential or Differential is not installed). | // if the user can't use Differential or Differential is not installed). | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | foreach ($rules as $key => $rule) { | ||||
} | } | ||||
$rule->attachTriggerObject($object); | $rule->attachTriggerObject($object); | ||||
} | } | ||||
} | } | ||||
return $rules; | return $rules; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.id IN (%Ld)', | 'rule.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.phid IN (%Ls)', | 'rule.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->authorPHIDs) { | if ($this->authorPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.authorPHID IN (%Ls)', | 'rule.authorPHID IN (%Ls)', | ||||
$this->authorPHIDs); | $this->authorPHIDs); | ||||
} | } | ||||
if ($this->ruleTypes) { | if ($this->ruleTypes !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.ruleType IN (%Ls)', | 'rule.ruleType IN (%Ls)', | ||||
$this->ruleTypes); | $this->ruleTypes); | ||||
} | } | ||||
if ($this->contentTypes) { | if ($this->contentTypes !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.contentType IN (%Ls)', | 'rule.contentType IN (%Ls)', | ||||
$this->contentTypes); | $this->contentTypes); | ||||
} | } | ||||
if ($this->disabled !== null) { | if ($this->disabled !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.isDisabled = %d', | 'rule.isDisabled = %d', | ||||
(int)$this->disabled); | (int)$this->disabled); | ||||
} | } | ||||
if ($this->datasourceQuery) { | if ($this->datasourceQuery !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.name LIKE %>', | 'rule.name LIKE %>', | ||||
$this->datasourceQuery); | $this->datasourceQuery); | ||||
} | } | ||||
if ($this->triggerObjectPHIDs) { | if ($this->triggerObjectPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'rule.triggerObjectPHID IN (%Ls)', | 'rule.triggerObjectPHID IN (%Ls)', | ||||
$this->triggerObjectPHIDs); | $this->triggerObjectPHIDs); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn); | return $where; | ||||
return $this->formatWhereClause($conn, $where); | |||||
} | } | ||||
private function validateRuleAuthors(array $rules) { | private function validateRuleAuthors(array $rules) { | ||||
// "Global" and "Object" rules always have valid authors. | // "Global" and "Object" rules always have valid authors. | ||||
foreach ($rules as $key => $rule) { | foreach ($rules as $key => $rule) { | ||||
if ($rule->isGlobalRule() || $rule->isObjectRule()) { | if ($rule->isGlobalRule() || $rule->isObjectRule()) { | ||||
$rule->attachValidAuthor(true); | $rule->attachValidAuthor(true); | ||||
unset($rules[$key]); | unset($rules[$key]); | ||||
Show All 28 Lines | foreach ($rules as $key => $rule) { | ||||
$rule->attachAuthor($users[$author_phid]); | $rule->attachAuthor($users[$author_phid]); | ||||
} | } | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorHeraldApplication'; | return 'PhabricatorHeraldApplication'; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | |||||
return 'rule'; | |||||
} | |||||
} | } |