diff --git a/src/Asset/Elements/Asset.php b/src/Asset/Elements/Asset.php index 3c81011d09d..94c450e4897 100644 --- a/src/Asset/Elements/Asset.php +++ b/src/Asset/Elements/Asset.php @@ -316,12 +316,6 @@ class Asset extends Element public function __construct($config = []) { - // alt='' actually means something, so we should preserve it. - $alt = Arr::pull($config, 'alt'); - if ($alt !== null) { - $this->alt = $alt; - } - parent::__construct($config); if (isset($this->alt)) { @@ -1148,19 +1142,6 @@ public function __get($name) } } - #[Override] - public function setAttributesFromRequest(array $values): void - { - // alt='' actually means something, so we should preserve it. - $alt = Arr::pull($values, 'alt'); - - if ($alt !== null) { - $this->alt = $alt; - } - - parent::setAttributesFromRequest($values); - } - /** * Returns the volume’s ID. */ @@ -2966,10 +2947,6 @@ public function afterSave(bool $isNew): void $model->mimeType = $this->_mimeType; } - if ($model->alt === null) { - $model->alt = $this->alt; - } - if ($this->getHasFocalPoint()) { $focal = $this->getFocalPoint(); $model->focalPoint = number_format($focal['x'], 4).';'.number_format($focal['y'], 4); @@ -2978,8 +2955,17 @@ public function afterSave(bool $isNew): void } $model->save(); + + // we're not propagating at this point, so save the alt ONLY against the site we're saving to + DB::table(Table::ASSETS_SITES) + ->upsert([ + 'assetId' => $this->id, + 'siteId' => $this->siteId, + 'alt' => $this->alt, + ], ['assetId', 'siteId']); } + $upsert = false; if ( $this->propagating && $this->propagatingFrom && @@ -2992,16 +2978,19 @@ public function afterSave(bool $isNew): void $this->alt !== $from->alt && $this->getAltTranslationKey() === $from->getAltTranslationKey() ) { + $upsert = true; $this->alt = $from->alt; } } - DB::table(Table::ASSETS_SITES) - ->upsert([ - 'assetId' => $this->id, - 'siteId' => $this->siteId, - 'alt' => $this->alt, - ], ['assetId', 'siteId']); + if ($upsert || $this->propagateAll) { + DB::table(Table::ASSETS_SITES) + ->upsert([ + 'assetId' => $this->id, + 'siteId' => $this->siteId, + 'alt' => $this->alt, + ], ['assetId', 'siteId']); + } parent::afterSave($isNew); } diff --git a/src/Cms.php b/src/Cms.php index b4b8e0df71a..1ee135d9555 100644 --- a/src/Cms.php +++ b/src/Cms.php @@ -30,9 +30,9 @@ public const string VERSION = '6.0.0-alpha.6'; - public const string SCHEMA_VERSION = '6.0.0.2'; + public const string SCHEMA_VERSION = '6.0.0.3'; - public const string MIN_VERSION_REQUIRED = '5.9.0'; + public const string MIN_VERSION_REQUIRED = '5.11.0'; public static function name(): string { diff --git a/src/Database/Migrations/2026_06_10_112441_drop_assets_alt_column.php b/src/Database/Migrations/2026_06_10_112441_drop_assets_alt_column.php new file mode 100644 index 00000000000..702894f42cb --- /dev/null +++ b/src/Database/Migrations/2026_06_10_112441_drop_assets_alt_column.php @@ -0,0 +1,33 @@ +dropColumn('alt'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $this->output->error('2026_06_10_112441_drop_assets_alt_column cannot be reverted.'); + } +}; diff --git a/src/Database/Migrations/Install.php b/src/Database/Migrations/Install.php index d6b174b01f3..4e613d0f05b 100644 --- a/src/Database/Migrations/Install.php +++ b/src/Database/Migrations/Install.php @@ -286,7 +286,6 @@ public function createTables(?Logger $logger = null): void $table->string('filename'); $table->string('mimeType')->nullable(); $table->string('kind', 50)->default(FileKind::Unknown->value); - $table->text('alt')->nullable(); $table->unsignedInteger('width')->nullable(); $table->unsignedInteger('height')->nullable(); $table->unsignedBigInteger('size')->nullable(); diff --git a/src/Element/Queries/AssetQuery.php b/src/Element/Queries/AssetQuery.php index 0b4a052b4c2..57c0d5999ce 100644 --- a/src/Element/Queries/AssetQuery.php +++ b/src/Element/Queries/AssetQuery.php @@ -69,7 +69,6 @@ public function __construct(array $config = []) 'assets.width as width', 'assets.height as height', 'assets.size as size', - 'assets.alt as alt', 'assets.focalPoint as focalPoint', 'assets.keptFile as keptFile', 'assets.dateModified as dateModified', @@ -188,12 +187,9 @@ private function applyAuthParam(?bool $value, string $permissionPrefix, string $ #[Override] public function createElement(array $row): ElementInterface { - // Use the site-specific alt text, if set + // Use the site-specific alt text $siteAlt = Arr::pull($row, 'siteAlt'); - - if ($siteAlt !== null) { - $row['alt'] = $siteAlt; - } + $row['alt'] = $siteAlt; return parent::createElement($row); } diff --git a/src/Element/Queries/Concerns/Asset/QueriesAlt.php b/src/Element/Queries/Concerns/Asset/QueriesAlt.php index 5e2587e5fdf..c5404065ace 100644 --- a/src/Element/Queries/Concerns/Asset/QueriesAlt.php +++ b/src/Element/Queries/Concerns/Asset/QueriesAlt.php @@ -28,22 +28,12 @@ protected function initQueriesAlt(): void $hasAltCondition = function (Builder $query) { $query->where('assets_sites.alt', '!=', '') - ->orWhere(function (Builder $query) { - $query->whereNull('assets_sites.alt') - ->where('assets.alt', '!=', '') - ->whereNotNull('assets.alt'); - }); + ->whereNotNull('assets_sites.alt'); }; $withoutAltCondition = function (Builder $query) { $query->where('assets_sites.alt', '=', '') - ->orWhere(function (Builder $query) { - $query->whereNull('assets_sites.alt') - ->where(function (Builder $query) { - $query->where('assets.alt', '=', '') - ->orWhereNull('assets.alt'); - }); - }); + ->orWhereNull('assets_sites.alt'); }; $assetQuery->where($this->hasAlt ? $hasAltCondition : $withoutAltCondition); diff --git a/tests/Feature/Element/Queries/Concerns/Asset/QueriesAltTest.php b/tests/Feature/Element/Queries/Concerns/Asset/QueriesAltTest.php index 17e8aee7a69..1fb7c45e08c 100644 --- a/tests/Feature/Element/Queries/Concerns/Asset/QueriesAltTest.php +++ b/tests/Feature/Element/Queries/Concerns/Asset/QueriesAltTest.php @@ -8,7 +8,7 @@ Asset::factory()->create(); // With alt - Asset::factory()->create([ + Asset::factory()->create()->sites()->attach(Site::all(), [ 'alt' => 'Alt text', ]); diff --git a/yii2-adapter/legacy/elements/db/AssetQuery.php b/yii2-adapter/legacy/elements/db/AssetQuery.php index 7f3446a480e..e570c2b5760 100644 --- a/yii2-adapter/legacy/elements/db/AssetQuery.php +++ b/yii2-adapter/legacy/elements/db/AssetQuery.php @@ -919,7 +919,6 @@ protected function beforePrepare(): bool 'assets.width', 'assets.height', 'assets.size', - 'assets.alt', 'assets.focalPoint', 'assets.keptFile', 'assets.dateModified', @@ -1021,29 +1020,15 @@ protected function afterPrepare(): bool { if ($this->hasAlt !== null) { $hasAltCondition = [ - 'or', + 'and', ['not', ['assets_sites.alt' => '']], - [ - 'and', - ['assets_sites.alt' => null], - ['not', ['assets.alt' => '']], - ['not', ['assets.alt' => null]], - ], + ['not', ['assets_sites.alt' => null]], ]; $withoutAltCondition = [ 'or', ['assets_sites.alt' => ''], - [ - 'and', - ['assets_sites.alt' => null], - [ - 'or', - ['assets.alt' => ''], - ['assets.alt' => null], - ], - - ], + ['assets_sites.alt' => null], ]; $this->subQuery @@ -1159,11 +1144,9 @@ private function _normalizeVolumeId(): void */ public function createElement(array $row): ElementInterface { - // Use the site-specific alt text, if set + // Use the site-specific alt text $siteAlt = Arr::pull($row, 'siteAlt'); - if ($siteAlt !== null) { - $row['alt'] = $siteAlt; - } + $row['alt'] = $siteAlt; return parent::createElement($row); }