[BUGFIX] Executing Extbase commands as scheduler task 28/46928/5
authorNicole Cordes <typo3@cordes.co>
Sat, 27 Feb 2016 12:03:54 +0000 (13:03 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 3 Mar 2016 20:33:54 +0000 (21:33 +0100)
Currently the execution of all Extbase commands as scheduler task
exits with a warning due to wrong parameter input type. This patch
ensures the object is initialized only if needed and a correct CLI
context is available.

Resolves: #73714
Releases: master
Change-Id: I869b1fe9e8440885f4cfb6fb0570ca98334494a1
Reviewed-on: https://review.typo3.org/46928
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extbase/Classes/Mvc/Cli/ConsoleOutput.php

index 37b8522..06d6d56 100644 (file)
@@ -63,8 +63,6 @@ class ConsoleOutput
      */
     public function __construct()
     {
-        $this->input = new ArgvInput();
-
         $this->output = new SymfonyConsoleOutput();
         $this->output->getFormatter()->setStyle('b', new OutputFormatterStyle(null, null, array('bold')));
         $this->output->getFormatter()->setStyle('i', new OutputFormatterStyle('black', 'white'));
@@ -167,7 +165,7 @@ class ConsoleOutput
             ->setMaxAttempts($attempts)
             ->setErrorMessage('Value "%s" is invalid');
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -184,7 +182,7 @@ class ConsoleOutput
         $question = (new Question($question, $default))
             ->setAutocompleterValues($autocomplete);
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -200,7 +198,7 @@ class ConsoleOutput
     {
         $question = new ConfirmationQuestion($question, $default);
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -217,7 +215,7 @@ class ConsoleOutput
             ->setHidden(true)
             ->setHiddenFallback($fallback);
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -242,7 +240,7 @@ class ConsoleOutput
             ->setMaxAttempts($attempts)
             ->setAutocompleterValues($autocomplete);
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -268,7 +266,7 @@ class ConsoleOutput
             ->setHidden(true)
             ->setHiddenFallback($fallback);
 
-        return $this->getQuestionHelper()->ask($this->input, $this->output, $question);
+        return $this->getQuestionHelper()->ask($this->getInput(), $this->output, $question);
     }
 
     /**
@@ -317,6 +315,21 @@ class ConsoleOutput
     }
 
     /**
+     * @return ArgvInput
+     * @throws \RuntimeException
+     */
+    protected function getInput() {
+        if ($this->input === null) {
+            if (!isset($_SERVER['argv'])) {
+                throw new \RuntimeException('Cannot initialize ArgvInput object without CLI context.', 1456914444);
+            }
+            $this->input = new ArgvInput();
+        }
+
+        return $this->input;
+    }
+
+    /**
      * Returns or initializes the symfony/console QuestionHelper
      *
      * @return QuestionHelper