Skip to content

Commit

Permalink
Fix #3677
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Jan 21, 2019
1 parent 662e9ae commit b0a6b51
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- Fixed an error that occurred when updating to Craft 3.1 if a plugin or module was calling any soft-deletable records’ `find()` methods.
- Fixed an error that occurred when updating from Craft 2 to Craft 3.1 if there were any RichText fields. ([#3677](https://github.com/craftcms/cms/issues/3677))

## 3.1.2.2 - 2019-01-19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function safeUp()
$fields = (new Query())
->select(['id', 'settings'])
->from([Table::FIELDS])
->where(['type' => 'craft\\redactor\\Fields'])
->where(['type' => 'craft\\redactor\\Field'])
->all($this->db);

foreach ($fields as $field) {
Expand Down
45 changes: 45 additions & 0 deletions src/migrations/m190121_120000_fix_redactor_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace craft\migrations;

use craft\db\Migration;
use craft\db\Query;
use craft\db\Table;
use craft\helpers\ArrayHelper;
use craft\helpers\Json;

/**
* m190121_120000_fix_redactor_settings migration.
*/
class m190121_120000_fix_redactor_settings extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$fields = (new Query())
->select(['id', 'settings'])
->from([Table::FIELDS])
->where(['type' => 'craft\\redactor\\Field'])
->all($this->db);

foreach ($fields as $field) {
$settings = Json::decode($field['settings']);
if (is_array($settings) && array_key_exists('availableAssetSources', $settings)) {
$settings['availableVolumes'] = ArrayHelper::remove($settings, 'availableAssetSources');
$this->update(Table::FIELDS, ['settings' => Json::encode($settings)], ['id' => $field['id']]);
}
}
}

/**
* @inheritdoc
*/
public function safeDown()
{
echo "m190121_120000_fix_redactor_settings cannot be reverted.\n";

return false;
}
}

0 comments on commit b0a6b51

Please sign in to comment.