Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/autopatches/20140210.herald.rule-condition-mig.php
| <?php | <?php | ||||
| $table = new HeraldCondition(); | $table = new HeraldCondition(); | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| echo "Migrating Herald conditions of type Herald rule from IDs to PHIDs...\n"; | echo pht( | ||||
| "Migrating Herald conditions of type Herald rule from IDs to PHIDs...\n"); | |||||
| foreach (new LiskMigrationIterator($table) as $condition) { | foreach (new LiskMigrationIterator($table) as $condition) { | ||||
| if ($condition->getFieldName() != HeraldAdapter::FIELD_RULE) { | if ($condition->getFieldName() != HeraldAdapter::FIELD_RULE) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $value = $condition->getValue(); | $value = $condition->getValue(); | ||||
| if (!is_numeric($value)) { | if (!is_numeric($value)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $id = $condition->getID(); | $id = $condition->getID(); | ||||
| echo "Updating condition {$id}...\n"; | echo pht('Updating condition %s...', $id)."\n"; | ||||
| $rule = id(new HeraldRuleQuery()) | $rule = id(new HeraldRuleQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withIDs(array($value)) | ->withIDs(array($value)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET value = %s WHERE id = %d', | 'UPDATE %T SET value = %s WHERE id = %d', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| json_encode($rule->getPHID()), | json_encode($rule->getPHID()), | ||||
| $id); | $id); | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||