1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00
phorge-phorge/resources/sql/autopatches/20140706.harbormasterdepend.1.php
James Rhodes cad41ea294 Implement build simulation; convert Harbormaster to be purely dependency based
Summary:
Depends on D9806.  This implements the build simulator, which is used to calculate the order of build steps in the plan editor.  This includes a migration script to convert existing plans from sequential based to dependency based, and then drops the sequence column.

Because build plans are now dependency based, the grippable and re-order behaviour has been removed.

Test Plan: Tested the migration, saw the dependencies appear correctly.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9847
2014-07-31 11:39:49 +10:00

54 lines
1.4 KiB
PHP

<?php
$plan_table = new HarbormasterBuildPlan();
$step_table = new HarbormasterBuildStep();
$conn_w = $plan_table->establishConnection('w');
foreach (new LiskMigrationIterator($plan_table) as $plan) {
echo pht(
"Migrating build plan %d: %s...\n",
$plan->getID(),
$plan->getName());
// Load all build steps in order using the step sequence.
$steps = queryfx_all(
$conn_w,
'SELECT id FROM %T WHERE buildPlanPHID = %s ORDER BY sequence ASC;',
$step_table->getTableName(),
$plan->getPHID());
$previous_step = null;
foreach ($steps as $step) {
$id = $step['id'];
$loaded_step = id(new HarbormasterBuildStep())->load($id);
$depends_on = $loaded_step->getDetail('dependsOn');
if ($depends_on !== null) {
// This plan already contains steps with depends_on set, so
// we skip since there's nothing to migrate.
break;
}
if ($previous_step === null) {
$depends_on = array();
} else {
$depends_on = array($previous_step->getPHID());
}
$loaded_step->setDetail('dependsOn', $depends_on);
queryfx(
$conn_w,
'UPDATE %T SET details = %s WHERE id = %d',
$step_table->getTableName(),
json_encode($loaded_step->getDetails()),
$loaded_step->getID());
$previous_step = $loaded_step;
echo pht(
" Migrated build step %d.\n",
$loaded_step->getID());
}
}