Total Complexity | 3 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
8 | class Migration1604502151AddThemePreviewMediaConstraint extends MigrationStep |
||
9 | { |
||
10 | public function getCreationTimestamp(): int |
||
13 | } |
||
14 | |||
15 | public function update(Connection $connection): void |
||
16 | { |
||
17 | // get all themes where preview_media_id is invalid |
||
18 | $themeIdsWithInvalidMediaId = $connection->executeQuery(' |
||
19 | SELECT `theme`.`id` FROM `theme` |
||
20 | LEFT OUTER JOIN `media` ON `theme`.`preview_media_id` = `media`.`id` |
||
21 | WHERE `media`.`id` IS null |
||
22 | ')->fetchColumn(); |
||
23 | |||
24 | $connection->executeUpdate(' |
||
25 | UPDATE `theme` SET `theme`.`preview_media_id` = null |
||
26 | WHERE `theme`.`id` IN (:theme_ids) |
||
27 | ', ['theme_ids' => $themeIdsWithInvalidMediaId]); |
||
28 | |||
29 | $connection->exec(' |
||
30 | ALTER TABLE `theme` |
||
31 | ADD FOREIGN KEY `fk.theme.preview_media_id`(preview_media_id) REFERENCES media(id) |
||
32 | ON UPDATE CASCADE |
||
33 | ON DELETE SET NULL; |
||
34 | '); |
||
35 | } |
||
36 | |||
37 | public function updateDestructive(Connection $connection): void |
||
39 | // nth |
||
40 | } |
||
42 |