diff --git a/CHANGELOG.md b/CHANGELOG.md index d4ac3a2..1c23049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Fik FKs +## Unreleased + +- Added Craft 5 compatibility. + ## 2.0.0 - 2022-05-03 ### Added diff --git a/README.md b/README.md index 878d797..c5956ef 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This plugin enables users to restore foreign key constraints in their database. ## Requirements -This plugin requires Craft CMS 4.0 or later. +This plugin requires Craft CMS 4.0.0+ or 5.0.0+. ## Installation diff --git a/composer.json b/composer.json index 795d190..88d8a8b 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "craftcms/cms": "^4.0.0-RC3" + "craftcms/cms": "^4.0.0-RC3|^5.0.0-beta.1" }, "require-dev": { "craftcms/ecs": "dev-main", diff --git a/composer.lock b/composer.lock index fea07e8..92ff64d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e1171bc04645c3bd6510af007c2ff899", + "content-hash": "5e05c4b7e5fbb87d914ca9163fdc675b", "packages": [ { "name": "cebe/markdown", diff --git a/src/Plugin.php b/src/Plugin.php index eb7c065..f95c314 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -26,10 +26,15 @@ public function init() { parent::init(); + $eventName = defined(sprintf('%s::EVENT_REGISTER_UTILITY_TYPES', Utilities::class)) + ? Utilities::EVENT_REGISTER_UTILITY_TYPES // Craft 4 + /** @phpstan-ignore-next-line */ + : Utilities::EVENT_REGISTER_UTILITIES; // Craft 5+ + // Register our query utility. Event::on( Utilities::class, - Utilities::EVENT_REGISTER_UTILITY_TYPES, + $eventName, function(RegisterComponentTypesEvent $event) { $event->types[] = Utility::class; } diff --git a/src/Utility.php b/src/Utility.php index 9fc3e86..cb014db 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -38,7 +38,7 @@ public static function id(): string */ public static function iconPath(): ?string { - return Craft::getAlias('@app/icons/database.svg'); + return Craft::getAlias('@appicons/database.svg'); } /** diff --git a/src/controllers/RestoreController.php b/src/controllers/RestoreController.php index 5bef13b..fd99366 100644 --- a/src/controllers/RestoreController.php +++ b/src/controllers/RestoreController.php @@ -46,14 +46,16 @@ public function actionIndex() // Add default FKs (new Install())->addForeignKeys(); - // Add Matrix FKs - $fields = Craft::$app->getFields()->getAllFields(); - foreach ($fields as $field) { - if ($field instanceof Matrix) { - $migration = new CreateMatrixContentTable([ - 'tableName' => $field->contentTable, - ]); - $migration->addForeignKeys(); + if (version_compare(Craft::$app->getVersion(), '5.0.0-beta.1', '<')) { + // Add Matrix FKs + $fields = Craft::$app->getFields()->getAllFields(); + foreach ($fields as $field) { + if ($field instanceof Matrix) { + $migration = new CreateMatrixContentTable([ + 'tableName' => $field->contentTable, + ]); + $migration->addForeignKeys(); + } } }