From ed154b846b1e786746a0a55d02554aa3d7b05f80 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 28 Aug 2024 08:13:29 +0100 Subject: [PATCH 1/9] only validate visible fields --- src/fields/Assets.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fields/Assets.php b/src/fields/Assets.php index 2ef87beee4c..0e454d020b8 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -242,11 +242,23 @@ protected function defineRules(): array [ 'sources', 'defaultUploadLocationSource', - 'restrictedLocationSource', 'defaultUploadLocationSubpath', + ], + 'validateNotTempVolume', + 'when' => function(self $field): bool { + return (bool)$field->restrictLocation === false; + }, + ]; + + $rules[] = [ + [ + 'restrictedLocationSource', 'restrictedLocationSubpath', ], 'validateNotTempVolume', + 'when' => function(self $field): bool { + return (bool)$field->restrictLocation; + }, ]; $rules[] = [['previewMode'], 'in', 'range' => [self::PREVIEW_MODE_FULL, self::PREVIEW_MODE_THUMBS], 'skipOnEmpty' => false]; From c8bf87323dd5f90dfe8226238ad8c43df772300d Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 28 Aug 2024 08:46:03 +0100 Subject: [PATCH 2/9] set x-robots-tag for preview links too --- src/web/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/web/Application.php b/src/web/Application.php index f934e83aedc..072c34b624e 100644 --- a/src/web/Application.php +++ b/src/web/Application.php @@ -191,6 +191,7 @@ public function handleRequest($request, bool $skipSpecialHandling = false): Base $generalConfig->disallowRobots || $request->getIsCpRequest() || $request->getToken() !== null || + $request->getIsPreview() || ($request->getIsActionRequest() && !($request->getIsLoginRequest() && $request->getIsGet())) ) { $headers->set('X-Robots-Tag', 'none'); From 9f170f284434ecd949c8c1d8bb863e350b32ccd3 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 28 Aug 2024 14:19:37 +0100 Subject: [PATCH 3/9] when ordering by value from json col, cast text to char --- src/base/Field.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/base/Field.php b/src/base/Field.php index 591207913f0..1618686a0f6 100644 --- a/src/base/Field.php +++ b/src/base/Field.php @@ -773,15 +773,31 @@ public function getPreviewHtml(mixed $value, ElementInterface $element): string */ public function getSortOption(): array { - if (static::dbType() === null || !isset($this->layoutElement)) { + $dbType = static::dbType(); + if ($dbType === null || !isset($this->layoutElement)) { throw new NotSupportedException('getSortOption() not supported by ' . $this->name); } + $orderBy = $this->getValueSql(); + + // for mysql, we have to make sure text column type is cast to char, otherwise it won't be sorted correctly + // see https://github.com/craftcms/cms/issues/15609 + $db = Craft::$app->getDb(); + if ($db->getIsMysql()) { + $castType = match (Db::parseColumnType($dbType)) { + Schema::TYPE_TEXT => 'CHAR(255)', + default => null, + }; + if ($castType !== null) { + $orderBy = "CAST($orderBy AS $castType)"; + } + } + // The attribute name should match the table attribute name, // per ElementSources::getTableAttributesForFieldLayouts() return [ 'label' => Craft::t('site', $this->name), - 'orderBy' => $this->getValueSql(), + 'orderBy' => $orderBy, 'attribute' => isset($this->layoutElement->handle) ? "fieldInstance:{$this->layoutElement->uid}" : "field:$this->uid", From 2ce4b5babe94f6f9b1d016440ea2c8d9817ead34 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 28 Aug 2024 10:52:35 -0700 Subject: [PATCH 4/9] Fixed #15570 --- CHANGELOG.md | 1 + src/fields/BaseRelationField.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 239a1190779..222e9221cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592)) - Fixed a bug where tabs within field layout designers weren’t always getting positioned correctly when wrapped. ([#15590](https://github.com/craftcms/cms/issues/15590)) - Fixed a bug where editable table rows’ action buttons were misaligned for newly-created rows. ([#15602](https://github.com/craftcms/cms/issues/15602)) +- Fixed a bug where relational fields’ element query results weren’t limited to the selected relations if the `id` param was overridden. ([#15570](https://github.com/craftcms/cms/issues/15570)) ## 5.3.6 - 2024-08-26 diff --git a/src/fields/BaseRelationField.php b/src/fields/BaseRelationField.php index 64a65ba5302..300a69dbbec 100644 --- a/src/fields/BaseRelationField.php +++ b/src/fields/BaseRelationField.php @@ -18,6 +18,7 @@ use craft\base\NestedElementInterface; use craft\base\RelationalFieldInterface; use craft\behaviors\EventBehavior; +use craft\db\FixedOrderExpression; use craft\db\Query; use craft\db\Table as DbTable; use craft\elements\conditions\ElementCondition; @@ -674,9 +675,14 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed ->siteId($this->targetSiteId($element)); if (is_array($value)) { - $query - ->id(array_values(array_filter($value))) - ->fixedOrder(); + $value = array_values(array_filter($value)); + if (!empty($value)) { + $query + ->andWhere(['elements.id' => $value]) + ->orderBy([new FixedOrderExpression('elements.id', $value, Craft::$app->getDb())]); + } else { + $query->andWhere('0 = 1'); + } } elseif ($value === null && $element?->id && $this->isFirstInstance($element)) { // If $value is null, the element + field haven’t been saved since updating to Craft 5.3+, // or since the field was added to the field layout. So only actually look at the `relations` table From 20432f56a06aec8f5537bff573716b79518fb4f0 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 28 Aug 2024 11:15:18 -0700 Subject: [PATCH 5/9] Cleanup --- src/fields/Assets.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/fields/Assets.php b/src/fields/Assets.php index 0e454d020b8..c5f1754b071 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -245,9 +245,7 @@ protected function defineRules(): array 'defaultUploadLocationSubpath', ], 'validateNotTempVolume', - 'when' => function(self $field): bool { - return (bool)$field->restrictLocation === false; - }, + 'when' => fn() => !$this->restrictLocation, ]; $rules[] = [ @@ -256,9 +254,7 @@ protected function defineRules(): array 'restrictedLocationSubpath', ], 'validateNotTempVolume', - 'when' => function(self $field): bool { - return (bool)$field->restrictLocation; - }, + 'when' => fn() => $this->restrictLocation, ]; $rules[] = [['previewMode'], 'in', 'range' => [self::PREVIEW_MODE_FULL, self::PREVIEW_MODE_THUMBS], 'skipOnEmpty' => false]; From fadfc23a7fdc21287c25daab803d9e782a3a03ca Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 28 Aug 2024 11:16:42 -0700 Subject: [PATCH 6/9] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aecd9db096b..facb46c3eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a SQL error that occurred when running the `db/convert-charset` command if there were any custom database views or sequences. ([#15598](https://github.com/craftcms/cms/issues/15598)) - Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592)) +- Fixed a bug where Assets fields were validating settings that weren’t applicable depending on the “Restrict assets to a single location” setting. ([#15545](https://github.com/craftcms/cms/issues/15545)) ## 4.11.5 - 2024-08-26 From 5855b79f74040a1de6054fe54c9208f97cabc9a7 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 29 Aug 2024 11:37:29 -0700 Subject: [PATCH 7/9] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index facb46c3eb2..74891abd71b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Craft now sends `X-Robots-Tag: none` headers for preview requests. ([#15612](https://github.com/craftcms/cms/pull/15612), [#15586](https://github.com/craftcms/cms/issues/15586)) - Fixed a SQL error that occurred when running the `db/convert-charset` command if there were any custom database views or sequences. ([#15598](https://github.com/craftcms/cms/issues/15598)) - Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592)) - Fixed a bug where Assets fields were validating settings that weren’t applicable depending on the “Restrict assets to a single location” setting. ([#15545](https://github.com/craftcms/cms/issues/15545)) From 13b3b3b360007d2aadfcf426287772976bb8c84a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 29 Aug 2024 14:33:34 -0700 Subject: [PATCH 8/9] Cleanup --- src/base/Field.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/base/Field.php b/src/base/Field.php index 1618686a0f6..9392459f5f8 100644 --- a/src/base/Field.php +++ b/src/base/Field.php @@ -783,14 +783,8 @@ public function getSortOption(): array // for mysql, we have to make sure text column type is cast to char, otherwise it won't be sorted correctly // see https://github.com/craftcms/cms/issues/15609 $db = Craft::$app->getDb(); - if ($db->getIsMysql()) { - $castType = match (Db::parseColumnType($dbType)) { - Schema::TYPE_TEXT => 'CHAR(255)', - default => null, - }; - if ($castType !== null) { - $orderBy = "CAST($orderBy AS $castType)"; - } + if ($db->getIsMysql() && Db::parseColumnType($dbType) === Schema::TYPE_TEXT) { + $orderBy = "CAST($orderBy AS CHAR(255))"; } // The attribute name should match the table attribute name, From ca827dcfc24a978751ee0689c6a1f1c7d456c287 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 29 Aug 2024 14:36:06 -0700 Subject: [PATCH 9/9] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6622e9274a1..2b5ad270981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed a bug where tabs within field layout designers weren’t always getting positioned correctly when wrapped. ([#15590](https://github.com/craftcms/cms/issues/15590)) - Fixed a bug where editable table rows’ action buttons were misaligned for newly-created rows. ([#15602](https://github.com/craftcms/cms/issues/15602)) - Fixed a bug where relational fields’ element query results weren’t limited to the selected relations if the `id` param was overridden. ([#15570](https://github.com/craftcms/cms/issues/15570)) +- Fixed a bug where ordering element queries by textual custom fields would factor in character marks. ([#15609](https://github.com/craftcms/cms/issues/15609)) ## 5.3.6 - 2024-08-26