1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Add PHIDs to Herald Rules

Summary: Ref T2769. Precursor to various Herald-related modernizations.

Test Plan: Ran migration; loaded Herald via web.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

Differential Revision: https://secure.phabricator.com/D6648
This commit is contained in:
epriestley 2013-08-02 06:11:25 -07:00
parent d3e700ce19
commit 2820fdc89b
8 changed files with 135 additions and 0 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_herald.herald_rule
ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin;

View file

@ -0,0 +1,24 @@
<?php
$table = new HeraldRule();
$conn_w = $table->establishConnection('w');
echo "Assigning PHIDs to Herald Rules...\n";
foreach (new LiskMigrationIterator(new HeraldRule()) as $rule) {
$id = $rule->getID();
echo "Rule {$id}.\n";
if ($rule->getPHID()) {
continue;
}
queryfx(
$conn_w,
'UPDATE %T SET phid = %s WHERE id = %d',
$table->getTableName(),
PhabricatorPHID::generateNewPHID(HeraldPHIDTypeRule::TYPECONST),
$rule->getID());
}
echo "Done.\n";

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_herald.herald_rule
ADD UNIQUE KEY (phid);

View file

@ -617,6 +617,7 @@ phutil_register_library_map(array(
'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php',
'HeraldObjectAdapter' => 'applications/herald/adapter/HeraldObjectAdapter.php',
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
'HeraldRecursiveConditionsException' => 'applications/herald/engine/engine/HeraldRecursiveConditionsException.php',
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
@ -2621,6 +2622,7 @@ phutil_register_library_map(array(
'HeraldInvalidConditionException' => 'Exception',
'HeraldInvalidFieldException' => 'Exception',
'HeraldNewController' => 'HeraldController',
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
'HeraldRecursiveConditionsException' => 'Exception',
'HeraldRule' => 'HeraldDAO',
'HeraldRuleController' => 'HeraldController',

View file

@ -0,0 +1,45 @@
<?php
final class HeraldPHIDTypeRule extends PhabricatorPHIDType {
const TYPECONST = 'HRUL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Herald Rule');
}
public function newObject() {
return new HeraldRule();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HeraldRuleQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$rule = $objects[$phid];
$id = $rule->getID();
$name = $rule->getName();
$handle->setName($name);
$handle->setURI("/herald/rule/{$id}/");
}
}
}

View file

@ -2,10 +2,34 @@
final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery {
private $ids;
private $phids;
private $authorPHIDs;
private $ruleTypes;
private $contentTypes;
// TODO: Remove when this becomes policy-aware.
private $viewer;
public function setViewer($viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
@ -43,6 +67,20 @@ final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery {
private function buildWhereClause($conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'rule.id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'rule.phid IN (%Ls)',
$this->phids);
}
if ($this->authorPHIDs) {
$where[] = qsprintf(
$conn_r,

View file

@ -19,6 +19,16 @@ final class HeraldRule extends HeraldDAO {
private $conditions;
private $actions;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(HeraldPHIDTypeRule::TYPECONST);
}
public static function loadAllByContentTypeWithFullData(
$content_type,
$object_phid) {

View file

@ -1519,6 +1519,18 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'php',
'name' => $this->getPatchPath('20130805.pastemailkeypop.php'),
),
'20130802.heraldphid.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130802.heraldphid.sql'),
),
'20130802.heraldphids.php' => array(
'type' => 'php',
'name' => $this->getPatchPath('20130802.heraldphids.php'),
),
'20130802.heraldphidukey.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130802.heraldphidukey.sql'),
),
);
}
}