[BUGFIX] FAL: update wizard fails if file does not exist 33/16533/6
authorAndreas Wolf <andreas.wolf@typo3.org>
Sat, 17 Nov 2012 16:02:40 +0000 (17:02 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 12 Jan 2013 15:24:25 +0000 (16:24 +0100)
The FAL update wizard throws an exception during migration if a file is
missing. As we cannot do that much about a missing source file, we
should at least not fatal here, but give the user a warning message in
the logs instead.

Change-Id: I3ab0ecd8d8f60e782b7459d7f92f89d2c0a9fd40
Resolves: #42882
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/16533
Reviewed-by: Franz Holzinger
Tested-by: Franz Holzinger
Reviewed-by: Francois Suter
Tested-by: Francois Suter
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/install/Classes/Updates/TceformsUpdateWizard.php

index cc1cd3a..85bef9e 100644 (file)
@@ -30,6 +30,11 @@ namespace TYPO3\CMS\Install\Updates;
  * @author Ingmar Schlecht <ingmar@typo3.org>
  * @license http://www.gnu.org/copyleft/gpl.html
  */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Updates TCEform references from direct file relations to FAL.
+ */
 class TceformsUpdateWizard extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
 
        /**
@@ -43,6 +48,17 @@ class TceformsUpdateWizard extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
        protected $storage;
 
        /**
+        * @var \TYPO3\CMS\Core\Log\Logger
+        */
+       protected $logger;
+
+       public function __construct() {
+               /** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
+               $logManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
+               $this->logger = $logManager->getLogger(__CLASS__);
+       }
+
+       /**
         * Initialize the storage repository.
         */
        public function init() {
@@ -145,7 +161,7 @@ class TceformsUpdateWizard extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
                                $records = $this->getRecordsFromTable($table, $fieldsToGet);
                                foreach ($records as $record) {
                                        foreach ($fieldsToMigrate as $field) {
-                                               $dbQueries = array_merge($this->migrateField($table, $record, $field, $tableConfiguration[$field]));
+                                               $dbQueries = array_merge($this->migrateField($table, $record, $field, $tableConfiguration[$field], $customMessages));
                                        }
                                }
                        }
@@ -161,7 +177,18 @@ class TceformsUpdateWizard extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
                return $records;
        }
 
-       protected function migrateField($table, $row, $fieldname, $fieldConfiguration) {
+       /**
+        * Migrates a single field.
+        *
+        * @param string $table
+        * @param array $row
+        * @param string $fieldname
+        * @param array $fieldConfiguration
+        * @param string $customMessages
+        * @return array A list of performed database queries
+        * @throws \Exception
+        */
+       protected function migrateField($table, $row, $fieldname, $fieldConfiguration, &$customMessages) {
                $fieldItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row[$fieldname], TRUE);
                if (empty($fieldItems) || is_numeric($row[$fieldname])) {
                        return array();
@@ -189,9 +216,26 @@ class TceformsUpdateWizard extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
                        if (!PATH_site) {
                                throw new \Exception('PATH_site was undefined.');
                        }
-                       // copy file
+
                        $sourcePath = PATH_site . $fieldConfiguration['sourcePath'] . $item;
                        $targetPath = PATH_site . $fileadminDirectory . $fieldConfiguration['targetPath'] . $item;
+
+                       // if the source file does not exist, we should just continue, but leave a message in the docs;
+                       // ideally, the user would be informed after the update as well.
+                       if (!file_exists($sourcePath)) {
+                               $this->logger->notice('File ' . $fieldConfiguration['sourcePath'] . $item . ' does not exist. Reference was not migrated.', array('table' => $table, 'record' => $row, 'field' => $fieldname));
+
+                               $format = 'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
+                               $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Core\Messaging\FlashMessage',
+                                       sprintf($format, $fieldConfiguration['sourcePath'] . $item, $table, $row['uid'], $fieldname),
+                                       '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
+                               );
+                               /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $message */
+                               $customMessages .= '<br />' . $message->render();
+
+                               continue;
+                       }
+
                        if (!is_dir(dirname($targetPath))) {
                                \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep(dirname($targetPath));
                        }