Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

craft 5 support #15

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading