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