Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20131205.buildstepordermig.php
| <?php | <?php | ||||
| $table = new HarbormasterBuildPlan(); | $table = new HarbormasterBuildPlan(); | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| $viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
| // Since HarbormasterBuildStepQuery has been updated to handle the | // Since HarbormasterBuildStepQuery has been updated to handle the | ||||
| // correct order, we can't use the built in database access. | // correct order, we can't use the built in database access. | ||||
| foreach (new LiskMigrationIterator($table) as $plan) { | foreach (new LiskMigrationIterator($table) as $plan) { | ||||
| $planname = $plan->getName(); | $planname = $plan->getName(); | ||||
| echo "Migrating steps in {$planname}...\n"; | echo "Migrating steps in {$planname}...\n"; | ||||
| $rows = queryfx_all( | $rows = queryfx_all( | ||||
| $conn_w, | $conn_w, | ||||
| "SELECT id, sequence FROM harbormaster_buildstep ". | 'SELECT id, sequence FROM harbormaster_buildstep '. | ||||
| "WHERE buildPlanPHID = %s ". | 'WHERE buildPlanPHID = %s '. | ||||
| "ORDER BY id ASC", | 'ORDER BY id ASC', | ||||
| $plan->getPHID()); | $plan->getPHID()); | ||||
| $sequence = 1; | $sequence = 1; | ||||
| foreach ($rows as $row) { | foreach ($rows as $row) { | ||||
| $id = $row['id']; | $id = $row['id']; | ||||
| $existing = $row['sequence']; | $existing = $row['sequence']; | ||||
| if ($existing != 0) { | if ($existing != 0) { | ||||
| echo " - {$id} (already migrated)...\n"; | echo " - {$id} (already migrated)...\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| echo " - {$id} to position {$sequence}...\n"; | echo " - {$id} to position {$sequence}...\n"; | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| "UPDATE harbormaster_buildstep ". | 'UPDATE harbormaster_buildstep '. | ||||
| "SET sequence = %d ". | 'SET sequence = %d '. | ||||
| "WHERE id = %d", | 'WHERE id = %d', | ||||
| $sequence, | $sequence, | ||||
| $id); | $id); | ||||
| $sequence++; | $sequence++; | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo "Done.\n"; | ||||