Development

/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelDataDumpTask.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelDataDumpTask.class.php

Revision 23922, 3.3 kB (checked in by fabien, 5 years ago)

[1.4] removed deprecated stuff

  • Property svn:mergeinfo set to
  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php');
12
13 /**
14  * Dumps data to the fixtures directory.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelDataDumpTask extends sfPropelBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addArguments(array(
29       new sfCommandArgument('target', sfCommandArgument::OPTIONAL, 'The target filename'),
30     ));
31
32     $this->addOptions(array(
33       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
34       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'cli'),
35       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
36       new sfCommandOption('classes', null, sfCommandOption::PARAMETER_REQUIRED, 'The class names to dump (separated by a colon)', null),
37     ));
38
39     $this->namespace = 'propel';
40     $this->name = 'data-dump';
41     $this->briefDescription = 'Dumps data to the fixtures directory';
42
43     $this->detailedDescription = <<<EOF
44 The [propel:data-dump|INFO] task dumps database data:
45
46   [./symfony propel:data-dump > data/fixtures/dump.yml|INFO]
47
48 By default, the task outputs the data to the standard output,
49 but you can also pass a filename as a second argument:
50
51   [./symfony propel:data-dump dump.yml|INFO]
52
53 The task will dump data in [data/fixtures/%target%|COMMENT]
54 (data/fixtures/dump.yml in the example).
55
56 The dump file is in the YML format and can be re-imported by using
57 the [propel:data-load|INFO] task.
58
59 By default, the task use the [propel|COMMENT] connection as defined in [config/databases.yml|COMMENT].
60 You can use another connection by using the [connection|COMMENT] option:
61
62   [./symfony propel:data-dump --connection="name"|INFO]
63
64 If you only want to dump some classes, use the [classes|COMMENT] option:
65
66   [./symfony propel:data-dump --classes="Article,Category"|INFO]
67
68 If you want to use a specific database configuration from an application, you can use
69 the [application|COMMENT] option:
70
71   [./symfony propel:data-dump --application=frontend|INFO]
72 EOF;
73   }
74
75   /**
76    * @see sfTask
77    */
78   protected function execute($arguments = array(), $options = array())
79   {
80     $databaseManager = new sfDatabaseManager($this->configuration);
81
82     $filename = $arguments['target'];
83     if (null !== $filename && !sfToolkit::isPathAbsolute($filename))
84     {
85       $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures';
86       $this->getFilesystem()->mkdirs($dir);
87       $filename = $dir.DIRECTORY_SEPARATOR.$filename;
88
89       $this->logSection('propel', sprintf('dumping data to "%s"', $filename));
90     }
91
92     $data = new sfPropelData();
93
94     $classes = null === $options['classes'] ? 'all' : explode(',', $options['classes']);
95
96     if (null !== $filename)
97     {
98       $data->dumpData($filename, $classes, $options['connection']);
99     }
100     else
101     {
102       fwrite(STDOUT, sfYaml::dump($data->getData($classes, $options['connection']), 3));
103     }
104   }
105 }
106
Note: See TracBrowser for help on using the browser.