| Conditions | 9 |
| Paths | 8 |
| Total Lines | 38 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 5 | public function run($request) { |
||
| 6 | $log = function($message) { |
||
| 7 | $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; |
||
| 8 | echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '<br>'); |
||
| 9 | }; |
||
| 10 | |||
| 11 | foreach (DB::query('SELECT "ID", "Status", "State" FROM "DNDeployment"') as $record) { |
||
| 12 | // This record looks to be already migrated |
||
| 13 | if (empty($record['Status'])) { |
||
| 14 | continue; |
||
| 15 | } |
||
| 16 | |||
| 17 | $obj = DNDeployment::get()->byId($record['ID']); |
||
| 18 | if (!$obj) { |
||
| 19 | $logFn(sprintf('Failed to get DNDeployment object for record ID %s', $record['ID'])); |
||
|
|
|||
| 20 | continue; |
||
| 21 | } |
||
| 22 | if ($record['Status'] === 'Queued') { |
||
| 23 | $obj->State = 'Queued'; |
||
| 24 | } elseif ($record['Status'] === 'Started') { |
||
| 25 | $obj->State = 'Deploying'; |
||
| 26 | } elseif ($record['Status'] === 'Finished') { |
||
| 27 | $obj->State = 'Completed'; |
||
| 28 | } elseif ($record['Status'] === 'Failed') { |
||
| 29 | $obj->State = 'Failed'; |
||
| 30 | } |
||
| 31 | $obj->write(); |
||
| 32 | |||
| 33 | // Blank out the old column, as it has been successfully migrated. |
||
| 34 | // Note that the field no longer exists on the DNDeployment object, so we have to |
||
| 35 | // manually run the update on the database. |
||
| 36 | DB::query(sprintf('UPDATE "DNDeployment" SET "Status" = NULL WHERE "ID" = %s', $record['ID'])); |
||
| 37 | |||
| 38 | $log(sprintf('DNDeployment record %s has been successfully migrated', $record['ID'])); |
||
| 39 | } |
||
| 40 | |||
| 41 | $log('Finished. Please delete the DNDeployment.Status column from the database'); |
||
| 42 | } |
||
| 43 | |||
| 45 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.