Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1709: Modified date is not updated when Editing image Tags the second time #29424

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SaveAssetLinks
private const TABLE_ASSET_KEYWORD = 'media_gallery_asset_keyword';
private const FIELD_ASSET_ID = 'asset_id';
private const FIELD_KEYWORD_ID = 'keyword_id';
private const TABLE_MEDIA_ASSET = 'media_gallery_asset';

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

$this->deleteAssetKeywords($assetId, $obsoleteKeywordIds);
$this->insertAssetKeywords($assetId, $newKeywordIds);

if ($obsoleteKeywordIds || $newKeywordIds) {
$this->setAssetUpdatedAt($assetId);
}
}

/**
Expand Down Expand Up @@ -179,4 +184,28 @@ function (KeywordInterface $keyword): int {
$keywordsData
);
}

/**
* Updates modified date of media asset
*
* @param int $assetId
* @throws CouldNotSaveException
*/
private function setAssetUpdatedAt(int $assetId): void
{
try {
$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName(self::TABLE_MEDIA_ASSET),
['updated_at' => null],
['id =?' => $assetId]
);
} catch (\Exception $exception) {
$this->logger->critical($exception);
throw new CouldNotSaveException(
__('Could not update assets modified date'),
$exception
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testAssetKeywordsSave(int $assetId, array $keywordIds, array $va
$expectedCalls = (int) (count($keywordIds));

if ($expectedCalls) {
$this->resourceConnectionMock->expects($this->once())
$this->resourceConnectionMock->expects($this->exactly(2))
->method('getConnection')
->willReturn($this->connectionMock);
$this->resourceConnectionMock->expects($this->once())
Expand Down