Commit 975b74bd authored by Jonathan.Wage's avatar Jonathan.Wage

Enhancements to CLI and removing sandbox files. Will add ignores.

parent 8d2aebad
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* *
* Doctrine_Adapter * Doctrine_Adapter
......
...@@ -32,10 +32,13 @@ ...@@ -32,10 +32,13 @@
*/ */
class Doctrine_Cli class Doctrine_Cli
{ {
protected $tasks = array(); protected $tasks = array(),
protected $scriptName = null; $taskInstance = null,
protected $config = array(); $formatter = null,
$scriptName = null,
$message = null,
$config = array();
/** /**
* __construct * __construct
* *
...@@ -45,6 +48,29 @@ class Doctrine_Cli ...@@ -45,6 +48,29 @@ class Doctrine_Cli
public function __construct($config = array()) public function __construct($config = array())
{ {
$this->config = $config; $this->config = $config;
$this->formatter = new Doctrine_Cli_AnsiColorFormatter();
}
/**
* notify
*
* @param string $notification
* @return void
*/
public function notify($notification = null)
{
echo $this->formatter->format($this->taskInstance->getTaskName(), 'INFO') . ' - ' . $this->formatter->format($notification, 'HEADER') . "\n";
}
/**
* notifyException
*
* @param string $exception
* @return void
*/
public function notifyException($exception)
{
echo $this->formatter->format($exception->getMessage(), 'ERROR') . "\n";
} }
/** /**
...@@ -56,43 +82,79 @@ class Doctrine_Cli ...@@ -56,43 +82,79 @@ class Doctrine_Cli
*/ */
public function run($args) public function run($args)
{ {
echo "\n";
try {
$this->_run($args);
} catch (Exception $exception) {
$this->notifyException($exception);
}
echo "\n";
}
protected function _getTaskClassFromArgs($args)
{
$taskName = str_replace('-', '_', $args[1]);
$taskClass = 'Doctrine_Task_' . Doctrine::classify($taskName);
return $taskClass;
}
protected function _run($args)
{
$this->scriptName = $args[0]; $this->scriptName = $args[0];
$taskName = $args[1];
$arg1 = isset($args[1]) ? $args[1]:null;
if (!$arg1 || $arg1 == 'help') {
echo $this->printTasks(null, $arg1 == 'help' ? true:false);
return;
}
if (!isset($args[1])) { if (isset($args[1]) && isset($args[2]) && $args[2] == 'help') {
echo $this->printTasks(); echo $this->printTasks($args[1], true);
return; return;
} }
$taskClass = $this->_getTaskClassFromArgs($args);
if (!class_exists($taskClass)) {
throw new Doctrine_Cli_Exception('Cli task could not be found: ' . $taskClass);
}
unset($args[0]); unset($args[0]);
$taskName = str_replace('-', '_', $args[1]);
unset($args[1]); unset($args[1]);
$taskClass = 'Doctrine_Task_' . Doctrine::classify($taskName); $this->taskInstance = new $taskClass($this);
if (class_exists($taskClass)) { $args = $this->prepareArgs($args);
$taskInstance = new $taskClass();
$this->taskInstance->setArguments($args);
$args = $this->prepareArgs($taskInstance, $args);
try {
$taskInstance->setArguments($args); if ($this->taskInstance->validate()) {
$this->taskInstance->execute();
if ($taskInstance->validate()) { } else {
$taskInstance->execute(); echo $this->formatter->format('Requires arguments missing!!', 'ERROR') . "\n\n";
echo $this->printTasks($taskName, true);
} }
} else { } catch (Exception $e) {
throw new Doctrine_Cli_Exception('Cli task could not be found: '.$taskClass); throw new Doctrine_Cli_Exception($e->getMessage());
} }
} }
/** /**
* prepareArgs * prepareArgs
* *
* @param string $taskInstance
* @param string $args * @param string $args
* @return array $prepared * @return array $prepared
*/ */
protected function prepareArgs($taskInstance, $args) protected function prepareArgs($args)
{ {
$taskInstance = $this->taskInstance;
$args = array_values($args); $args = array_values($args);
// First lets load populate an array with all the possible arguments. required and optional // First lets load populate an array with all the possible arguments. required and optional
...@@ -137,54 +199,63 @@ class Doctrine_Cli ...@@ -137,54 +199,63 @@ class Doctrine_Cli
* *
* @return void * @return void
*/ */
public function printTasks() public function printTasks($task = null, $full = false)
{ {
$task = Doctrine::classify(str_replace('-', '_', $task));
$tasks = $this->loadTasks(); $tasks = $this->loadTasks();
echo "\nAvailable Doctrine Command Line Interface Tasks\n"; echo $this->formatter->format("Doctrine Command Line Interface", 'HEADER') . "\n\n";
echo str_repeat('-', 40)."\n\n";
foreach ($tasks as $taskName) foreach ($tasks as $taskName)
{ {
if ($task != null && strtolower($task) != strtolower($taskName)) {
continue;
}
$className = 'Doctrine_Task_' . $taskName; $className = 'Doctrine_Task_' . $taskName;
$taskInstance = new $className(); $taskInstance = new $className();
$taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName)); $taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName));
echo $taskInstance->getDescription() . "\n";
$syntax = "Syntax: ";
$syntax .= $this->scriptName . ' ' . $taskInstance->getTaskName(); $syntax = $this->scriptName . ' ' . $taskInstance->getTaskName();
if ($required = $taskInstance->getRequiredArguments()) {
$syntax .= ' <' . implode('> <', $required) . '>';
}
if ($optional = $taskInstance->getOptionalArguments()) {
$syntax .= ' <' . implode('> <', $optional) . '>';
}
echo $syntax."\n"; echo $this->formatter->format($syntax, 'INFO');
$args = null; if ($full) {
if ($requiredArguments = $taskInstance->getRequiredArgumentsDescriptions()) { echo " - " . $taskInstance->getDescription() . "\n";
foreach ($requiredArguments as $name => $description) {
$args .= '*' . $name . ' - ' . $description."\n"; $args = null;
$requiredArguments = $taskInstance->getRequiredArgumentsDescriptions();
if (!empty($requiredArguments)) {
foreach ($requiredArguments as $name => $description) {
$args .= $this->formatter->format($name, "ERROR");
if (isset($this->config[$name])) {
$args .= " - " . $this->formatter->format($this->config[$name], 'COMMENT');
} else {
$args .= " - " . $description;
}
$args .= "\n";
}
} }
}
if ($optionalArguments = $taskInstance->getOptionalArgumentsDescriptions()) { $optionalArguments = $taskInstance->getOptionalArgumentsDescriptions();
foreach ($optionalArguments as $name => $description) {
$args .= $name . ' - ' . $description."\n"; if (!empty($optionalArguments)) {
foreach ($optionalArguments as $name => $description) {
$args .= $name . ' - ' . $description."\n";
}
} }
}
if ($args) { if ($args) {
echo "\nArguments (* = required):\n"; echo "\n" . $this->formatter->format('Arguments:', 'HEADER') . "\n" . $args;
echo $args; }
} }
echo "\n".str_repeat("-", 40)."\n"; echo "\n";
} }
} }
......
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* $Id: AnsiColorFormatter.php 2702 2007-10-03 21:43:22Z Jonathan.Wage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_AnsiColorFormatter provides methods to colorize text to be displayed on a console.
*
* @package Doctrine
* @subpackage Cli
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfAnsiColorFormatter.class.php 5250 2007-09-24 08:11:50Z fabien $
*/
class Doctrine_Cli_AnsiColorFormatter extends Doctrine_Cli_Formatter
{
protected
$styles = array(
'HEADER' => array('fg' => 'black', 'bold' => true),
'ERROR' => array('bg' => 'red', 'fg' => 'white', 'bold' => true),
'INFO' => array('fg' => 'green', 'bold' => true),
'COMMENT' => array('fg' => 'yellow'),
),
$options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8),
$foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37),
$background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
/**
* Sets a new style.
*
* @param string The style name
* @param array An array of options
*/
public function setStyle($name, $options = array())
{
$this->styles[$name] = $options;
}
/**
* Formats a text according to the given style or parameters.
*
* @param string The test to style
* @param mixed An array of options or a style name
*
* @return string The styled text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
if (!$this->supportsColors($stream))
{
return $text;
}
if (!is_array($parameters) && 'NONE' == $parameters)
{
return $text;
}
if (!is_array($parameters) && isset($this->styles[$parameters]))
{
$parameters = $this->styles[$parameters];
}
$codes = array();
if (isset($parameters['fg']))
{
$codes[] = $this->foreground[$parameters['fg']];
}
if (isset($parameters['bg']))
{
$codes[] = $this->background[$parameters['bg']];
}
foreach ($this->options as $option => $value)
{
if (isset($parameters[$option]) && $parameters[$option])
{
$codes[] = $value;
}
}
return "\033[".implode(';', $codes).'m'.$text."\033[0m";
}
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
$width = 9 + strlen($this->format('', 'INFO'));
return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size));
}
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if (!$size)
{
$size = $this->size;
}
if (strlen($text) < $size)
{
return $text;
}
$subsize = floor(($size - 3) / 2);
return substr($text, 0, $subsize).$this->format('...', 'INFO').substr($text, -$subsize);
}
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - windows
* - non tty consoles
*
* @param mixed A stream
*
* @return Boolean true if the stream supports colorization, false otherwise
*/
public function supportsColors($stream)
{
return DIRECTORY_SEPARATOR != '\\' && function_exists('posix_isatty') && @posix_isatty($stream);
}
}
\ No newline at end of file
<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* $Id: Formatter.php 2702 2007-10-03 21:43:22Z Jonathan.Wage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Cli_Formatter provides methods to format text to be displayed on a console.
*
* @package Doctrine
* @subpackage Cli
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: Doctrine_Cli_Formatter.class.php 5250 2007-09-24 08:11:50Z fabien $
*/
class Doctrine_Cli_Formatter
{
protected
$size = 65;
function __construct($maxLineSize = 65)
{
$this->size = $maxLineSize;
}
/**
* Formats a text according to the given parameters.
*
* @param string The test to style
* @param mixed An array of parameters
* @param stream A stream (default to STDOUT)
*
* @return string The formatted text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
return $text;
}
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
return sprintf(">> %-$9s %s", $section, $this->excerpt($text, $size));
}
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if (!$size)
{
$size = $this->size;
}
if (strlen($text) < $size)
{
return $text;
}
$subsize = floor(($size - 3) / 2);
return substr($text, 0, $subsize).'...'.substr($text, -$subsize);
}
/**
* Sets the maximum line size.
*
* @param integer The maximum line size for a message
*/
public function setMaxLineSize($size)
{
$this->size = $size;
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -326,7 +326,7 @@ class Doctrine_Migration ...@@ -326,7 +326,7 @@ class Doctrine_Migration
} }
if ($from == $to) { if ($from == $to) {
throw new Doctrine_Migration_Exception('Already at version: ' . $to); throw new Doctrine_Migration_Exception('Already at version # ' . $to);
} }
$direction = $from > $to ? 'down':'up'; $direction = $from > $to ? 'down':'up';
...@@ -343,7 +343,7 @@ class Doctrine_Migration ...@@ -343,7 +343,7 @@ class Doctrine_Migration
$this->setCurrentVersion($to); $this->setCurrentVersion($to);
return true; return $to;
} }
/** /**
......
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
*/ */
abstract class Doctrine_Task abstract class Doctrine_Task
{ {
public $taskName = null, public $dispatcher = null,
$taskName = null,
$description = null, $description = null,
$arguments = array(), $arguments = array(),
$requiredArguments = array(), $requiredArguments = array(),
...@@ -48,11 +49,22 @@ abstract class Doctrine_Task ...@@ -48,11 +49,22 @@ abstract class Doctrine_Task
* *
* @return void * @return void
*/ */
public function __construct() public function __construct($dispatcher = null)
{ {
$this->dispatcher = $dispatcher;
$this->taskName = str_replace('_', '-', Doctrine::tableize(str_replace('Doctrine_Task_', '', get_class($this)))); $this->taskName = str_replace('_', '-', Doctrine::tableize(str_replace('Doctrine_Task_', '', get_class($this))));
} }
public function notify($message)
{
if (is_object($message)) {
return $message->notify($message);
} else {
return $message;
}
}
/** /**
* execute * execute
* *
...@@ -76,7 +88,7 @@ abstract class Doctrine_Task ...@@ -76,7 +88,7 @@ abstract class Doctrine_Task
foreach ($requiredArguments as $arg) { foreach ($requiredArguments as $arg) {
if (!isset($this->arguments[$arg])) { if (!isset($this->arguments[$arg])) {
throw new Doctrine_Task_Exception('Required arguments missing. The follow arguments are required: ' . implode(', ', $requiredArguments)); return false;
} }
} }
......
...@@ -39,5 +39,7 @@ class Doctrine_Task_CreateTables extends Doctrine_Task ...@@ -39,5 +39,7 @@ class Doctrine_Task_CreateTables extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::createTablesFromModels($this->getArgument('models_path')); Doctrine::createTablesFromModels($this->getArgument('models_path'));
$this->dispatcher->notify('successfully created tables');
} }
} }
\ No newline at end of file
...@@ -39,5 +39,7 @@ class Doctrine_Task_DropDb extends Doctrine_Task ...@@ -39,5 +39,7 @@ class Doctrine_Task_DropDb extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::dropDatabases($this->getArgument('connection')); Doctrine::dropDatabases($this->getArgument('connection'));
$this->dispatcher->notify('Successfully dropped all databases');
} }
} }
\ No newline at end of file
...@@ -54,5 +54,7 @@ class Doctrine_Task_DumpData extends Doctrine_Task ...@@ -54,5 +54,7 @@ class Doctrine_Task_DumpData extends Doctrine_Task
} }
Doctrine::dumpData($path, $individualFiles); Doctrine::dumpData($path, $individualFiles);
$this->dispatcher->notify(sprintf('successfully dumped data to %s', $path));
} }
} }
\ No newline at end of file
...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateMigration extends Doctrine_Task ...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateMigration extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateMigrationClass($this->getArgument('class_name'), $this->getArgument('migrations_path')); Doctrine::generateMigrationClass($this->getArgument('class_name'), $this->getArgument('migrations_path'));
$this->dispatcher->notify(sprintf('successfully generated migration class: %s to %s', $this->getArgument('class_name'), $this->getArgument('migrations_path')));
} }
} }
\ No newline at end of file
...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateMigrationsFromDb extends Doctrine_Task ...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateMigrationsFromDb extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateMigrationsFromDb($this->getArgument('migrations_path')); Doctrine::generateMigrationsFromDb($this->getArgument('migrations_path'));
$this->dispatcher->notify('successfully generated migration classes from databases');
} }
} }
\ No newline at end of file
...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateMigrationsFromModels extends Doctrine_Task ...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateMigrationsFromModels extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateMigrationsFromModels($this->getArgument('migrations_path'), $this->getArgument('models_path')); Doctrine::generateMigrationsFromModels($this->getArgument('migrations_path'), $this->getArgument('models_path'));
$this->dispatcher->notify('successfully generated migrations from models');
} }
} }
\ No newline at end of file
...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateModelsFromDb extends Doctrine_Task ...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateModelsFromDb extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateModelsFromDb($this->getArgument('models_path'), (array) $this->getArgument('connection')); Doctrine::generateModelsFromDb($this->getArgument('models_path'), (array) $this->getArgument('connection'));
$this->dispatcher->notify('successfully generated models from databases');
} }
} }
\ No newline at end of file
...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateModelsFromYaml extends Doctrine_Task ...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateModelsFromYaml extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateModelsFromYaml($this->getArgument('yaml_schema_path'), $this->getArgument('models_path')); Doctrine::generateModelsFromYaml($this->getArgument('yaml_schema_path'), $this->getArgument('models_path'));
$this->dispatcher->notify('successfully generated models from yaml');
} }
} }
\ No newline at end of file
...@@ -50,5 +50,7 @@ class Doctrine_Task_GenerateSql extends Doctrine_Task ...@@ -50,5 +50,7 @@ class Doctrine_Task_GenerateSql extends Doctrine_Task
$sql = Doctrine::generateSqlFromModels($this->getArgument('models_path')); $sql = Doctrine::generateSqlFromModels($this->getArgument('models_path'));
file_put_contents($path, $sql); file_put_contents($path, $sql);
$this->dispatcher->notify('successfully generated sql for models');
} }
} }
\ No newline at end of file
...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateYamlFromDb extends Doctrine_Task ...@@ -39,5 +39,7 @@ class Doctrine_Task_GenerateYamlFromDb extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateYamlFromDb($this->getArgument('yaml_schema_path')); Doctrine::generateYamlFromDb($this->getArgument('yaml_schema_path'));
$this->dispatcher->notify('successfully generated yaml schema from databases');
} }
} }
\ No newline at end of file
...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateYamlFromModels extends Doctrine_Task ...@@ -40,5 +40,7 @@ class Doctrine_Task_GenerateYamlFromModels extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::generateYamlFromModels($this->getArgument('yaml_schema_path'), $this->getArgument('models_path')); Doctrine::generateYamlFromModels($this->getArgument('yaml_schema_path'), $this->getArgument('models_path'));
$this->dispatcher->notify('successfully generated yaml schema from models');
} }
} }
\ No newline at end of file
...@@ -41,5 +41,7 @@ class Doctrine_Task_LoadData extends Doctrine_Task ...@@ -41,5 +41,7 @@ class Doctrine_Task_LoadData extends Doctrine_Task
{ {
Doctrine::loadModels($this->getArgument('models_path')); Doctrine::loadModels($this->getArgument('models_path'));
Doctrine::loadData($this->getArgument('data_fixtures_path')); Doctrine::loadData($this->getArgument('data_fixtures_path'));
$this->dispatcher->notify('data was successfully loaded');
} }
} }
\ No newline at end of file
...@@ -41,5 +41,7 @@ class Doctrine_Task_LoadDummyData extends Doctrine_Task ...@@ -41,5 +41,7 @@ class Doctrine_Task_LoadDummyData extends Doctrine_Task
{ {
Doctrine::loadModels($this->getArgument('models_path')); Doctrine::loadModels($this->getArgument('models_path'));
Doctrine::loadDummyData($this->getArgument('append') ? true:false, $this->getArgument('num') ? $this->getArgument('num'):5); Doctrine::loadDummyData($this->getArgument('append') ? true:false, $this->getArgument('num') ? $this->getArgument('num'):5);
$this->dispatcher->notify('dummy data successfully loaded');
} }
} }
\ No newline at end of file
...@@ -38,6 +38,8 @@ class Doctrine_Task_Migrate extends Doctrine_Task ...@@ -38,6 +38,8 @@ class Doctrine_Task_Migrate extends Doctrine_Task
public function execute() public function execute()
{ {
Doctrine::migrate($this->getArgument('migrations_path'), $this->getArgument('version')); $version = Doctrine::migrate($this->getArgument('migrations_path'), $this->getArgument('version'));
$this->dispatcher->notify('migrated to version # ' . $version);
} }
} }
\ No newline at end of file
...@@ -10,4 +10,4 @@ $config = array('data_fixtures_path' => DATA_FIXTURES_PATH, ...@@ -10,4 +10,4 @@ $config = array('data_fixtures_path' => DATA_FIXTURES_PATH,
'yaml_schema_path' => YAML_SCHEMA_PATH); 'yaml_schema_path' => YAML_SCHEMA_PATH);
$cli = new Doctrine_Cli($config); $cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']); $cli->run($_SERVER['argv']);
\ No newline at end of file
---
Adult:
Adult_1:
name: Parent 1
Contact: Contact_1
\ No newline at end of file
---
Car:
Car_1:
name: Chevorlet Trailblazer
Car_2:
name: Chevorlet Blazer
Car_3:
name: Buick
\ No newline at end of file
---
Child:
Child_1:
name: Child 1
Adult: Adult_1
\ No newline at end of file
---
Contact:
Contact_1:
name: jonathan h. wage
User:
User_1:
username: jonwage
Contact: Contact_1
---
Dog:
Dog_1:
name: Sam
User: User_1
Dog_2:
name: Dixie
User: User_2
Dog_3:
name: Chief
User: User_3
\ No newline at end of file
---
SelfReference:
SelfReference_1:
User1: User_1
User2: User_2
name: Self Reference 1
SelfReference1: SelfReference_2
SelfReference2: SelfReference_3
SelfReference_2:
User1: User_2
User2: User_1
name: Self Reference 2
SelfReference1: SelfReference_1
SelfReference2: SelfReference_1
SelfReference_3:
User1: User_2
User2: User_1
name: Self Reference 3
SelfReference1: SelfReference_3
SelfReference2: SelfReference_3
\ No newline at end of file
---
UserCar:
UserCar_1:
User: User_1
Car: Car_1
UserCar_2:
User: User_2
Car: Car_2
UserCar_3:
User: User_3
Car: Car_3
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddAdult extends Doctrine_Migration
{
public function up()
{
$this->createTable('adult', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
'contact_id' =>
array (
'type' => 'integer',
'length' => 11,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('adult');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddCar extends Doctrine_Migration
{
public function up()
{
$this->createTable('car', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('car');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddChild extends Doctrine_Migration
{
public function up()
{
$this->createTable('child', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
'adult_id' =>
array (
'type' => 'integer',
'length' => 11,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('child');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddContact extends Doctrine_Migration
{
public function up()
{
$this->createTable('contact', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('contact');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddDog extends Doctrine_Migration
{
public function up()
{
$this->createTable('dog', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
'user_id' =>
array (
'type' => 'integer',
'length' => 11,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('dog');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddEntity extends Doctrine_Migration
{
public function up()
{
$this->createTable('entity', array (
'id' =>
array (
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('entity');
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class AddGroups extends Doctrine_Migration
{
public function up()
{
$this->createTable('groups', array (
'id' =>
array (
'notnull' => true,
'primary' => true,
'autoincrement' => true,
'type' => 'integer',
'length' => 11,
),
'name' =>
array (
'type' => 'string',
'length' => 255,
),
), array (
'indexes' =>
array (
),
'primary' =>
array (
0 => 'id',
),
));
}
public function down()
{
$this->dropTable('groups');
}
}
\ No newline at end of file
<?php
require_once('generated/BaseAdult.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Adult extends BaseAdult
{
}
\ No newline at end of file
<?php
require_once('generated/BaseCar.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Car extends BaseCar
{
}
\ No newline at end of file
<?php
require_once('generated/BaseChild.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Child extends BaseChild
{
}
\ No newline at end of file
<?php
require_once('generated/BaseContact.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Contact extends BaseContact
{
}
\ No newline at end of file
<?php
require_once('generated/BaseDog.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Dog extends BaseDog
{
}
\ No newline at end of file
<?php
require_once('generated/BaseEntity.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Entity extends BaseEntity
{
}
\ No newline at end of file
<?php
require_once('generated/BaseGroup.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Group extends BaseGroup
{
}
\ No newline at end of file
<?php
require_once('generated/BaseSelfReference.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class SelfReference extends BaseSelfReference
{
}
\ No newline at end of file
<?php
require_once('generated/BaseUser.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class User extends BaseUser
{
}
\ No newline at end of file
<?php
require_once('generated/BaseUserCar.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class UserCar extends BaseUserCar
{
}
\ No newline at end of file
<?php
require_once('generated/BaseUserGroup.class.php');
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class UserGroup extends BaseUserGroup
{
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseAdult extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('adult');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
$this->hasColumn('contact_id', 'integer', 11);
}
public function setUp()
{
$this->hasOne('Contact', array('local' => 'contact_id',
'foreign' => 'id'));
$this->hasMany('Child as Children', array('local' => 'id',
'foreign' => 'adult_id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseCar extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('car');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
}
public function setUp()
{
$this->hasMany('User as Users', array('refClass' => 'UserCar',
'local' => 'car_id',
'foreign' => 'user_id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseChild extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('child');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
$this->hasColumn('adult_id', 'integer', 11);
}
public function setUp()
{
$this->hasOne('Adult', array('local' => 'adult_id',
'foreign' => 'id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseContact extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('contact');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
}
public function setUp()
{
$this->hasOne('Adult', array('local' => 'id',
'foreign' => 'contact_id'));
$this->hasOne('User', array('local' => 'id',
'foreign' => 'contact_id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseDog extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('dog');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
$this->hasColumn('user_id', 'integer', 11);
}
public function setUp()
{
$this->hasOne('User', array('local' => 'user_id',
'foreign' => 'id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseEntity extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('entity');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseGroup extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('groups');
$this->hasColumn('id', 'integer', 11, array('notnull' => true,
'primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
}
public function setUp()
{
$this->hasMany('User as Users', array('refClass' => 'UserGroup',
'local' => 'group_id',
'foreign' => 'user_id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseSelfReference extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('self_reference');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('name', 'string', 255);
$this->hasColumn('user_id1', 'integer', 11);
$this->hasColumn('user_id2', 'integer', 11);
$this->hasColumn('parent_self_reference_id', 'integer', 11);
$this->hasColumn('parent_self_reference_id2', 'integer', 11);
}
public function setUp()
{
$this->hasOne('User as User1', array('local' => 'user_id1',
'foreign' => 'id'));
$this->hasOne('User as User2', array('local' => 'user_id2',
'foreign' => 'id'));
$this->hasOne('SelfReference as SelfReference1', array('local' => 'parent_self_reference_id',
'foreign' => 'id'));
$this->hasOne('SelfReference as SelfReference2', array('local' => 'parent_self_reference_id2',
'foreign' => 'id'));
$this->hasMany('SelfReference as SelfReferences1', array('local' => 'id',
'foreign' => 'parent_self_reference_id'));
$this->hasMany('SelfReference as SelfReferences2', array('local' => 'id',
'foreign' => 'parent_self_reference_id2'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseUser extends Entity
{
public function setTableDefinition()
{
$this->setTableName('user');
$this->hasColumn('id', 'integer', 11, array('primary' => true,
'autoincrement' => true));
$this->hasColumn('username', 'string', 255);
$this->hasColumn('hair_color', 'string', 255);
$this->hasColumn('contact_id', 'integer', 11);
$this->index('name_x', array('fields' => array('username' => array( 'sorting' => 'ASC', 'length' => '11', 'primary' => true, ), ), 'type' => 'unique'));
}
public function setUp()
{
$this->hasOne('Contact', array('local' => 'contact_id',
'foreign' => 'id'));
$this->hasMany('Car as Cars', array('refClass' => 'UserCar',
'local' => 'user_id',
'foreign' => 'car_id'));
$this->hasMany('Group as Groups', array('refClass' => 'UserGroup',
'local' => 'user_id',
'foreign' => 'group_id'));
$this->hasOne('Dog', array('local' => 'id',
'foreign' => 'user_id'));
$this->hasMany('SelfReference as SelfReference1', array('local' => 'id',
'foreign' => 'user_id1'));
$this->hasMany('SelfReference as SelfReference2', array('local' => 'id',
'foreign' => 'user_id2'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseUserCar extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('user_car');
$this->hasColumn('user_id', 'integer', 11, array('primary' => true));
$this->hasColumn('car_id', 'integer', 11, array('primary' => true));
}
public function setUp()
{
$this->hasOne('User', array('local' => 'user_id',
'foreign' => 'id'));
$this->hasOne('Car', array('local' => 'car_id',
'foreign' => 'id'));
}
}
\ No newline at end of file
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
abstract class BaseUserGroup extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('user_group');
$this->hasColumn('user_id', 'integer', 11, array('primary' => true));
$this->hasColumn('group_id', 'integer', 11, array('primary' => true));
}
public function setUp()
{
$this->hasOne('User', array('local' => 'user_id',
'foreign' => 'id'));
$this->hasOne('Group', array('local' => 'group_id',
'foreign' => 'id'));
}
}
\ No newline at end of file
---
Adult:
fields:
id:
type: integer
size: 11
primary: true
autoincrement: true
name:
type: string
size: 255
contact_id:
type: integer
size: 11
relations:
Contact:
foreignType: one
\ No newline at end of file
---
Car:
columns:
id:
type: integer
length: 11
primary: true
autoincrement: true
name:
type: string
length: 255
relations:
Users:
class: User
refClass: UserCar
\ No newline at end of file
---
Child:
fields:
id:
type: integer
size: 11
primary: true
autoincrement: true
name:
type: string
size: 255
adult_id:
type: integer
size: 11
relations:
Adult:
foreignAlias: Children
\ No newline at end of file
---
Contact:
columns:
id:
type: integer
length: 11
primary: true
autoincrement: true
name:
type: string
length: 255
\ No newline at end of file
---
Dog:
columns:
id:
type: integer
length: 11
primary: true
autoincrement: true
name:
type: string
length: 255
user_id:
type: integer
length: 11
relations:
User:
foreignType: one
\ No newline at end of file
---
Entity:
columns:
id:
type: integer
size: 11
primary: true
autoincrement: true
\ No newline at end of file
---
Group:
tableName: groups
columns:
id:
notnull: true
primary: true
autoincrement: true
type: integer
length: 11
name: id
name:
type: string
length: 255
relations:
Users:
class: User
refClass: UserGroup
---
SelfReference:
fields:
id:
type: integer
length: 11
primary: true
autoincrement: true
name:
type: string
length: 255
user_id1:
type: integer
length: 11
user_id2:
type: integer
length: 11
parent_self_reference_id:
type: integer
length: 11
parent_self_reference_id2:
type: integer
length: 11
relations:
User1:
class: User
local: user_id1
foreignAlias: SelfReference1
User2:
class: User
local: user_id2
foreignAlias: SelfReference2
SelfReference1:
class: SelfReference
local: parent_self_reference_id
foreignAlias: SelfReferences1
SelfReference2:
class: SelfReference
local: parent_self_reference_id2
foreignAlias: SelfReferences2
---
User:
inheritance:
extends: Entity
fields:
id:
type: integer
size: 11
primary: true
autoincrement: true
username:
type: string
length: 255
hair_color:
type: string
length: 255
contact_id:
type: integer
length: 11
relations:
Contact:
local: contact_id
foreign: id
foreignType: one
Cars:
class: Car
refClass: UserCar
Groups:
class: Group
refClass: UserGroup
indexes:
name_x:
columns:
username:
sorting: ASC
length: 11
primary: true
type: unique
\ No newline at end of file
---
UserCar:
columns:
user_id:
type: integer
length: 11
primary: true
car_id:
type: integer
length: 11
primary: true
relations:
User: -
Car: -
\ No newline at end of file
---
UserGroup:
columns:
user_id:
type: integer
length: 11
primary: true
group_id:
type: integer
length: 11
primary: true
relations:
User: -
Group: -
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