From f26f30421ae3482c149380ae8415cb2b84d605ef Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Wed, 20 Sep 2023 23:38:35 +0200
Subject: [PATCH] [BUGFIX] Prevent type errors on renaming and moving processed
 files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Whenever a file is renamed or moved, also
the corresponding index entry is updated.

However this does only works and is only
relevant for File objects and can’t be
done for e.g. processed files.

Proper type checks for those two places
are added, preventing corresponding type
errors.

Resolves: #88400
Releases: main, 12.4
Change-Id: I86ecd9500875e2a904ef9bd1768488f886947625
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81120
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
---
 Build/phpstan/phpstan-baseline.neon                    | 5 -----
 typo3/sysext/core/Classes/Resource/ResourceStorage.php | 6 ++++--
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 4c3ec8b310de..d896d4cbb879 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -805,11 +805,6 @@ parameters:
 			count: 2
 			path: ../../typo3/sysext/core/Classes/Resource/ResourceStorage.php
 
-		-
-			message: "#^Parameter \\#1 \\$fileObject of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Index\\\\Indexer\\:\\:updateIndexEntry\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface given\\.$#"
-			count: 2
-			path: ../../typo3/sysext/core/Classes/Resource/ResourceStorage.php
-
 		-
 			message: "#^Parameter \\#2 \\$folder of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceStorage\\:\\:checkFolderActionPermission\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\|null, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface given\\.$#"
 			count: 1
diff --git a/typo3/sysext/core/Classes/Resource/ResourceStorage.php b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
index f08f5b62c6d2..70d1719c5377 100644
--- a/typo3/sysext/core/Classes/Resource/ResourceStorage.php
+++ b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
@@ -1991,7 +1991,9 @@ class ResourceStorage implements ResourceStorageInterface
                     $file->updateProperties(['storage' => $this->getUid(), 'identifier' => $newIdentifier]);
                 }
             }
-            $this->getIndexer()->updateIndexEntry($file);
+            if ($file instanceof File) {
+                $this->getIndexer()->updateIndexEntry($file);
+            }
         } catch (\TYPO3\CMS\Core\Exception $e) {
             echo $e->getMessage();
         }
@@ -2029,8 +2031,8 @@ class ResourceStorage implements ResourceStorageInterface
             $newIdentifier = $this->driver->renameFile($file->getIdentifier(), $sanitizedTargetFileName);
             if ($file instanceof File) {
                 $file->updateProperties(['identifier' => $newIdentifier]);
+                $this->getIndexer()->updateIndexEntry($file);
             }
-            $this->getIndexer()->updateIndexEntry($file);
         } catch (ExistingTargetFileNameException $exception) {
             if ($conflictMode->equals(DuplicationBehavior::RENAME)) {
                 $newName = $this->getUniqueName($file->getParentFolder(), $sanitizedTargetFileName);
-- 
GitLab