From 54418ff5cf9aa15ac14a98b448e654fea4cecc3a Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Thu, 1 Jun 2023 13:58:58 -0400 Subject: [PATCH 1/4] Account for null Asset::dateModified --- src/helpers/Assets.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/helpers/Assets.php b/src/helpers/Assets.php index 02e14797326..9fa855b3154 100644 --- a/src/helpers/Assets.php +++ b/src/helpers/Assets.php @@ -111,16 +111,22 @@ public static function generateUrl(BaseFsInterface $fs, Asset $asset, ?string $u */ public static function revParams(Asset $asset, ?DateTime $dateUpdated = null): array { - /** @var DateTime $dateModified */ - $dateModified = max($asset->dateModified, $dateUpdated ?? null); - $v = $dateModified->getTimestamp(); + $v = []; + $dateModified = $asset->dateModified ? max($asset->dateModified, $dateUpdated) : null; + + if ($dateModified) { + $v[] = $dateModified->getTimestamp(); + } if ($asset->getHasFocalPoint()) { $fp = $asset->getFocalPoint(); - $v .= ",{$fp['x']},{$fp['y']}"; + $v[] = $fp['x']; + $v[] = $fp['y']; } - return compact('v'); + return [ + 'v' => implode(',', $v), + ]; } /** From 44fecd2ce0d330076134a2cb4272428b971f5a97 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Thu, 1 Jun 2023 14:02:36 -0400 Subject: [PATCH 2/4] Return empty --- src/helpers/Assets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/Assets.php b/src/helpers/Assets.php index 9fa855b3154..2cf65248434 100644 --- a/src/helpers/Assets.php +++ b/src/helpers/Assets.php @@ -124,9 +124,9 @@ public static function revParams(Asset $asset, ?DateTime $dateUpdated = null): a $v[] = $fp['y']; } - return [ + return $v ? [ 'v' => implode(',', $v), - ]; + ] : []; } /** From 98e86383ae8d85dda657f045e7a68c69f378dce4 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 12 Jun 2023 14:55:19 -0700 Subject: [PATCH 3/4] Cleanup --- src/helpers/Assets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/Assets.php b/src/helpers/Assets.php index 2cf65248434..32509eefb3c 100644 --- a/src/helpers/Assets.php +++ b/src/helpers/Assets.php @@ -112,8 +112,8 @@ public static function generateUrl(BaseFsInterface $fs, Asset $asset, ?string $u public static function revParams(Asset $asset, ?DateTime $dateUpdated = null): array { $v = []; - $dateModified = $asset->dateModified ? max($asset->dateModified, $dateUpdated) : null; + $dateModified = max($asset->dateModified, $dateUpdated); if ($dateModified) { $v[] = $dateModified->getTimestamp(); } @@ -124,9 +124,9 @@ public static function revParams(Asset $asset, ?DateTime $dateUpdated = null): a $v[] = $fp['y']; } - return $v ? [ + return array_filter([ 'v' => implode(',', $v), - ] : []; + ]); } /** From 6ddcd7ea198247c577df4fde86341603258a1189 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 12 Jun 2023 15:00:19 -0700 Subject: [PATCH 4/4] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c261f0f68..b4840b02093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fixed a SQL error that could occur when upgrading to 4.4 on PostgreSQL, if the database was converted from MySQL. ([#12855](https://github.com/craftcms/cms/issues/12855)) - Fixed a bug where `craft\db\Query::collect()` was returning a `craft\elements\ElementCollection` instance. - Fixed a SQL error that could occur when upgrading to Craft 4 if any database tables had foreign keys to `entryversions` or other now-unused tables that are removed during the upgrade. +- Fixed a PHP error that occurred if an asset without a `dateModified` value was passed to `craft\helpers\Assets::revParams()`. ([#13268](https://github.com/craftcms/cms/pull/13268)) ## 4.4.13 - 2023-05-24