|
| 1 | +<?php |
| 2 | + |
| 3 | +// Convert dashboards to a new storage format. The old storage format looks |
| 4 | +// like this: |
| 5 | + |
| 6 | +// { |
| 7 | +// "0": ["PHID-DSHP-A", ...], |
| 8 | +// "1": ["PHID-DSHP-B", ...] |
| 9 | +// } |
| 10 | + |
| 11 | +// The new storage format looks like this: |
| 12 | + |
| 13 | +// [ |
| 14 | +// { |
| 15 | +// "panelKey": "abcdefgh", |
| 16 | +// "panelPHID": "PHID-DSHP-A", |
| 17 | +// "columnKey": "left" |
| 18 | +// }, |
| 19 | +// ... |
| 20 | +// ] |
| 21 | + |
| 22 | +// One major issue with the old storage format is that when multiple copies of |
| 23 | +// a single dashboard panel appeared on the same dashboard, the UI had a lot |
| 24 | +// of difficulty acting on a particular copy because copies were identified |
| 25 | +// only by PHID and all copies of the same panel have the same panel PHID. |
| 26 | + |
| 27 | +$dashboard_table = new PhabricatorDashboard(); |
| 28 | +$conn = $dashboard_table->establishConnection('r'); |
| 29 | +$table_name = $dashboard_table->getTableName(); |
| 30 | + |
| 31 | +$rows = new LiskRawMigrationIterator($conn, $table_name); |
| 32 | +foreach ($rows as $row) { |
| 33 | + $config = $row['layoutConfig']; |
| 34 | + |
| 35 | + try { |
| 36 | + $config = phutil_json_decode($config); |
| 37 | + } catch (Exception $ex) { |
| 38 | + $config = array(); |
| 39 | + } |
| 40 | + |
| 41 | + if (!is_array($config)) { |
| 42 | + $config = array(); |
| 43 | + } |
| 44 | + |
| 45 | + $panels = idx($config, 'panelLocations'); |
| 46 | + if (!is_array($panels)) { |
| 47 | + $panels = array(); |
| 48 | + } |
| 49 | + |
| 50 | + if (idx($config, 'layoutMode') === 'layout-mode-full') { |
| 51 | + $column_map = array( |
| 52 | + 0 => 'main', |
| 53 | + ); |
| 54 | + } else { |
| 55 | + $column_map = array( |
| 56 | + 0 => 'left', |
| 57 | + 1 => 'right', |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + $panel_list = array(); |
| 62 | + foreach ($panels as $column_idx => $panel_phids) { |
| 63 | + $column_key = idx($column_map, $column_idx, 'unknown'); |
| 64 | + foreach ($panel_phids as $panel_phid) { |
| 65 | + $panel_list[] = array( |
| 66 | + 'panelKey' => Filesystem::readRandomCharacters(8), |
| 67 | + 'columnKey' => $column_key, |
| 68 | + 'panelPHID' => $panel_phid, |
| 69 | + ); |
| 70 | + } |
| 71 | + } |
| 72 | + unset($config['panelLocations']); |
| 73 | + $config['panels'] = $panel_list; |
| 74 | + |
| 75 | + queryfx( |
| 76 | + $conn, |
| 77 | + 'UPDATE %R SET layoutConfig = %s WHERE id = %d', |
| 78 | + $dashboard_table, |
| 79 | + phutil_json_encode($config), |
| 80 | + $row['id']); |
| 81 | +} |
0 commit comments