[TASK] Make "current page" configurations usable with CLI export/import 03/58203/4
authorCybercraft <info@cybercraft.de>
Thu, 6 Sep 2018 15:09:55 +0000 (17:09 +0200)
committerJo Hasenau <info@cybercraft.de>
Sat, 8 Sep 2018 14:34:03 +0000 (16:34 +0200)
Change-Id: I212169fc3ce49872fc1bf594e61ed3d64a0ef5d5
Reviewed-on: https://review.typo3.org/58203
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
Classes/Cli/Export.php
Classes/Cli/Import.php
Classes/Model/L10nConfiguration.php

index 6578567..40cd437 100644 (file)
@@ -64,6 +64,16 @@ class Export extends CommandLineController
             "UID of the workspace used during export. Default = 0\n"
         );
         $this->cli_options[] = array(
+            '--srcPID',
+            'Source page ID',
+            "UID of the page used during export. Needs configuration depth to be set to \"current page\" Default = 0\n"
+        );
+        $this->cli_options[] = array(
+            '--forcedSourceLanguage',
+            'Forced Source Language ID',
+            "UID of the already translated language used as overlaid source language during export."
+        );
+        $this->cli_options[] = array(
             '--hidden',
             'Do not export hidden contents',
             "The values can be: \n TRUE = Hidden content is skipped\n FALSE = Hidden content is exported. Default is FALSE.\n"
@@ -238,6 +248,8 @@ class Export extends CommandLineController
         /** @var L10nConfiguration $l10nmgrCfgObj */
         $l10nmgrCfgObj = GeneralUtility::makeInstance(L10nConfiguration::class);
         $l10nmgrCfgObj->load($l10ncfg);
+        $sourcePid = isset($this->cli_args['--srcPID']) ? (int)$this->cli_args['--srcPID'][0] : 0;
+        $l10nmgrCfgObj->setSourcePid($sourcePid);
         if ($l10nmgrCfgObj->isLoaded()) {
             /** @var CatXmlView $l10nmgrGetXML */
             $l10nmgrGetXML = GeneralUtility::makeInstance(CatXmlView::class, $l10nmgrCfgObj, $tlang);
@@ -250,6 +262,10 @@ class Export extends CommandLineController
                     $l10nmgrGetXML->setForcedSourceLanguage($forceLanguage);
                 }
             }
+            $forceLanguage = isset($this->cli_args['--forcedSourceLanguage']) ? (int)$this->cli_args['--forcedSourceLanguage'][0] : 0;
+            if ($forceLanguage) {
+                $l10nmgrGetXML->setForcedSourceLanguage($forceLanguage);
+            }
             $onlyChanged = isset($this->cli_args['--updated']) ? $this->cli_args['--updated'][0] : 'FALSE';
             if ($onlyChanged === 'TRUE') {
                 $l10nmgrGetXML->setModeOnlyChanged();
@@ -349,6 +365,7 @@ class Export extends CommandLineController
         /** @var L10nConfiguration $l10nmgrCfgObj */
         $l10nmgrCfgObj = GeneralUtility::makeInstance(L10nConfiguration::class);
         $l10nmgrCfgObj->load($l10ncfg);
+        $l10nmgrCfgObj->setSourcePid((int)$this->cli_args['--srcPID']);
         if ($l10nmgrCfgObj->isLoaded()) {
             /** @var ExcelXmlView $l10nmgrGetXML */
             $l10nmgrGetXML = GeneralUtility::makeInstance(ExcelXmlView::class, $l10nmgrCfgObj, $tlang);
@@ -361,6 +378,10 @@ class Export extends CommandLineController
                     $l10nmgrGetXML->setForcedSourceLanguage($forceLanguage);
                 }
             }
+            $forceLanguage = isset($this->cli_args['--forcedSourceLanguage']) ? (int)$this->cli_args['--forcedSourceLanguage'][0] : 0;
+            if ($forceLanguage) {
+                $l10nmgrGetXML->setForcedSourceLanguage($forceLanguage);
+            }
             $onlyChanged = isset($this->cli_args['--updated']) ? $this->cli_args['--updated'][0] : 'FALSE';
             if ($onlyChanged === 'TRUE') {
                 $l10nmgrGetXML->setModeOnlyChanged();
index dcb6b56..32633ca 100644 (file)
@@ -113,6 +113,11 @@ class Import extends CommandLineController
             'Import as default language',
             "If set this setting will overwrite the default language during the import.\nThe values can be: \n TRUE = Content will be imported as default language.\n FALSE = Content will be imported as translation (default).\n"
         );
