3 include('../include/admin-header.php');
5 function merge_platforms($platform_to_merge, $destination_platform) {
8 $db->begin_transaction();
10 // First, move all test runs to the test configurations in the destination for all test configurations that
11 // exist in both the original platform and the platform into which we're merging.
12 if (!$db->query_and_get_affected_rows('UPDATE test_runs SET run_config = destination.config_id
13 FROM test_configurations as merged, test_configurations as destination
14 WHERE merged.config_platform = $1 AND destination.config_platform = $2 AND run_config = merged.config_id
15 AND destination.config_metric = merged.config_metric', array($platform_to_merge, $destination_platform))) {
16 $db->rollback_transaction();
17 return notice("Failed to migrate test runs for $platform_to_merge that have test configurations in $destination_platform.");
20 // Then migrate test configurations that don't exist in the destination platform to the new platform
21 // so that test runs associated with those configurations are moved to the destination.
22 if ($db->query_and_get_affected_rows('UPDATE test_configurations SET config_platform = $2
23 WHERE config_platform = $1 AND config_metric NOT IN (SELECT config_metric FROM test_configurations WHERE config_platform = $2)',
24 array($platform_to_merge, $destination_platform)) === FALSE) {
25 $db->rollback_transaction();
26 return notice("Failed to migrate test configurations for $platform_to_merge.");
29 if ($db->query_and_fetch_all('SELECT * FROM test_runs, test_configurations WHERE run_config = config_id AND config_platform = $1', array($platform_to_merge))) {
30 // We should never reach here.
31 $db->rollback_transaction();
32 return notice('Failed to migrate all test runs.');
35 $db->query_and_get_affected_rows('DELETE FROM platforms WHERE platform_id = $1', array($platform_to_merge));
36 $db->commit_transaction();
40 if ($action == 'update') {
41 if (update_field('platforms', 'platform', 'name')
42 || update_field('platforms', 'platform', 'hidden'))
43 regenerate_manifest();
45 notice('Invalid parameters.');
46 } else if ($action == 'merge')
47 merge_platforms(intval($_POST['id']), intval($_POST['destination']));
49 $platforms = $db->fetch_table('platforms', 'platform_name');
51 function merge_list($platform_row) {
55 $id = $platform_row['platform_id'];
57 <form method="POST"><input type="hidden" name="id" value="$id">
58 <select name="destination">
61 foreach ($platforms as $platform) {
62 if ($platform['platform_id'] == $id)
65 <option value="{$platform['platform_id']}">{$platform['platform_name']}</option>
71 <button type="submit" name="action" value="merge">Merge</button>
74 return array($content);
77 $page = new AdministrativePage($db, 'platforms', 'platform', array(
78 'name' => array('editing_mode' => 'string'),
79 'hidden' => array('editing_mode' => 'boolean'),
80 'merge into' => array('custom' => function ($platform_row) { return merge_list($platform_row); }),
83 $page->render_table('name');
86 include('../include/admin-footer.php');