1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Fixes to sandbox and added printing of params to output of dql task.

This commit is contained in:
jwage 2008-01-25 02:53:24 +00:00
parent 00195ebb7d
commit ddefc7f96d
2 changed files with 16 additions and 14 deletions

View File

@ -36,38 +36,40 @@ class Doctrine_Task_Dql extends Doctrine_Task
$requiredArguments = array('models_path' => 'Specify path to your Doctrine_Record definitions.',
'dql_query' => 'Specify the complete dql query to execute.'),
$optionalArguments = array('params' => 'Comma separated list of the params to replace the ? tokens in the dql');
public function execute()
{
Doctrine::loadModels($this->getArgument('models_path'));
$dql = $this->getArgument('dql_query');
$query = new Doctrine_Query();
$params = explode(',', $this->getArgument('params'));
$this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')');
$this->notify('executing: "' . $dql . '"');
$results = $query->query($dql, explode(',', $this->getArgument('params')));
$results = $query->query($dql, $params);
$this->printResults($results);
}
protected function printResults($data)
{
$array = $data->toArray(true);
$yaml = Doctrine_Parser::dump($array, 'yml');
$lines = explode("\n", $yaml);
unset($lines[0]);
$lines[1] = $data->getTable()->getOption('name') . ':';
foreach ($lines as $yamlLine) {
$line = trim($yamlLine);
if ($line) {
$this->notify($yamlLine);
}
}
}
}
}

View File

@ -50,4 +50,4 @@ spl_autoload_register(array('Doctrine', 'autoload'));
Doctrine_Manager::connection(DSN, 'sandbox');
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);