[TASK] Merge latest fixes for file references and metadata 15/57215/2
authorCybercraft <info@cybercraft.de>
Thu, 14 Jun 2018 11:43:10 +0000 (13:43 +0200)
committerJo Hasenau <info@cybercraft.de>
Thu, 14 Jun 2018 11:46:00 +0000 (13:46 +0200)
Change-Id: I22df3f91f8f43c4eef5f8ea0e494e8012138399a
Reviewed-on: https://review.typo3.org/57215
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
Classes/Model/L10nAccumulatedInformation.php
Classes/Model/L10nBaseService.php
composer.json
ext_emconf.php

index fb2b9d0..6913c2a 100644 (file)
@@ -22,6 +22,8 @@ use Localizationteam\L10nmgr\Model\Tools\Tools;
 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Utility\DebugUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -159,6 +161,7 @@ class L10nAccumulatedInformation
         if ($previewLanguage) {
             $t8Tools->previewLanguages = array($previewLanguage);
         }
+        $fileList = '';
         // Traverse tree elements:
         foreach ($tree->tree as $treeElement) {
             $pageId = $treeElement['row']['uid'];
@@ -185,6 +188,9 @@ class L10nAccumulatedInformation
                                     // Now, for each record, look for localization:
                                     foreach ($allRows as $row) {
                                         BackendUtility::workspaceOL($table, $row);
+                                        if ($table === 'sys_file_reference') {
+                                            $fileList .= $fileList ? ',' . (int)$row['uid_local'] : (int)$row['uid_local'];
+                                        }
                                         if (is_array($row) && count($tableUidConstraintIndex) > 0) {
                                             if (is_array($row) && isset($tableUidConstraintIndex[$table . ':' . $row['uid']])) {
                                                 $accum[$pageId]['items'][$table][$row['uid']] = $t8Tools->translationDetails($table,
@@ -203,9 +209,20 @@ class L10nAccumulatedInformation
                             }
                         }
                     }
+                    if ($table === 'sys_file_reference' && !empty($fileList)) {
+                        $fileList = implode(',', array_keys(array_flip(GeneralUtility::intExplode(',', $fileList, true))));
+                        if (!empty($fileList)) {
+                            $metaData = $this->getDatabaseConnection()->exec_SELECTgetRows('uid', 'sys_file_metadata', 'sys_language_uid = ' . (int)$previewLanguage . ' AND file IN (' . $fileList . ')', '', 'uid', '', 'uid');
+                            if (!empty($metaData)) {
+                                $l10ncfg['include'] .= $l10ncfg['include'] ? ',' : '';
+                                $l10ncfg['include'] .= 'sys_file_metadata:' . implode(',sys_file_metadata:', array_keys($metaData));
+                            }
+                        }
+                    }
                 }
             }
         }
+
         $includeIndex = array_unique(GeneralUtility::trimExplode(',', $l10ncfg['include'], 1));
         foreach ($includeIndex as $recId) {
             list($table, $uid) = explode(':', $recId);
@@ -245,6 +262,21 @@ class L10nAccumulatedInformation
     }
 
     /**
+     * Get DatabaseConnection instance - $GLOBALS['TYPO3_DB']
+     *
+     * This method should be used instead of direct access to
+     * $GLOBALS['TYPO3_DB'] for easy IDE auto completion.
+     *
+     * @return DatabaseConnection
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
+     */
+    protected function getDatabaseConnection()
+    {
+        GeneralUtility::logDeprecatedFunction();
+        return $GLOBALS['TYPO3_DB'];
+    }
+
+    /**
      * @return int
      */
     public function getFieldCount()
index dd16a12..6966b12 100644 (file)
@@ -59,6 +59,10 @@ class L10nBaseService
      */
     protected $checkedParentRecords = [];
     /**
+     * @var array
+     */
+    protected $childMappingArray = [];
+    /**
      * @var int
      */
     protected $depthCounter = 0;
@@ -454,6 +458,8 @@ class L10nBaseService
             foreach ($accum as $pId => $page) {
                 foreach ($accum[$pId]['items'] as $table => $elements) {
                     foreach ($elements as $elementUid => $data) {
+                        $element = BackendUtility::getRecordRaw($table,
+                            'uid = ' . (int)$elementUid . ($TCA[$table]['delete'] ? ' AND ' . $TCA[$table]['delete'] . '=0' : ''));
                         $hooks = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['beforeDataFieldsTranslated'];
                         if (is_array($hooks)) {
                             foreach ($hooks as $hookObj) {
@@ -476,12 +482,10 @@ class L10nBaseService
                                     // If new element is required, we prepare for localization
                                     if ($Tuid === 'NEW') {
                                         if ($table === 'tt_content' && ($gridElementsInstalled === true || $fluxInstalled === true)) {
-                                            $element = BackendUtility::getRecordRaw($table,
-                                                'uid = ' . (int)$elementUid . ' AND deleted = 0');
                                             if (isset($this->TCEmain_cmd['tt_content'][$elementUid])) {
                                                 unset($this->TCEmain_cmd['tt_content'][$elementUid]);
                                             }
-                                            if ((int)$element['colPos'] > -1 && (int)$element['colPos'] !== 18181) {
+                                            if ((int)$element['colPos'] !== -2 && (int)$element['colPos'] !== -1 && (int)$element['colPos'] !== 18181) {
                                                 $this->TCEmain_cmd['tt_content'][$elementUid]['localize'] = $Tlang;
                                             } else {
                                                 if ($element['tx_gridelements_container'] > 0) {
@@ -504,7 +508,7 @@ class L10nBaseService
                                                         unset($this->TCEmain_cmd[$table][$elementUid]);
                                                     }
                                                     $this->TCEmain_cmd[$table][$elementUid]['localize'] = $Tlang;
-                                                    $TCEmain_data[$Ttable][$TuidString]['tablenames'] = 'pages';
+                                                    $TCEmain_data[$table][$TuidString]['tablenames'] = 'pages';
                                                 } else {
                                                     $parent = BackendUtility::getRecordRaw($element['tablenames'],
                                                         $TCA[$element['tablenames']]['ctrl']['transOrigPointerField'] . ' = ' . (int)$element['uid_foreign'] .
@@ -523,6 +527,27 @@ class L10nBaseService
                                                 unset($this->TCEmain_cmd[$table][$elementUid]);
                                             }
                                             $this->TCEmain_cmd[$table][$elementUid]['localize'] = $Tlang;
+                                            /** @var $relationHandler RelationHandler */
+                                            // integrators have to make sure to configure fields of parent elements properly
+                                            // so they will do translations of their children automatically when translated
+                                            if (!empty($TCA[$table]['columns'][$key])) {
+                                                $configuration = $TCA[$table]['columns'][$key]['config'];
+                                                if ($configuration['foreign_table']) {
+                                                    $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
+                                                    $relationHandler->start($element[$key], $configuration['foreign_table'],
+                                                        $configuration['MM'], $elementUid, $table, $configuration);
+                                                    $relationHandler->processDeletePlaceholder();
+                                                    $referenceUids = $relationHandler->tableArray[$configuration['foreign_table']];
+                                                    if (!empty($referenceUids)) {
+                                                        foreach ($referenceUids as $referenceUid) {
+                                                            $this->childMappingArray[$configuration['foreign_table']][$referenceUid] = true;
+                                                            if ($table !== 'pages') {
+                                                                unset($this->TCEmain_cmd[$configuration['foreign_table']][$referenceUid]);
+                                                            }
+                                                        }
+                                                    }
+                                                }
+                                            }
                                         }
                                         $hooks = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['importNewTceMainCmd'];
                                         if (is_array($hooks)) {
@@ -563,27 +588,6 @@ class L10nBaseService
                             }
                         }
 
-                        /** @var $relationHandler RelationHandler */
-                        // integrators have to make sure to configure fields of parent elements properly
-                        // so they will do translations of their children automatically when translated
-                        if (!empty($TCA[$table]['columns'])) {
-                            foreach ($TCA[$table]['columns'] as $column => $setup) {
-                                $configuration = $setup['config'];
-                                if ($configuration['foreign_table']) {
-                                    $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
-                                    $relationHandler->start($element[$column], $configuration['foreign_table'],
-                                        $configuration['MM'], $elementUid, $table, $configuration);
-                                    $relationHandler->processDeletePlaceholder();
-                                    $referenceUids = $relationHandler->tableArray[$configuration['foreign_table']];
-                                    if (!empty($referenceUids)) {
-                                        foreach ($referenceUids as $referenceUid) {
-                                            unset($this->TCEmain_cmd[$configuration['foreign_table']][$referenceUid]);
-                                        }
-                                    }
-                                }
-                            }
-                        }
-
                         $hooks = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['afterDataFieldsTranslated'];
                         if (is_array($hooks)) {
                             foreach ($hooks as $hookObj) {
@@ -626,7 +630,7 @@ class L10nBaseService
                 foreach ($TCEmain_data[$table] as $TuidString => $fields) {
                     if ($table === 'sys_file_reference' && $fields['tablenames'] === 'pages') {
                         $parent = BackendUtility::getRecordRaw('pages_language_overlay',
-                            'pid = ' . (int)$element['uid_foreign'] . ' AND deleted = 0 AND sys_language_uid = ' . (int)$Tlang);
+                            'pid = ' . (int)$element['pid'] . ' AND deleted = 0 AND sys_language_uid = ' . (int)$Tlang);
                         if ($parent['uid']) {
                             $fields['tablenames'] = 'pages_language_overlay';
                             $fields['uid_foreign'] = $parent['uid'];
@@ -638,6 +642,23 @@ class L10nBaseService
                         if ($tce->copyMappingArray_merged[$table][$TdefRecord]) {
                             $TCEmain_data[$table][BackendUtility::wsMapId($table,
                                 $tce->copyMappingArray_merged[$table][$TdefRecord])] = $fields;
+                        } else if ($this->childMappingArray[$table][$TdefRecord]) {
+                            if ($this->childMappingArray[$table][$TdefRecord] === true) {
+                                $translatedRecordRaw = BackendUtility::getRecordRaw($table,
+                                    $TCA[$table]['ctrl']['transOrigPointerField'] . ' = ' . (int)$TdefRecord . ' AND deleted = 0 AND sys_language_uid = ' . (int)$Tlang);
+                                if ($translatedRecordRaw['uid']) {
+                                    $this->childMappingArray[$table][$TdefRecord] = $translatedRecordRaw['uid'];
+                                }
+                            }
+                            if ($this->childMappingArray[$table][$TdefRecord]) {
+                                if ($this->extensionConfiguration['enable_neverHideAtCopy'] == 1 &&
+                                    $TCA[$table]['ctrl']['enablecolumns'] &&
+                                    $TCA[$table]['ctrl']['enablecolumns']['disabled']) {
+                                    $fields[$TCA[$table]['ctrl']['enablecolumns']['disabled']] = 0;
+                                }
+                                $TCEmain_data[$table][BackendUtility::wsMapId($table,
+                                    $this->childMappingArray[$table][$TdefRecord])] = $fields;
+                            }
                         } else {
                             GeneralUtility::sysLog(__FILE__ . ': ' . __LINE__ . ': Record "' . $table . ':' . $TdefRecord . '" was NOT localized as it should have been!',
                                 'l10nmgr');
index ac7be73..c88a16e 100644 (file)
@@ -1,7 +1,7 @@
 {
        "name": "localizationteam/l10nmgr",
        "type": "typo3-cms-extension",
-       "version" : "8.2.4",
+       "version" : "8.3.1",
        "description": "Module for managing localization import and export",
        "homepage": "https://docs.typo3.org/typo3cms/extensions/l10nmgr/",
        "license": ["GPL-2.0-or-later"],
index 71a8752..c1684af 100644 (file)
@@ -10,7 +10,7 @@ $EM_CONF[$_EXTKEY] = array(
   'title' => 'Localization Manager',
   'description' => 'Module for managing localization import and export',
   'category' => 'module',
-  'version' => '8.2.4',
+  'version' => '8.3.1',
   'state' => 'beta',
   'uploadfolder' => false,
   'createDirs' => 'uploads/tx_l10nmgr/settings,uploads/tx_l10nmgr/saved_files,uploads/tx_l10nmgr/jobs,uploads/tx_l10nmgr/jobs/out,uploads/tx_l10nmgr/jobs/in,uploads/tx_l10nmgr/jobs/done,uploads/tx_l10nmgr/jobs/_cmd',