Skip to content
Merged
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
31 changes: 31 additions & 0 deletions src/migrations/m260220_182920_drop_cke_configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use Craft;
use craft\ckeditor\Field;
use craft\db\Migration;
use craft\db\Query;
use craft\db\Table;
use craft\helpers\ArrayHelper;
use craft\helpers\Json;
use craft\helpers\ProjectConfig;
use Throwable;

/**
* m260220_182920_drop_cke_configs migration.
Expand All @@ -29,6 +33,14 @@ public function safeUp(): bool
}

$settings = ProjectConfig::unpackAssociativeArrays($fieldConfig['settings']);

// if we've already lost the ckeConfig and we have some new properties (e.g. toolbar)
// we need to get the "old" field's settings directly from the database (not from the memoized array)
if (!isset($settings['ckeConfig']) && isset($settings['toolbar'])) {
$fieldUid = str_replace('fields.', '', $fieldPath);
$settings = $this->getOldFieldSettings($fieldUid) ?? $settings;
}

$ckeConfigUid = ArrayHelper::remove($settings, 'ckeConfig');
$expandEntryButtons = ArrayHelper::remove($settings, 'expandEntryButtons') ?? false;

Expand Down Expand Up @@ -90,4 +102,23 @@ public function safeDown(): bool
echo "m260220_182920_drop_cke_configs cannot be reverted.\n";
return false;
}

private function getOldFieldSettings(string $fieldUid): ?array
{
$settings = (new Query())
->select('settings')
->from(['fields' => Table::FIELDS])
->where(['uid' => $fieldUid])
->scalar();

if ($settings) {
try {
return Json::decode($settings);
} catch (Throwable $e) {
// fail silently
}
}

return null;
}
}
Loading