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:
parent
d3e700ce19
commit
2820fdc89b
8 changed files with 135 additions and 0 deletions
2
resources/sql/patches/20130802.heraldphid.sql
Normal file
2
resources/sql/patches/20130802.heraldphid.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_herald.herald_rule
|
||||
ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin;
|
24
resources/sql/patches/20130802.heraldphids.php
Normal file
24
resources/sql/patches/20130802.heraldphids.php
Normal 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";
|
2
resources/sql/patches/20130802.heraldphidukey.sql
Normal file
2
resources/sql/patches/20130802.heraldphidukey.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_herald.herald_rule
|
||||
ADD UNIQUE KEY (phid);
|
|
@ -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',
|
||||
|
|
45
src/applications/herald/phid/HeraldPHIDTypeRule.php
Normal file
45
src/applications/herald/phid/HeraldPHIDTypeRule.php
Normal 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}/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue