Skip to content

Commit

Permalink
ENGCOM-7973: #1709: Modified date is not updated when Editing image T…
Browse files Browse the repository at this point in the history
…ags the second time #29424
  • Loading branch information
lenaorobei authored Aug 10, 2020
2 parents 4dc6768 + 1e71275 commit 15c8daa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 15c8daa

Please sign in to comment.