+        $this->cli_options[] = array(
+            '--srcPID',
+            'Source page ID',
+            "UID of the page used during export. Needs configuration depth to be set to \"current page\" Default = 0\n"
+        );
         // Setting help texts
         $this->cli_help['name'] = 'Localization Manager importer';
         $this->cli_help['synopsis'] = '###OPTIONS###';
@@ -252,6 +257,12 @@ class Import extends CommandLineController
             $importAsDefaultLanguage = (bool)$this->cli_args['_DEFAULT'][6];
         }
         $this->callParameters['importAsDefaultLanguage'] = $importAsDefaultLanguage;
+        // Source PID
+        $sourcePid = 0;
+        if (isset($this->cli_args['--srcPID'])) {
+            $sourcePid = (int)$this->cli_args['--srcPID'][0];
+        }
+        $this->callParameters['sourcePid'] = $sourcePid;
     }
 
     /**
@@ -314,6 +325,7 @@ class Import extends CommandLineController
             /** @var L10nConfiguration $l10ncfgObj */
             $l10ncfgObj = GeneralUtility::makeInstance(L10nConfiguration::class);
             $l10ncfgObj->load($importManager->headerData['t3_l10ncfg']);
+            $l10ncfgObj->setSourcePid($this->callParameters['sourcePid']);
             $status = $l10ncfgObj->isLoaded();
             if ($status === false) {
                 $this->cli_echo("l10ncfg not loaded! Exiting...\n");
@@ -448,6 +460,7 @@ class Import extends CommandLineController
                         /** @var L10nConfiguration $l10ncfgObj */
                         $l10ncfgObj = GeneralUtility::makeInstance(L10nConfiguration::class);
                         $l10ncfgObj->load($importManager->headerData['t3_l10ncfg']);
+                        $l10ncfgObj->setSourcePid($this->callParameters['sourcePid']);
                         $status = $l10ncfgObj->isLoaded();
                         if ($status === false) {
                             $this->cli_echo("l10ncfg not loaded! Exiting...\n");
index 4157f57..8d3baea 100644 (file)
@@ -44,6 +44,11 @@ class L10nConfiguration
     public $l10ncfg;
 
     /**
+     * @var int
+     */
+    protected $sourcePid;
+
+    /**
      * loads internal array with l10nmgrcfg record
      *
      * @param int $id Id of the cfg record
@@ -89,7 +94,7 @@ class L10nConfiguration
      **/
     public function getData($key)
     {
-        return $this->l10ncfg[$key];
+        return $key === 'pid' && (int)$this->l10ncfg['depth'] === -1 && (int)$this->sourcePid ? (int)$this->sourcePid : $this->l10ncfg[$key];
     }
 
     /**
@@ -98,7 +103,7 @@ class L10nConfiguration
      * @param int $sysLang sys_language_uid
      *
      * @return L10nAccumulatedInformation
-     **/
+     */
     public function getL10nAccumulatedInformationsObjectForLanguage($sysLang)
     {
         $l10ncfg = $this->l10ncfg;
@@ -107,7 +112,8 @@ class L10nConfiguration
         // Showing the tree:
         // Initialize starting point of page tree:
         if ($depth === -1) {
-            $treeStartingPoints = array((int)GeneralUtility::_GET('srcPID'));
+            $sourcePid = (int)$this->sourcePid ? (int)$this->sourcePid : (int)GeneralUtility::_GET('srcPID');
+            $treeStartingPoints = array($sourcePid);
         } else {
             if ($depth === -2 && !empty($l10ncfg['pages'])) {
                 $treeStartingPoints = GeneralUtility::intExplode(',', $l10ncfg['pages']);
@@ -198,4 +204,14 @@ class L10nConfiguration
         GeneralUtility::logDeprecatedFunction();
         return $GLOBALS['TYPO3_DB'];
     }
+
+    /**
+     * @param int $id
+     * @return void
+     */
+    public function setSourcePid($id)
+    {
+        $this->sourcePid = (int)$id;
+    }
+
 }
\ No newline at end of file