Created
July 5, 2012 02:21
-
-
Save redthor/3050655 to your computer and use it in GitHub Desktop.
To change symfony 1.4 and doctrine to support dumping individual tables and selecting which models will be dumped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd $SF_HOME/lib/vendor/symfony/lib/plugins | |
$ svn status |grep '^M' | |
M sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php | |
M sfDoctrinePlugin/lib/task/sfDoctrineDataDumpTask.class.php | |
M sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Cli.php | |
M sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Task/DumpData.php | |
M sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php | |
$ for a in `svn status |grep '^M' |awk '{print $2}'`; | |
> do | |
> svn diff $a | |
> done | |
Index: sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php | |
=================================================================== | |
--- sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php (revision 33482) | |
+++ sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php (working copy) | |
@@ -102,6 +102,8 @@ | |
'migrations_path' => sfConfig::get('sf_lib_dir').'/migration/doctrine', | |
'sql_path' => sfConfig::get('sf_data_dir').'/sql', | |
'yaml_schema_path' => sfConfig::get('sf_config_dir').'/doctrine', | |
+ 'individualFiles' => true, | |
+ 'classes' => array(), | |
); | |
// filter config through the dispatcher | |
Index: sfDoctrinePlugin/lib/task/sfDoctrineDataDumpTask.class.php | |
=================================================================== | |
--- sfDoctrinePlugin/lib/task/sfDoctrineDataDumpTask.class.php (revision 33482) | |
+++ sfDoctrinePlugin/lib/task/sfDoctrineDataDumpTask.class.php (working copy) | |
@@ -34,6 +34,20 @@ | |
$this->addOptions(array( | |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true), | |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), | |
+ new sfCommandOption( | |
+ 'individualFiles', | |
+ null, | |
+ sfCommandOption::PARAMETER_REQUIRED, | |
+ 'Whether or not to export individual Yml files', | |
+ true | |
+ ), | |
+ new sfCommandOption( | |
+ 'classes', | |
+ null, | |
+ sfCommandOption::PARAMETER_REQUIRED, | |
+ 'The class names to dump (separated by a comma)', | |
+ null | |
+ ), | |
)); | |
$this->namespace = 'doctrine'; | |
@@ -71,6 +85,14 @@ | |
$this->getFilesystem()->mkdirs($args['data_fixtures_path']); | |
} | |
+ if (isset($options['classes'])) { | |
+ $args['classes'] = explode(',', $options['classes']); | |
+ } | |
+ | |
+ if (isset($options['individualFiles'])) { | |
+ $args['individualFiles'] = $options['individualFiles']; | |
+ } | |
+ | |
if ($arguments['target']) | |
{ | |
$filename = $arguments['target']; | |
@@ -88,4 +110,4 @@ | |
$this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $args['data_fixtures_path'])); | |
$this->callDoctrineCli('dump-data', $args); | |
} | |
-} | |
\ No newline at end of file | |
+} | |
Index: sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Cli.php | |
=================================================================== | |
--- sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Cli.php (revision 3) | |
+++ sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Cli.php (working copy) | |
@@ -676,4 +676,4 @@ | |
{ | |
return $this->createOldStyleTaskList($this->getRegisteredTasks()); | |
} | |
-} | |
\ No newline at end of file | |
+} | |
Index: sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Task/DumpData.php | |
=================================================================== | |
--- sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Task/DumpData.php (revision 3) | |
+++ sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Task/DumpData.php (working copy) | |
@@ -35,16 +35,40 @@ | |
public $description = 'Dump data to a yaml data fixture file.', | |
$requiredArguments = array('data_fixtures_path' => 'Specify path to write the yaml data fixtures file to.', | |
'models_path' => 'Specify path to your Doctrine_Record definitions.'), | |
- $optionalArguments = array(); | |
+ $optionalArguments = array('classes' => 'Optionally specify just the classes you want to export.', | |
+ 'individualFiles' => 'Optionally specify individual files instead of one big file'); | |
public function execute() | |
{ | |
$models = Doctrine_Core::loadModels($this->getArgument('models_path')); | |
+ // Get the classes the user wants to export | |
+ if ($classes = $this->getArgument('classes')) { | |
+ if (!is_array($classes)) { | |
+ throw new Doctrine_Task_Exception( | |
+ 'classes argument expecting an array: ' | |
+ . var_export(array('MyModel', 'AnotherModel'), true) | |
+ ); | |
+ } | |
+ | |
+ $models = array_filter( | |
+ $models, | |
+ function($value) use ($classes) { | |
+ return in_array($value, $classes); | |
+ } | |
+ ); | |
+ } | |
+ | |
if (empty($models)) { | |
throw new Doctrine_Task_Exception('No models were loaded'); | |
} | |
+ $individualFiles = $this->getArgument('individualFiles'); | |
+ | |
+ if (!is_bool($individualFiles)) { | |
+ $individualFiles = false; | |
+ } | |
+ | |
$path = $this->getArgument('data_fixtures_path'); | |
if (is_array($path) && count($path) > 0) { | |
@@ -52,11 +76,11 @@ | |
} | |
if ( ! empty($path)) { | |
- Doctrine_Core::dumpData($path); | |
+ Doctrine_Core::dumpData($path, $models, $individualFiles); | |
$this->notify(sprintf('Dumped data successfully to: %s', $path)); | |
} else { | |
throw new Doctrine_Task_Exception('Unable to find data fixtures path.'); | |
} | |
} | |
-} | |
\ No newline at end of file | |
+} | |
Index: sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php | |
=================================================================== | |
--- sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php (revision 3) | |
+++ sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php (working copy) | |
@@ -984,11 +984,11 @@ | |
* @param string $individualFiles Whether or not to dump data to individual fixtures files | |
* @return void | |
*/ | |
- public static function dumpData($yamlPath, $individualFiles = false) | |
+ public static function dumpData($yamlPath, $classes, $individualFiles = false) | |
{ | |
$data = new Doctrine_Data(); | |
- return $data->exportData($yamlPath, 'yml', array(), $individualFiles); | |
+ return $data->exportData($yamlPath, 'yml', $classes, $individualFiles); | |
} | |
/** | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great job! Saved me big hassle.