Commit 0cc9e0da authored by guilhermeblanco's avatar guilhermeblanco

[2.0][DDC-426] Fixed issue with CliController that never notifies if run()...

[2.0][DDC-426] Fixed issue with CliController that never notifies if run() executed successfully or not.
parent e06f7c98
...@@ -67,13 +67,13 @@ class CliController extends AbstractNamespace ...@@ -67,13 +67,13 @@ class CliController extends AbstractNamespace
{ {
$this->setPrinter($printer); $this->setPrinter($printer);
$this->setConfiguration($config); $this->setConfiguration($config);
// Include core namespaces of tasks // Include core namespaces of tasks
$ns = 'Doctrine\Common\Cli\Tasks'; $ns = 'Doctrine\Common\Cli\Tasks';
$this->addNamespace('Core') $this->addNamespace('Core')
->addTask('help', $ns . '\HelpTask') ->addTask('help', $ns . '\HelpTask')
->addTask('version', $ns . '\VersionTask'); ->addTask('version', $ns . '\VersionTask');
$ns = 'Doctrine\ORM\Tools\Cli\Tasks'; $ns = 'Doctrine\ORM\Tools\Cli\Tasks';
$this->addNamespace('Orm') $this->addNamespace('Orm')
->addTask('clear-cache', $ns . '\ClearCacheTask') ->addTask('clear-cache', $ns . '\ClearCacheTask')
...@@ -83,13 +83,13 @@ class CliController extends AbstractNamespace ...@@ -83,13 +83,13 @@ class CliController extends AbstractNamespace
->addTask('run-dql', $ns . '\RunDqlTask') ->addTask('run-dql', $ns . '\RunDqlTask')
->addTask('schema-tool', $ns . '\SchemaToolTask') ->addTask('schema-tool', $ns . '\SchemaToolTask')
->addTask('version', $ns . '\VersionTask'); ->addTask('version', $ns . '\VersionTask');
$ns = 'Doctrine\DBAL\Tools\Cli\Tasks'; $ns = 'Doctrine\DBAL\Tools\Cli\Tasks';
$this->addNamespace('Dbal') $this->addNamespace('Dbal')
->addTask('run-sql', $ns . '\RunSqlTask') ->addTask('run-sql', $ns . '\RunSqlTask')
->addTask('version', $ns . '\VersionTask'); ->addTask('version', $ns . '\VersionTask');
} }
/** /**
* Add a single task to CLI Core Namespace. This method acts as a delegate. * Add a single task to CLI Core Namespace. This method acts as a delegate.
* Example of inclusion support to a single task: * Example of inclusion support to a single task:
...@@ -105,10 +105,10 @@ class CliController extends AbstractNamespace ...@@ -105,10 +105,10 @@ class CliController extends AbstractNamespace
public function addTask($name, $class) public function addTask($name, $class)
{ {
$this->getNamespace('Core')->addTask($name, $class); $this->getNamespace('Core')->addTask($name, $class);
return $this; return $this;
} }
/** /**
* Processor of CLI Tasks. Handles multiple task calls, instantiate * Processor of CLI Tasks. Handles multiple task calls, instantiate
* respective classes and run them. * respective classes and run them.
...@@ -119,37 +119,40 @@ class CliController extends AbstractNamespace ...@@ -119,37 +119,40 @@ class CliController extends AbstractNamespace
{ {
// Remove script file argument // Remove script file argument
$scriptFile = array_shift($args); $scriptFile = array_shift($args);
// If not arguments are defined, include "help" // If not arguments are defined, include "help"
if (empty($args)) { if (empty($args)) {
array_unshift($args, 'Core:Help'); array_unshift($args, 'Core:Help');
} }
// Process all sent arguments // Process all sent arguments
$args = $this->_processArguments($args); $args = $this->_processArguments($args);
try { try {
$this->getPrinter()->writeln('Doctrine Command Line Interface' . PHP_EOL, 'HEADER'); $this->getPrinter()->writeln('Doctrine Command Line Interface' . PHP_EOL, 'HEADER');
// Handle possible multiple tasks on a single command // Handle possible multiple tasks on a single command
foreach($args as $taskData) { foreach($args as $taskData) {
$taskName = $taskData['name']; $taskName = $taskData['name'];
$taskArguments = $taskData['args']; $taskArguments = $taskData['args'];
$this->runTask($taskName, $taskArguments); $this->runTask($taskName, $taskArguments);
} }
return true;
} catch (\Exception $e) { } catch (\Exception $e) {
$message = $taskName . ' => ' . $e->getMessage(); $message = $taskName . ' => ' . $e->getMessage();
if (isset($taskArguments['trace']) && $taskArguments['trace']) { if (isset($taskArguments['trace']) && $taskArguments['trace']) {
$message .= PHP_EOL . PHP_EOL . $e->getTraceAsString(); $message .= PHP_EOL . PHP_EOL . $e->getTraceAsString();
} }
$this->getPrinter()->writeln($message, 'ERROR'); $this->getPrinter()->writeln($message, 'ERROR');
return false;
} }
} }
/** /**
* Executes a given CLI Task * Executes a given CLI Task
* *
...@@ -160,14 +163,14 @@ class CliController extends AbstractNamespace ...@@ -160,14 +163,14 @@ class CliController extends AbstractNamespace
{ {
// Retrieve namespace name, task name and arguments // Retrieve namespace name, task name and arguments
$taskPath = explode(':', $name); $taskPath = explode(':', $name);
// Find the correct namespace where the task is defined // Find the correct namespace where the task is defined
$taskName = array_pop($taskPath); $taskName = array_pop($taskPath);
$taskNamespace = $this->_retrieveTaskNamespace($taskPath); $taskNamespace = $this->_retrieveTaskNamespace($taskPath);
$taskNamespace->runTask($taskName, $args); $taskNamespace->runTask($taskName, $args);
} }
/** /**
* Processes arguments and returns a structured hierachy. * Processes arguments and returns a structured hierachy.
* Example: * Example:
...@@ -211,12 +214,12 @@ class CliController extends AbstractNamespace ...@@ -211,12 +214,12 @@ class CliController extends AbstractNamespace
$regex = '/\s*[,]?\s*"([^"]*)"|\s*[,]?\s*([^,]*)/i'; $regex = '/\s*[,]?\s*"([^"]*)"|\s*[,]?\s*([^,]*)/i';
$preparedArgs = array(); $preparedArgs = array();
$out = & $preparedArgs; $out = & $preparedArgs;
foreach ($args as $arg){ foreach ($args as $arg){
// --foo --bar=baz // --foo --bar=baz
if (substr($arg, 0, 2) == '--'){ if (substr($arg, 0, 2) == '--'){
$eqPos = strpos($arg, '='); $eqPos = strpos($arg, '=');
// --foo // --foo
if ($eqPos === false){ if ($eqPos === false){
$key = substr($arg, 2); $key = substr($arg, 2);
...@@ -245,7 +248,7 @@ class CliController extends AbstractNamespace ...@@ -245,7 +248,7 @@ class CliController extends AbstractNamespace
// -abc // -abc
} else { } else {
$chars = str_split(substr($arg, 1)); $chars = str_split(substr($arg, 1));
foreach ($chars as $char){ foreach ($chars as $char){
$key = $char; $key = $char;
$out[$key] = isset($out[$key]) ? $out[$key] : true; $out[$key] = isset($out[$key]) ? $out[$key] : true;
...@@ -261,7 +264,7 @@ class CliController extends AbstractNamespace ...@@ -261,7 +264,7 @@ class CliController extends AbstractNamespace
$out = & $preparedArgs[$key]['args']; $out = & $preparedArgs[$key]['args'];
} }
} }
return $preparedArgs; return $preparedArgs;
} }
...@@ -276,25 +279,25 @@ class CliController extends AbstractNamespace ...@@ -276,25 +279,25 @@ class CliController extends AbstractNamespace
{ {
$taskNamespace = $this; $taskNamespace = $this;
$currentNamespacePath = ''; $currentNamespacePath = '';
// Consider possible missing namespace (ie. "help") and forward to "core" // Consider possible missing namespace (ie. "help") and forward to "core"
if (count($namespacePath) == 0) { if (count($namespacePath) == 0) {
$namespacePath = array('Core'); $namespacePath = array('Core');
} }
// Loop through each namespace // Loop through each namespace
foreach ($namespacePath as $namespaceName) { foreach ($namespacePath as $namespaceName) {
$taskNamespace = $taskNamespace->getNamespace($namespaceName); $taskNamespace = $taskNamespace->getNamespace($namespaceName);
// If the given namespace returned "null", throw exception // If the given namespace returned "null", throw exception
if ($taskNamespace === null) { if ($taskNamespace === null) {
throw CliException::namespaceDoesNotExist($namespaceName, $currentNamespacePath); throw CliException::namespaceDoesNotExist($namespaceName, $currentNamespacePath);
} }
$currentNamespacePath = (( ! empty($currentNamespacePath)) ? ':' : '') $currentNamespacePath = (( ! empty($currentNamespacePath)) ? ':' : '')
. $taskNamespace->getName(); . $taskNamespace->getName();
} }
return $taskNamespace; return $taskNamespace;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment