[TASK] Finalize L10nModeUpdater for enhanced l10n_modes
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / RowUpdater / ImageCropUpdater.php
index 31ef750..c1d69d1 100644 (file)
@@ -29,6 +29,16 @@ use TYPO3\CMS\Install\Service\LoadTcaService;
  */
 class ImageCropUpdater implements RowUpdaterInterface
 {
+    /**
+     * @var array Full, migrated TCA as prepared by upgrade wizard controller
+     */
+    protected $migratedTca;
+
+    /**
+     * @var array Full, but NOT migrated TCA
+     */
+    protected $notMigratedTca;
+
     /**
      * List of tables with information about to migrate fields.
      * Created during hasPotentialUpdateForTable(), used in updateTableRow()
@@ -37,6 +47,18 @@ class ImageCropUpdater implements RowUpdaterInterface
      */
     protected $payload = [];
 
+    /**
+     * Prepare non-migrated TCA to be used in 'hasPotentialUpdateForTable' step
+     */
+    public function __construct()
+    {
+        $this->migratedTca = $GLOBALS['TCA'];
+        $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
+        $loadTcaService->loadExtensionTablesWithoutMigration();
+        $this->notMigratedTca = $GLOBALS['TCA'];
+        $GLOBALS['TCA'] = $this->migratedTca;
+    }
+
     /**
      * Get title
      *
@@ -55,12 +77,14 @@ class ImageCropUpdater implements RowUpdaterInterface
      */
     public function hasPotentialUpdateForTable(string $tableName): bool
     {
+        $GLOBALS['TCA'] = $this->notMigratedTca;
         $result = false;
         $payload = $this->getPayloadForTable($tableName);
         if (count($payload) !== 0) {
             $this->payload[$tableName] = $payload;
             $result = true;
         }
+        $GLOBALS['TCA'] = $this->migratedTca;
         return $result;
     }
 
@@ -78,13 +102,16 @@ class ImageCropUpdater implements RowUpdaterInterface
         foreach ($tablePayload['fields'] as $field) {
             if (strpos($inputRow[$field], '{"x":') === 0) {
                 $file = $this->getFile($inputRow, $tablePayload['fileReferenceField'] ?: 'uid_local');
-                $cropArea = Area::createFromConfiguration(json_decode($inputRow[$field], true));
-                $cropVariantCollectionConfig = [
-                    'default' => [
-                        'cropArea' => $cropArea->makeRelativeBasedOnFile($file)->asArray(),
-                    ]
-                ];
-                $inputRow[$field] = json_encode($cropVariantCollectionConfig);
+                $cropArray = json_decode($inputRow[$field], true);
+                if (is_array($cropArray)) {
+                    $cropArea = Area::createFromConfiguration(json_decode($inputRow[$field], true));
+                    $cropVariantCollectionConfig = [
+                        'default' => [
+                            'cropArea' => $cropArea->makeRelativeBasedOnFile($file)->asArray(),
+                        ]
+                    ];
+                    $inputRow[$field] = json_encode($cropVariantCollectionConfig);
+                }
             }
         }
 
@@ -106,8 +133,6 @@ class ImageCropUpdater implements RowUpdaterInterface
      */
     protected function getPayloadForTable(string $tableName): array
     {
-        $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
-        $loadTcaService->loadExtensionTablesWithoutMigration();
         if (!is_array($GLOBALS['TCA'][$tableName])) {
             throw new \RuntimeException(
                 'Globals TCA of given table name must exist',