[BUGFIX] Detect missing files in empty storage 34/30534/4
authorRobert Vock <robert.vock@4wdmedia.de>
Tue, 3 Jun 2014 11:56:15 +0000 (13:56 +0200)
committerFrans Saris <franssaris@gmail.com>
Mon, 7 Jul 2014 06:31:02 +0000 (08:31 +0200)
Improve the check for missing files by properly treating
the case when a storage is empty.

Change-Id: I8fba9be2622a4cd742c0065b68a8daf77f8a484a
Resolves: #54414
Releases: 6.3, 6.2
Reviewed-on: https://review.typo3.org/30534
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Wouter Wolters
Reviewed-by: Frans Saris
Tested-by: Frans Saris
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Classes/Resource/Index/Indexer.php

index 1ef1443..4d90b3c 100644 (file)
@@ -281,14 +281,13 @@ class FileIndexRepository implements SingletonInterface {
         * @return array
         */
        public function findInStorageAndNotInUidList(\TYPO3\CMS\Core\Resource\ResourceStorage $storage, array $uidList) {
-               array_walk($uidList, 'intval');
-               $uidList = array_unique($uidList);
-
-               return $this->getDatabaseConnection()->exec_SELECTgetRows(
-                       implode(',', $this->fields),
-                       $this->table,
-                       'storage = ' . (int)$storage->getUid() . ' AND uid NOT IN (' . implode(',', $uidList) . ')'
-               );
+               $where = 'storage = ' . (int)$storage->getUid();
+               if (!empty($uidList)) {
+                       array_walk($uidList, 'intval');
+                       $uidList = array_unique($uidList);
+                       $where .= ' AND uid NOT IN (' . implode(',', $uidList) . ')';
+               }
+               return $this->getDatabaseConnection()->exec_SELECTgetRows(implode(',', $this->fields), $this->table, $where);
        }
 
        /**
index fb7a937..43528fb 100644 (file)
@@ -122,13 +122,14 @@ class Indexer {
         * that files that are in indexed but not touched in this run are missing
         */
        protected function detectMissingFiles() {
-               if (count($this->identifiedFileUids) > 0) {
-                       $indexedNotExistentFiles = $this->getFileIndexRepository()->findInStorageAndNotInUidList($this->storage, $this->identifiedFileUids);
+               $indexedNotExistentFiles = $this->getFileIndexRepository()->findInStorageAndNotInUidList(
+                       $this->storage,
+                       $this->identifiedFileUids
+               );
 
-                       foreach ($indexedNotExistentFiles as $record) {
-                               if (!$this->storage->hasFile($record['identifier'])) {
-                                       $this->getFileIndexRepository()->markFileAsMissing($record['uid']);
-                               }
+               foreach ($indexedNotExistentFiles as $record) {
+                       if (!$this->storage->hasFile($record['identifier'])) {
+                               $this->getFileIndexRepository()->markFileAsMissing($record['uid']);
                        }
                }
        }