[TASK] Fix remaining calls to FileRepository for retrieving Files 50/26850/3
authorSteffen Ritter <info@rs-websystems.de>
Wed, 15 Jan 2014 15:31:07 +0000 (16:31 +0100)
committerFrans Saris <franssaris@gmail.com>
Thu, 30 Jan 2014 16:55:08 +0000 (17:55 +0100)
In previous efforts the calls to the FileRepository, when retrieving
File objects have been relocated to the ResourceFactory, since the
coexistence causes problems when it comes to metadata and multiple
instances of the same entity.

As findByUid is defined in the AbstractRepository it was overlooked
until now. This patch overrides the base method, deprecated it and
calls the ResourceFactory, too.
In addition all calls in core are replaced with the direct call.

Resolves: #53690
Releases: 6.2
Change-Id: I89a665211bd7d400f339e27bd2b155958fe5daf1
Reviewed-on: https://review.typo3.org/26850
Reviewed-by: Ingo Schmitt
Tested-by: Ingo Schmitt
Reviewed-by: Frans Saris
Tested-by: Frans Saris
typo3/sysext/core/Classes/Resource/FileReference.php
typo3/sysext/core/Classes/Resource/FileRepository.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/extbase/Classes/Domain/Model/File.php
typo3/sysext/extbase/Classes/Domain/Model/FileReference.php
typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FilesContentObjectTest.php

index bbfed03..47b90b3 100644 (file)
@@ -67,14 +67,6 @@ class FileReference implements FileInterface {
        protected $name;
 
        /**
-        * The FileRepository object. Is needed e.g. for the delete() method to delete the usage record
-        * (sys_file_reference record) of this file usage.
-        *
-        * @var FileRepository
-        */
-       protected $fileRepository;
-
-       /**
         * Reference to the original File object underlying this FileReference.
         *
         * @var File
@@ -107,10 +99,9 @@ class FileReference implements FileInterface {
                }
                if (!$factory) {
                        /** @var $factory ResourceFactory */
-                       $factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+                       $factory = ResourceFactory::getInstance();
                }
                $this->originalFile = $factory->getFileObject($fileReferenceData['uid_local']);
-               $this->fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
                if (!is_object($this->originalFile)) {
                        throw new \RuntimeException('Original File not found for FileReference.', 1300098529);
                }
index 0e17248..f9abf44 100644 (file)
@@ -62,6 +62,17 @@ class FileRepository extends AbstractRepository {
        protected $indexerService = NULL;
 
        /**
+        * @param int $uid
+        * @return File
+        * @deprecated since TYPO3 6.2 CMS, will be removed 2 versions later
+        */
+       public function findByUid($uid) {
+               GeneralUtility::logDeprecatedFunction();
+               return ResourceFactory::getInstance()->getFileObject($uid);
+       }
+
+
+       /**
         * Internal function to retrieve the indexer service,
         * if it does not exist, an instance will be created
         *
index d58dbf3..9ed5871 100644 (file)
@@ -142,11 +142,6 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
 
 
        /**
-        * @var \TYPO3\CMS\Core\Resource\FileRepository
-        */
-       protected $fileRepository;
-
-       /**
         * Initialization of the class
         *
         * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
@@ -162,8 +157,6 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $this->unzipPath = $unzipPath;
                // Initialize Object Factory
                $this->fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
-               // Initialize Object Factory
-               $this->fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
                // Initializing file processing commands:
                $this->fileCmdMap = $fileCmds;
        }
index 5fd643d..e2d8be1 100644 (file)
@@ -35,17 +35,11 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 class File extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder {
 
        /**
-        * @var \TYPO3\CMS\Core\Resource\FileRepository
-        * @inject
-        */
-       protected $fileRepository;
-
-       /**
         * @return \TYPO3\CMS\Core\Resource\File
         */
        public function getOriginalResource() {
                if ($this->originalResource === NULL) {
-                       $this->originalResource = $this->fileRepository->findByUid($this->getUid());
+                       $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($this->getUid());
                }
 
                return $this->originalResource;
index e89b98f..611821b 100644 (file)
@@ -35,17 +35,11 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder {
 
        /**
-        * @var \TYPO3\CMS\Core\Resource\FileRepository
-        * @inject
-        */
-       protected $fileRepository;
-
-       /**
         * @return \TYPO3\CMS\Core\Resource\FileReference
         */
        public function getOriginalResource() {
                if ($this->originalResource === NULL) {
-                       $this->originalResource = $this->fileRepository->findFileReferenceByUid($this->getUid());
+                       $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->getUid());
                }
 
                return $this->originalResource;
index c340be9..7a63fe5 100644 (file)
@@ -75,7 +75,10 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        $referencesUidArray = GeneralUtility::intExplode(',', $referencesUid, TRUE);
                        foreach ($referencesUidArray as $referenceUid) {
                                try {
-                                       $this->addToArray($this->getFileRepository()->findFileReferenceByUid($referenceUid), $fileObjects);
+                                       $this->addToArray(
+                                               $this->getFileFactory()->getFileReferenceObject($referenceUid),
+                                               $fileObjects
+                                       );
                                } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
                                        /** @var \TYPO3\CMS\Core\Log\Logger $logger */
                                        $logger = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__);
@@ -107,7 +110,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        $fileUids = GeneralUtility::intExplode(',', $this->stdWrapValue('files', $conf), TRUE);
                        foreach ($fileUids as $fileUid) {
                                try {
-                                       $this->addToArray($this->getFileRepository()->findByUid($fileUid), $fileObjects);
+                                       $this->addToArray($this->getFileFactory()->getFileObject($fileUid), $fileObjects);
                                } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
                                        /** @var \TYPO3\CMS\Core\Log\Logger $logger */
                                        $logger = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__);
index dc599f4..bc04e85 100644 (file)
@@ -224,14 +224,14 @@ class FilesContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ->with('name')
                                ->will($this->returnValue('File ' . $i));
 
-                       $fileReferenceMap[] = array($i, $fileReference);
+                       $fileReferenceMap[] = array($i, array(), $fileReference);
                }
 
-               $fileRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $fileRepository->expects($this->any())
-                       ->method('findFileReferenceByUid')
+               $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+               $resourceFactory->expects($this->any())
+                       ->method('getFileReferenceObject')
                        ->will($this->returnValueMap($fileReferenceMap));
-               $this->subject->setFileRepository($fileRepository);
+               $this->subject->setFileFactory($resourceFactory);
 
                $this->assertSame($expected, $this->subject->render($configuration));
        }
@@ -394,14 +394,14 @@ class FilesContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ->with('name')
                                ->will($this->returnValue('File ' . $i));
 
-                       $fileMap[] = array($i, $file);
+                       $fileMap[] = array($i, array(), $file);
                }
 
-               $fileRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $fileRepository->expects($this->any())
-                       ->method('findByUid')
+               $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+               $resourceFactory->expects($this->any())
+                       ->method('getFileObject')
                        ->will($this->returnValueMap($fileMap));
-               $this->subject->setFileRepository($fileRepository);
+               $this->subject->setFileFactory($resourceFactory);
 
                $this->assertSame($expected, $this->subject->render($configuration));
        }