mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 14:51:06 +01:00
Convert storage for Herald repetition policy to "text32"
Summary: Depends on D18926. Ref T6203. Ref T13048. Herald rule repetition policies are stored as integers but treated as strings in most contexts. After D18926, the integer stuff is almost totally hidden inside `HeraldRule` and getting rid of it completely isn't too tricky. Do so now. Test Plan: - Created "only the first time" and "every time" rules. Did a SELECT on their rows in the database. - Ran migrations, got a clean bill of health from `storage adjust`. - Did another SELECT on the rows, saw a faithful conversion to strings "every" and "first". - Edited and reviewed rules, swapping them between "every" and "first". Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13048, T6203 Differential Revision: https://secure.phabricator.com/D18927
This commit is contained in:
parent
1dd1237c92
commit
204d1de683
2 changed files with 26 additions and 30 deletions
22
resources/sql/autopatches/20180124.herald.01.repetition.sql
Normal file
22
resources/sql/autopatches/20180124.herald.01.repetition.sql
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* This column was previously "uint32?" with these values:
|
||||
|
||||
1: run every time
|
||||
0: run only the first time
|
||||
|
||||
*/
|
||||
|
||||
ALTER TABLE {$NAMESPACE}_herald.herald_rule
|
||||
CHANGE repetitionPolicy
|
||||
repetitionPolicy VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
||||
|
||||
/* If the old value was "0", the new value is "first". */
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_rule
|
||||
SET repetitionPolicy = 'first'
|
||||
WHERE repetitionPolicy = '0';
|
||||
|
||||
/* If the old value was anything else, the new value is "every". */
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_rule
|
||||
SET repetitionPolicy = 'every'
|
||||
WHERE repetitionPolicy NOT IN ('first', '0');
|
|
@ -41,13 +41,10 @@ final class HeraldRule extends HeraldDAO
|
|||
'contentType' => 'text255',
|
||||
'mustMatchAll' => 'bool',
|
||||
'configVersion' => 'uint32',
|
||||
'repetitionPolicy' => 'text32',
|
||||
'ruleType' => 'text32',
|
||||
'isDisabled' => 'uint32',
|
||||
'triggerObjectPHID' => 'phid?',
|
||||
|
||||
// T6203/NULLABILITY
|
||||
// This should not be nullable.
|
||||
'repetitionPolicy' => 'uint32?',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_name' => array(
|
||||
|
@ -261,27 +258,11 @@ final class HeraldRule extends HeraldDAO
|
|||
|
||||
|
||||
public function getRepetitionPolicyStringConstant() {
|
||||
$map = self::getRepetitionPolicyMap();
|
||||
$map = ipull($map, 'key.string', 'key.int');
|
||||
|
||||
return idx($map, $this->getRepetitionPolicyIntegerConstant());
|
||||
}
|
||||
|
||||
public function getRepetitionPolicyIntegerConstant() {
|
||||
$map = self::getRepetitionPolicyMap();
|
||||
$map = ipull($map, 'key.int', 'key.int');
|
||||
$int = $this->getRepetitionPolicy();
|
||||
|
||||
if (!isset($map[$int])) {
|
||||
return head_key($map);
|
||||
}
|
||||
|
||||
return $int;
|
||||
return $this->getRepetitionPolicy();
|
||||
}
|
||||
|
||||
public function setRepetitionPolicyStringConstant($value) {
|
||||
$map = self::getRepetitionPolicyMap();
|
||||
$map = ipull($map, 'key.int', 'key.string');
|
||||
|
||||
if (!isset($map[$value])) {
|
||||
throw new Exception(
|
||||
|
@ -290,9 +271,7 @@ final class HeraldRule extends HeraldDAO
|
|||
$value));
|
||||
}
|
||||
|
||||
$int = $map[$value];
|
||||
|
||||
return $this->setRepetitionPolicy($int);
|
||||
return $this->setRepetitionPolicy($value);
|
||||
}
|
||||
|
||||
public function isRepeatEvery() {
|
||||
|
@ -305,20 +284,15 @@ final class HeraldRule extends HeraldDAO
|
|||
|
||||
public static function getRepetitionPolicySelectOptionMap() {
|
||||
$map = self::getRepetitionPolicyMap();
|
||||
$map = ipull($map, 'select', 'key.string');
|
||||
return $map;
|
||||
return ipull($map, 'select');
|
||||
}
|
||||
|
||||
private static function getRepetitionPolicyMap() {
|
||||
return array(
|
||||
self::REPEAT_EVERY => array(
|
||||
'key.int' => 1,
|
||||
'key.string' => self::REPEAT_EVERY,
|
||||
'select' => pht('every time'),
|
||||
),
|
||||
self::REPEAT_FIRST => array(
|
||||
'key.int' => 0,
|
||||
'key.string' => self::REPEAT_FIRST,
|
||||
'select' => pht('only the first time'),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue