Skip to content
Snippets Groups Projects
Commit 72f25722 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Nikita Hovratov
Browse files

[BUGFIX] Prevent 'Undefined array key' in FileDeletionAspect

Properly check for valid meta data record
to prevent 'Undefined array key' error on
deleting a file.

Meta data record might not exists, because
the file might have not been indexed or
simply because the record was manually deleted.

Additionally, some code clean up is done.

Resolves: #102700
Releases: main, 12.4
Change-Id: Ibf8a0d53b40f08b60064583d5f28762c25d75937
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82247


Reviewed-by: default avatarNikita Hovratov <nikita.h@live.de>
Tested-by: default avatarNikita Hovratov <nikita.h@live.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
parent 8e54ff8e
Branches
Tags
No related merge requests found
...@@ -55,7 +55,7 @@ final class FileDeletionAspect ...@@ -55,7 +55,7 @@ final class FileDeletionAspect
/** /**
* Cleanup database record for a deleted file * Cleanup database record for a deleted file
*/ */
private function removeFromRepository(FileInterface $fileObject) private function removeFromRepository(FileInterface $fileObject): void
{ {
// remove file from repository // remove file from repository
if ($fileObject instanceof File) { if ($fileObject instanceof File) {
...@@ -69,7 +69,7 @@ final class FileDeletionAspect ...@@ -69,7 +69,7 @@ final class FileDeletionAspect
->delete( ->delete(
'sys_file_reference', 'sys_file_reference',
[ [
'uid_local' => (int)$fileObject->getUid(), 'uid_local' => $fileObject->getUid(),
] ]
); );
} elseif ($fileObject instanceof ProcessedFile) { } elseif ($fileObject instanceof ProcessedFile) {
...@@ -77,7 +77,7 @@ final class FileDeletionAspect ...@@ -77,7 +77,7 @@ final class FileDeletionAspect
->delete( ->delete(
'sys_file_processedfile', 'sys_file_processedfile',
[ [
'uid' => (int)$fileObject->getUid(), 'uid' => $fileObject->getUid(),
] ]
); );
} }
...@@ -86,17 +86,23 @@ final class FileDeletionAspect ...@@ -86,17 +86,23 @@ final class FileDeletionAspect
/** /**
* Remove all category references of the deleted file. * Remove all category references of the deleted file.
*/ */
private function cleanupCategoryReferences(File $fileObject) private function cleanupCategoryReferences(File $fileObject): void
{ {
// Retrieve the file metadata uid which is different from the file uid. // Retrieve the file metadata uid which is different from the file uid.
$metadataProperties = $fileObject->getMetaData()->get(); $metadataProperties = $fileObject->getMetaData()->get();
$metaDataUid = $metadataProperties['_ORIG_uid'] ?? $metadataProperties['uid']; $metaDataUid = (int)($metadataProperties['_ORIG_uid'] ?? $metadataProperties['uid'] ?? 0);
if ($metaDataUid <= 0) {
// No metadata record exists for the given file. The file might not
// have been indexed or the meta data record was deleted manually.
return;
}
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category_record_mm') GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category_record_mm')
->delete( ->delete(
'sys_category_record_mm', 'sys_category_record_mm',
[ [
'uid_foreign' => (int)$metaDataUid, 'uid_foreign' => $metaDataUid,
'tablenames' => 'sys_file_metadata', 'tablenames' => 'sys_file_metadata',
] ]
); );
...@@ -105,7 +111,7 @@ final class FileDeletionAspect ...@@ -105,7 +111,7 @@ final class FileDeletionAspect
/** /**
* Remove all processed files that belong to the given File object * Remove all processed files that belong to the given File object
*/ */
private function cleanupProcessedFiles(FileInterface $fileObject) private function cleanupProcessedFiles(FileInterface $fileObject): void
{ {
// only delete processed files of File objects // only delete processed files of File objects
if (!$fileObject instanceof File) { if (!$fileObject instanceof File) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment