. */ /** * Doctrine_Task_Dql * * @package Doctrine * @subpackage Task * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 2761 $ * @author Jonathan H. Wage */ class Doctrine_Task_Dql extends Doctrine_Task { public $description = 'Execute dql query and display the results', $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 = $this->getArgument('params'); $params = $params ? explode(',', $params):array(); $this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')'); $results = $query->query($dql); $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); } } } }