Skip to content

Commit

Permalink
Fixed #3641
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Jan 16, 2019
1 parent 80c2a10 commit 2370eda
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed a bug where the `clear-caches/cp-resources` command could clear out the wrong directory if the `resourceBasePath` config setting began with `@webroot`. ([#3637](https://github.com/craftcms/cms/issues/3637))
- Fixed an error that occurred when updating to Craft 3.1 if there were any Matrix blocks without any sub-fields. ([#3635](https://github.com/craftcms/cms/pull/3635))
- Fixed an error that occurred when updating to Craft 3.1 if there were any Matrix block types left over from a Matrix field that had been converted to something else.
- Fixed an error that occurred when updating to Craft 3.1 if there were any asset fields that were created before creating an asset volume first.

### Security
- Fixed an XSS vulnerability.
Expand Down
41 changes: 29 additions & 12 deletions src/migrations/m180516_153000_uids_in_field_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function safeUp()

switch ($field['type']) {
case Assets::class:
list(, $folderIds[]) = explode(':', $settings['defaultUploadLocationSource']);
list(, $folderIds[]) = explode(':', $settings['singleUploadLocationSource']);
if (strpos($settings['defaultUploadLocationSource'], ':') !== false) {
list(, $folderIds[]) = explode(':', $settings['defaultUploadLocationSource']);
}
if (strpos($settings['singleUploadLocationSource'], ':') !== false) {
list(, $folderIds[]) = explode(':', $settings['singleUploadLocationSource']);
}

if (is_array($settings['sources'])) {
foreach ($settings['sources'] as $source) {
Expand Down Expand Up @@ -80,11 +84,15 @@ public function safeUp()

break;
case Categories::class:
list(, $categoryGroupIds[]) = explode(':', $settings['source']);
if (strpos($settings['source'], ':') !== false) {
list(, $categoryGroupIds[]) = explode(':', $settings['source']);
}

break;
case Tags::class:
list(, $tagGroupIds[]) = explode(':', $settings['source']);
if (strpos($settings['source'], ':') !== false) {
list(, $tagGroupIds[]) = explode(':', $settings['source']);
}

break;
}
Expand Down Expand Up @@ -139,11 +147,16 @@ public function safeUp()

switch ($field['type']) {
case Assets::class:
$default = explode(':', $settings['defaultUploadLocationSource']);
$single = explode(':', $settings['singleUploadLocationSource']);
if (strpos($settings['defaultUploadLocationSource'], ':') !== false) {
$default = explode(':', $settings['defaultUploadLocationSource']);
$settings['defaultUploadLocationSource'] = isset($folders[$default[1]]) ? $default[0] . ':' . $folders[$default[1]] : null;
}

if (strpos($settings['singleUploadLocationSource'], ':') !== false) {
$single = explode(':', $settings['singleUploadLocationSource']);
$settings['singleUploadLocationSource'] = isset($folders[$single[1]]) ? $single[0] . ':' . $folders[$single[1]] : null;
}

$settings['defaultUploadLocationSource'] = isset($folders[$default[1]]) ? $default[0] . ':' . $folders[$default[1]] : null;
$settings['singleUploadLocationSource'] = isset($folders[$single[1]]) ? $single[0] . ':' . $folders[$single[1]] : null;

if (is_array($settings['sources'])) {
$newSources = [];
Expand Down Expand Up @@ -197,13 +210,17 @@ public function safeUp()

break;
case Categories::class:
$source = explode(':', $settings['source']);
$settings['source'] = $source[0] . ':' . ($categoryGroups[$source[1]] ?? $source[1]);
if (strpos($settings['source'], ':') !== false) {
$source = explode(':', $settings['source']);
$settings['source'] = $source[0] . ':' . ($categoryGroups[$source[1]] ?? $source[1]);
}

break;
case Tags::class:
$source = explode(':', $settings['source']);
$settings['source'] = $source[0] . ':' . ($tagGroups[$source[1]] ?? $source[1]);
if (strpos($settings['source'], ':') !== false) {
$source = explode(':', $settings['source']);
$settings['source'] = $source[0] . ':' . ($tagGroups[$source[1]] ?? $source[1]);
}

break;
}
Expand Down

0 comments on commit 2370eda

Please sign in to comment.