Skip to content

Commit

Permalink
Merge pull request #15 from craftcms/feature/craft-5-support
Browse files Browse the repository at this point in the history
craft 5 support
  • Loading branch information
brandonkelly authored Mar 19, 2024
2 parents 3117d5f + f7c29fb commit ec41ce2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Fik FKs

## Unreleased

- Added Craft 5 compatibility.

## 2.0.0 - 2022-05-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/controllers/RestoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit ec41ce2

Please sign in to comment.