Skip to content

Commit

Permalink
[BUGFIX] Create metadata record if necessary
Browse files Browse the repository at this point in the history
When uploading a new file in TYPO3 v11.5.33, most of the times
the meta data record has not been created yet when the MetaDataUpdateService
is called.
This patch creates the meta data record when necessary, preventing
the following error:

> (1/1) #1476107295 TYPO3\CMS\Core\Error\Exception
> PHP Warning: Undefined array key "uid" in typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php line 197
> Stack trace:
> #0 typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php(197): TYPO3\\CMS\\Core\\Error\\ErrorHandler->handleError()
> andersundsehr#1 typo3conf/ext/aus_driver_amazon_s3/Classes/Service/MetaDataUpdateService.php(51): TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository->update()
> andersundsehr#2 typo3conf/ext/aus_driver_amazon_s3/Classes/EventListener/AfterFileAddedToIndexEventListener.php(31): AUS\\AusDriverAmazonS3\\Service\\MetaDataUpdateService->updateMetadata()
> andersundsehr#3 typo3/sysext/core/Classes/EventDispatcher/EventDispatcher.php(51): AUS\\AusDriverAmazonS3\\EventListener\\AfterFileAddedToIndexEventListener->__invoke()
> andersundsehr#4 typo3/sysext/adminpanel/Classes/Service/EventDispatcher.php(41): TYPO3\\CMS\\Core\\EventDispatcher\\EventDispatcher->dispatch()
> andersundsehr#5 typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php(340): TYPO3\\CMS\\Adminpanel\\Service\\EventDispatcher->dispatch()
> andersundsehr#6 typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php(318): TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository->insertRecord()
> andersundsehr#7 typo3/sysext/core/Classes/Resource/Index/Indexer.php(84): TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository->addRaw()
  • Loading branch information
cweiske committed Jun 17, 2024
1 parent c6748eb commit 8a83c7d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Classes/Service/MetaDataUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ public function updateMetadata(array $fileProperties): void
if ($imageDimensions !== null) {
$metaDataRepository = $this->getMetaDataRepository();
$metaData = $metaDataRepository->findByFileUid($fileProperties['uid']);
$create = count($metaData) == 0;

$metaData['width'] = $imageDimensions[0];
$metaData['height'] = $imageDimensions[1];
$metaDataRepository->update($fileProperties['uid'], $metaData);
if ($create) {
$metaDataRepository->createMetaDataRecord($fileProperties['uid'], $metaData);
} else {
$metaDataRepository->update($fileProperties['uid'], $metaData);
}
}
}
}
Expand Down

0 comments on commit 8a83c7d

Please sign in to comment.