[BUGFIX] Report migration errors in TceformsUpdateWizard 00/29100/3
authorSteffen Müller <typo3@t3node.com>
Wed, 2 Apr 2014 20:38:31 +0000 (22:38 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 7 Jul 2014 07:03:27 +0000 (09:03 +0200)
TceformsUpdateWizard should report errors if a migration
failed due to a missing source file.

Resolves: #57575
Releases: 6.3, 6.2
Change-Id: I68af9a5155f7d6190a22cc4986ef4a467b747737
Reviewed-on: https://review.typo3.org/29100
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/install/Classes/Updates/TceformsUpdateWizard.php

index 312c05a..5bd478b 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Install\Updates;
 
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Domain\Model\File;
 
 /**
  * Upgrade wizard which goes through all files referenced in the tt_content.image filed
@@ -151,45 +152,49 @@ class TceformsUpdateWizard extends AbstractUpdate {
                        // Nothing to do
                        return TRUE;
                }
-               $this->init();
-               $finishedFields = $this->getFinishedFields();
-               foreach ($this->tables as $table => $tableConfiguration) {
-                       // find all additional fields we should get from the database
-                       foreach ($tableConfiguration as $fieldToMigrate => $fieldConfiguration) {
-                               $fieldKey = $table . ':' . $fieldToMigrate;
-                               if (in_array($fieldKey, $finishedFields)) {
-                                       // this field was already migrated
-                                       continue;
-                               }
-                               $fieldsToGet = array($fieldToMigrate);
-                               if (isset($fieldConfiguration['titleTexts'])) {
-                                       $fieldsToGet[] = $fieldConfiguration['titleTexts'];
-                               }
-                               if (isset($fieldConfiguration['alternativeTexts'])) {
-                                       $fieldsToGet[] = $fieldConfiguration['alternativeTexts'];
-                               }
-                               if (isset($fieldConfiguration['captions'])) {
-                                       $fieldsToGet[] = $fieldConfiguration['captions'];
-                               }
-                               if (isset($fieldConfiguration['links'])) {
-                                       $fieldsToGet[] = $fieldConfiguration['links'];
-                               }
-
-                               do {
-                                       $records = $this->getRecordsFromTable($table, $fieldToMigrate, $fieldsToGet, self::RECORDS_PER_QUERY);
-                                       foreach ($records as $record) {
-                                               $this->migrateField($table, $record, $fieldToMigrate, $fieldConfiguration, $customMessages);
+               try {
+                       $this->init();
+                       $finishedFields = $this->getFinishedFields();
+                       foreach ($this->tables as $table => $tableConfiguration) {
+                               // find all additional fields we should get from the database
+                               foreach ($tableConfiguration as $fieldToMigrate => $fieldConfiguration) {
+                                       $fieldKey = $table . ':' . $fieldToMigrate;
+                                       if (in_array($fieldKey, $finishedFields)) {
+                                               // this field was already migrated
+                                               continue;
+                                       }
+                                       $fieldsToGet = array($fieldToMigrate);
+                                       if (isset($fieldConfiguration['titleTexts'])) {
+                                               $fieldsToGet[] = $fieldConfiguration['titleTexts'];
+                                       }
+                                       if (isset($fieldConfiguration['alternativeTexts'])) {
+                                               $fieldsToGet[] = $fieldConfiguration['alternativeTexts'];
+                                       }
+                                       if (isset($fieldConfiguration['captions'])) {
+                                               $fieldsToGet[] = $fieldConfiguration['captions'];
+                                       }
+                                       if (isset($fieldConfiguration['links'])) {
+                                               $fieldsToGet[] = $fieldConfiguration['links'];
                                        }
-                               } while (count($records) === self::RECORDS_PER_QUERY);
 
-                               // add the field to the "finished fields" if things didn't fail above
-                               if (is_array($records)) {
-                                       $finishedFields[] = $fieldKey;
+                                       do {
+                                               $records = $this->getRecordsFromTable($table, $fieldToMigrate, $fieldsToGet, self::RECORDS_PER_QUERY);
+                                               foreach ($records as $record) {
+                                                       $this->migrateField($table, $record, $fieldToMigrate, $fieldConfiguration, $customMessages);
+                                               }
+                                       } while (count($records) === self::RECORDS_PER_QUERY);
+
+                                       // add the field to the "finished fields" if things didn't fail above
+                                       if (is_array($records)) {
+                                               $finishedFields[] = $fieldKey;
+                                       }
                                }
                        }
+                       $this->markWizardAsDone(implode(',', $finishedFields));
+               } catch (\Exception $e) {
+                       $customMessages .= PHP_EOL . $e->getMessage();
                }
-               $this->markWizardAsDone(implode(',', $finishedFields));
-               return TRUE;
+               return empty($customMessages);
        }
 
        /**
@@ -314,10 +319,11 @@ class TceformsUpdateWizard extends AbstractUpdate {
                                try {
                                        // 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.
+                                       /** @var File $file */
                                        $file = $this->storage->getFile($fieldConfiguration['targetPath'] . $item);
                                        $fileUid = $file->getUid();
 
-                               } catch (\Exception $e) {
+                               } catch (\InvalidArgumentException $e) {
 
                                        // no file found, no reference can be set
                                        $this->logger->notice(