Skip to content

Commit 1e71275

Browse files
ENGCOM-7973: #1709: Modified date is not updated when Editing image Tags the second time #29424
- Merge Pull Request #29424 from jmonteros422/magento2-1:1709-modified-date-is-not-updated-when-editing-image-tags-the-second-time - Merged commits: 1. bd364fb
2 parents 237c2b1 + bd364fb commit 1e71275

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetLinks.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SaveAssetLinks
2424
private const TABLE_ASSET_KEYWORD = 'media_gallery_asset_keyword';
2525
private const FIELD_ASSET_ID = 'asset_id';
2626
private const FIELD_KEYWORD_ID = 'keyword_id';
27+
private const TABLE_MEDIA_ASSET = 'media_gallery_asset';
2728

2829
/**
2930
* @var ResourceConnection
@@ -73,6 +74,10 @@ public function execute(int $assetId, array $keywordIds): void
7374

7475
$this->deleteAssetKeywords($assetId, $obsoleteKeywordIds);
7576
$this->insertAssetKeywords($assetId, $newKeywordIds);
77+
78+
if ($obsoleteKeywordIds || $newKeywordIds) {
79+
$this->setAssetUpdatedAt($assetId);
80+
}
7681
}
7782

7883
/**
@@ -179,4 +184,28 @@ function (KeywordInterface $keyword): int {
179184
$keywordsData
180185
);
181186
}
187+
188+
/**
189+
* Updates modified date of media asset
190+
*
191+
* @param int $assetId
192+
* @throws CouldNotSaveException
193+
*/
194+
private function setAssetUpdatedAt(int $assetId): void
195+
{
196+
try {
197+
$connection = $this->resourceConnection->getConnection();
198+
$connection->update(
199+
$connection->getTableName(self::TABLE_MEDIA_ASSET),
200+
['updated_at' => null],
201+
['id =?' => $assetId]
202+
);
203+
} catch (\Exception $exception) {
204+
$this->logger->critical($exception);
205+
throw new CouldNotSaveException(
206+
__('Could not update assets modified date'),
207+
$exception
208+
);
209+
}
210+
}
182211
}

app/code/Magento/MediaGallery/Test/Unit/Model/ResourceModel/Keyword/SaveAssetLinksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testAssetKeywordsSave(int $assetId, array $keywordIds, array $va
7575
$expectedCalls = (int) (count($keywordIds));
7676

7777
if ($expectedCalls) {
78-
$this->resourceConnectionMock->expects($this->once())
78+
$this->resourceConnectionMock->expects($this->exactly(2))
7979
->method('getConnection')
8080
->willReturn($this->connectionMock);
8181
$this->resourceConnectionMock->expects($this->once())

0 commit comments

Comments
 (0)