[BUGFIX] Upload in backend does not index file 18/19218/7
authorSteffen Ritter <info@rs-websystems.de>
Sat, 23 Mar 2013 14:19:01 +0000 (15:19 +0100)
committerBenjamin Mack <benni@typo3.org>
Sat, 6 Apr 2013 20:57:42 +0000 (22:57 +0200)
If a file is uploaded within the backend (f.e. file-module)
the file is not automatically indexed. If done within the
file-module the indexing happens when the folder is shown.
If the file is uploaded somehow else using the
ExtendedFileUtility it's not indexed.

Add the indexing to the upload function.

Releases: 6.1, 6.0
Fixes: #46595
Change-Id: I9ea30797390f960a8e382a1f2c456259d3daa60c
Reviewed-on: https://review.typo3.org/19218
Reviewed-by: Alexander Opitz
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

index 69bbacd..bad7d79 100644 (file)
@@ -27,6 +27,9 @@ namespace TYPO3\CMS\Core\Utility\File;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Contains functions for performing file operations like copying, pasting, uploading, moving,
  * deleting etc. through the TCE
@@ -136,6 +139,12 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         */
        protected $fileFactory;
 
+
+       /**
+        * @var FileRepository
+        */
+       protected $fileRepository;
+
        /**
         * Initialization of the class
         *
@@ -152,6 +161,8 @@ 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;
        }
@@ -200,6 +211,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         * Processing the command array in $this->fileCmdMap
         *
         * @return mixed FALSE, if the file functions were not initialized
+        * @throws \UnexpectedValueException
         * @todo Define visibility
         */
        public function processData() {
@@ -261,7 +273,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                                // Hook for post-processing the action
                                                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'])) {
                                                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'] as $classRef) {
-                                                               $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
+                                                               $hookObject = GeneralUtility::getUserObj($classRef);
                                                                if (!$hookObject instanceof \TYPO3\CMS\Core\Utility\File\ExtendedFileUtilityProcessDataHookInterface) {
                                                                        throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtilityProcessDataHookInterface', 1279719168);
                                                                }
@@ -284,7 +296,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         * @deprecated since TYPO3 6.1, will be removed two versions later, use ->getErrorMessages directly instead
         */
        public function printLogErrorMessages($redirect = '') {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               GeneralUtility::logDeprecatedFunction();
                $this->getErrorMessages();
        }
 
@@ -304,7 +316,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
                        $logData = unserialize($row['log_data']);
                        $msg = $row['error'] . ': ' . sprintf($row['details'], $logData[0], $logData[1], $logData[2], $logData[3], $logData[4]);
-                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       $flashMessage = GeneralUtility::makeInstance(
                                'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                $msg,
                                '',
@@ -327,10 +339,10 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         * @deprecated since TYPO3 6.0, use \TYPO3\CMS\Core\Resource\ResourceStorage method instead
         */
        public function findRecycler($theFile) {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               GeneralUtility::logDeprecatedFunction();
                if ($this->isPathValid($theFile)) {
                        $theFile = $this->cleanDirectoryName($theFile);
-                       $fI = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theFile);
+                       $fI = GeneralUtility::split_fileref($theFile);
                        $c = 0;
                        // !!! Method has been put in the storage, can be saftely removed
                        $rDir = $fI['path'] . $this->recyclerFN;
@@ -340,7 +352,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                }
                                $theFile = $fI['path'];
                                $theFile = $this->cleanDirectoryName($theFile);
-                               $fI = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theFile);
+                               $fI = GeneralUtility::split_fileref($theFile);
                                $c++;
                        }
                }
@@ -389,7 +401,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $fileObject = $this->getFileObject($cmds['data']);
                // @todo implement the recycler feature which has been removed from the original implementation
                // checks to delete the file
-               if ($fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
+               if ($fileObject instanceof File) {
                        $refIndexRecords = $this->getDatabaseConnection()->exec_SELECTgetRows(
                                '*',
                                'sys_refindex',
@@ -409,7 +421,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                }
 
                                // render a message that the file could not be deleted
-                               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                               $flashMessage = GeneralUtility::makeInstance(
                                        '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                        sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
                                        $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
@@ -422,7 +434,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                        $result = $fileObject->delete();
 
                                        // show the user that the file was deleted
-                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                       $flashMessage = GeneralUtility::makeInstance(
                                                '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                                sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
                                                $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
@@ -446,7 +458,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
                                if ($fileObject->getFileCount() > 0) {
                                        // render a message that the folder could not be deleted because it still contains files
-                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                       $flashMessage = GeneralUtility::makeInstance(
                                                '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                                sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
                                                $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
@@ -458,7 +470,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                        $result = $fileObject->delete(TRUE);
 
                                        // notify the user that the folder was deleted
-                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                       $flashMessage = GeneralUtility::makeInstance(
                                                '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                                sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
                                                $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
@@ -510,6 +522,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         *
         * @param string $identifier
         * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
         */
        protected function getFileObject($identifier) {
                $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
@@ -548,7 +561,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $appendSuffixOnConflict = (string) $cmds['altName'];
                $resultObject = NULL;
                // Copying the file
-               if ($sourceFileObject instanceof \TYPO3\CMS\Core\Resource\File) {
+               if ($sourceFileObject instanceof File) {
                        try {
                                $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
                                $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
@@ -623,7 +636,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $alternativeName = (string) $cmds['altName'];
                $resultObject = NULL;
                // Moving the file
-               if ($sourceFileObject instanceof \TYPO3\CMS\Core\Resource\File) {
+               if ($sourceFileObject instanceof File) {
                        try {
                                if ($alternativeName !== '') {
                                        // Don't allow overwriting existing files, but find a new name
@@ -696,7 +709,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $sourceFileObject = $this->getFileObject($cmds['data']);
                $targetFile = $cmds['target'];
                $resultObject = NULL;
-               if ($sourceFileObject instanceof \TYPO3\CMS\Core\Resource\File) {
+               if ($sourceFileObject instanceof File) {
                        try {
                                // Try to rename the File
                                $resultObject = $sourceFileObject->rename($targetFile);
@@ -823,12 +836,12 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                $fileObject = $this->getFileObject($fileIdentifier);
                // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
                $content = $cmds['data'];
-               if (!$fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
+               if (!$fileObject instanceof File) {
                        $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
                        return FALSE;
                }
                $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
-               if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($extList, $fileObject->getExtension())) {
+               if (!GeneralUtility::inList($extList, $fileObject->getExtension())) {
                        $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
                        return FALSE;
                }
@@ -913,7 +926,10 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                } else {
                                        $conflictMode = 'cancel';
                                }
-                               $resultObjects[] = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
+                               /** @var $fileObject File */
+                               $fileObject = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
+                               $this->fileRepository->addToIndex($fileObject);
+                               $resultObjects[] = $fileObject;
                                $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException $e) {
                                $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
@@ -931,6 +947,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
                        }
                }
+
                return $resultObjects;
        }
 
@@ -951,7 +968,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                        $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
                        return FALSE;
                }
-               $fI = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theFile);
+               $fI = GeneralUtility::split_fileref($theFile);
                if (!isset($cmds['target'])) {
                        $cmds['target'] = $fI['path'];
                }
@@ -995,7 +1012,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         */
        protected function addFlashMessage(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage) {
                /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
-               $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+               $flashMessageService = GeneralUtility::makeInstance(
                        'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
                );
                /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
@@ -1021,5 +1038,4 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
        }
 }
 
-
 ?>
\ No newline at end of file