Ejemplo n.º 1
0
 protected function loadPage()
 {
     $table = 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);
 }
Ejemplo n.º 2
0
 public function execute()
 {
     $table = new HeraldRule();
     $conn_r = $table->establishConnection('r');
     $where = $this->buildWhereClause($conn_r);
     $order = $this->buildOrderClause($conn_r);
     $limit = $this->buildLimitClause($conn_r);
     $data = queryfx_all($conn_r, 'SELECT rule.* FROM %T rule %Q %Q %Q', $table->getTableName(), $where, $order, $limit);
     return $table->loadAllFromArray($data);
 }
 private function queryRules(AphrontPagerView $pager)
 {
     $rule = new HeraldRule();
     $conn_r = $rule->establishConnection('r');
     $where_clause = qsprintf($conn_r, 'WHERE contentType = %s', $this->view);
     if ($this->viewPHID) {
         $where_clause .= qsprintf($conn_r, ' AND authorPHID = %s', $this->viewPHID);
     }
     $data = queryfx_all($conn_r, 'SELECT * FROM %T
     %Q
     ORDER BY id DESC
     LIMIT %d, %d', $rule->getTableName(), $where_clause, $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $rules = $rule->loadAllFromArray($data);
     $need_phids = mpull($rules, 'getAuthorPHID');
     if ($this->viewPHID) {
         $need_phids[] = $this->viewPHID;
     }
     $handles = id(new PhabricatorObjectHandleData($need_phids))->loadHandles();
     return array($rules, $handles);
 }
Ejemplo n.º 4
0
<?php

echo pht('Cleaning up old Herald rule applied rows...') . "\n";
$table = new HeraldRule();
$table->openTransaction();
$table->beginReadLocking();
$rules = $table->loadAll();
foreach ($rules as $key => $rule) {
    $first_policy = HeraldRepetitionPolicyConfig::toInt(HeraldRepetitionPolicyConfig::FIRST);
    if ($rule->getRepetitionPolicy() != $first_policy) {
        unset($rules[$key]);
    }
}
$conn_w = $table->establishConnection('w');
$clause = '';
if ($rules) {
    $clause = qsprintf($conn_w, 'WHERE ruleID NOT IN (%Ld)', mpull($rules, 'getID'));
}
echo pht('This may take a moment') . "\n";
do {
    queryfx($conn_w, 'DELETE FROM %T %Q LIMIT 1000', HeraldRule::TABLE_RULE_APPLIED, $clause);
    echo '.';
} while ($conn_w->getAffectedRows());
$table->endReadLocking();
$table->saveTransaction();
echo "\n" . pht('Done.') . "\n";