Skip to content

Commit

Permalink
Fixed #3662
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Jan 18, 2019
1 parent 3f687f4 commit 492b9cf
Show file tree
Hide file tree
Showing 3 changed files with 27 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 @@ -18,6 +18,7 @@
- Fixed a bug where an update to Craft 3.1 would fail with a database error in some scenarios.
- Fixed a bug where Plugin Store’s Try buttons would appear as disabled when they should be enabled. ([#3619](https://github.com/craftcms/cms/issues/3619))
- Fixed an error that occurred when updating to Craft 3.1 if there were any relational fields that were missing some expected settings. ([#3641](https://github.com/craftcms/cms/issues/3641))
- Fixed an error that occurred when updating to Craft 3.1 if there were any Matrix sub-fields that had their type set to a non-existing type. ([#3662](https://github.com/craftcms/cms/issues/3662))

### Security
- Fixed two XSS vulnerabilities.
Expand Down
13 changes: 13 additions & 0 deletions src/migrations/m190108_113000_asset_field_setting_change.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Craft;
use craft\db\Migration;
use craft\db\Query;
use craft\db\Table;
use craft\fields\Assets;
use craft\helpers\Json;
use craft\services\Fields;
use craft\services\Matrix;

Expand Down Expand Up @@ -41,6 +43,7 @@ public function safeUp()

// Get the field data from the project config
$fields = $projectConfig->get(Fields::CONFIG_FIELDS_KEY) ?? [];
$projectConfig->muteEvents = true;

foreach ($fields as $fieldUid => $fieldData) {
if ($fieldData['type'] === Assets::class) {
Expand All @@ -53,6 +56,10 @@ public function safeUp()
}

$projectConfig->set(Fields::CONFIG_FIELDS_KEY . '.' . $fieldUid, $fieldData);

if (!empty($fieldData['settings'])) {
$this->update(Table::FIELDS, ['settings' => Json::encode($fieldData['settings'])], ['uid' => $fieldUid]);
}
}
}

Expand All @@ -77,7 +84,13 @@ public function safeUp()
}

$projectConfig->set(Matrix::CONFIG_BLOCKTYPE_KEY . '.' . $matrixBlockTypeUid, $matrixBlockType);

if (!empty($fieldData['settings'])) {
$this->update(Table::FIELDS, ['settings' => Json::encode($fieldData['settings'])], ['uid' => $fieldUid]);
}
}

$projectConfig->muteEvents = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Craft;
use craft\db\Migration;
use craft\db\Query;
use craft\db\Table;
use craft\fields\Assets;
use craft\helpers\Json;
use craft\services\Fields;
use craft\services\Matrix;

Expand Down Expand Up @@ -41,6 +43,7 @@ public function safeUp()

// Get the field data from the project config
$fields = $projectConfig->get(Fields::CONFIG_FIELDS_KEY) ?? [];
$projectConfig->muteEvents = true;

foreach ($fields as $fieldUid => $fieldData) {
if ($fieldData['type'] === Assets::class && !empty($fieldData['settings']['sources'])) {
Expand All @@ -54,6 +57,10 @@ public function safeUp()
}

$projectConfig->set(Fields::CONFIG_FIELDS_KEY . '.' . $fieldUid, $fieldData);

if (!empty($fieldData['settings'])) {
$this->update(Table::FIELDS, ['settings' => Json::encode($fieldData['settings'])], ['uid' => $fieldUid]);
}
}
}

Expand All @@ -79,10 +86,15 @@ public function safeUp()
}
}
}
unset($fieldData);

$projectConfig->set(Matrix::CONFIG_BLOCKTYPE_KEY . '.' . $matrixBlockTypeUid, $matrixBlockType);

if (!empty($fieldData['settings'])) {
$this->update(Table::FIELDS, ['settings' => Json::encode($fieldData['settings'])], ['uid' => $fieldUid]);
}
}

$projectConfig->muteEvents = false;
}

/**
Expand Down

0 comments on commit 492b9cf

Please sign in to comment.