Development

/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelDumpDataTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelDumpDataTask.class.php

Revision 18726, 3.4 kB (checked in by fabien, 6 years ago)

[1.1, 1.2, 1.3] fixed typo (closes #6538)

  • 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 sfPropelDumpDataTask 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->aliases = array('propel-dump-data');
40     $this->namespace = 'propel';
41     $this->name = 'data-dump';
42     $this->briefDescription = 'Dumps data to the fixtures directory';
43
44     $this->detailedDescription = <<<EOF
45 The [propel:data-dump|INFO] task dumps database data:
46
47   [./symfony propel:data-dump > data/fixtures/dump.yml|INFO]
48
49 By default, the task outputs the data to the standard output,
50 but you can also pass a filename as a second argument:
51
52   [./symfony propel:data-dump dump.yml|INFO]
53
54 The task will dump data in [data/fixtures/%target%|COMMENT]
55 (data/fixtures/dump.yml in the example).
56
57 The dump file is in the YML format and can be re-imported by using
58 the [propel:data-load|INFO] task.
59
60 By default, the task use the [propel|COMMENT] connection as defined in [config/databases.yml|COMMENT].
61 You can use another connection by using the [connection|COMMENT] option:
62
63   [./symfony propel:data-dump --connection="name"|INFO]
64
65 If you only want to dump some classes, use the [classes|COMMENT] option:
66
67   [./symfony propel:data-dump --classes="Article,Category"|INFO]
68
69 If you want to use a specific database configuration from an application, you can use
70 the [application|COMMENT] option:
71
72   [./symfony propel:data-dump --application=frontend|INFO]
73 EOF;
74   }
75
76   /**
77    * @see sfTask
78    */
79   protected function execute($arguments = array(), $options = array())
80   {
81     $databaseManager = new sfDatabaseManager($this->configuration);
82
83     $filename = $arguments['target'];
84     if (!is_null($filename) && !sfToolkit::isPathAbsolute($filename))
85     {
86       $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures';
87       $this->getFilesystem()->mkdirs($dir);
88       $filename = $dir.DIRECTORY_SEPARATOR.$filename;
89
90       $this->logSection('propel', sprintf('dumping data to "%s"', $filename));
91     }
92
93     $data = new sfPropelData();
94
95     $classes = is_null($options['classes']) ? 'all' : explode(',', $options['classes']);
96
97     if (!is_null($filename))
98     {
99       $data->dumpData($filename, $classes, $options['connection']);
100     }
101     else
102     {
103       fwrite(STDOUT, sfYaml::dump($data->getData($classes, $options['connection']), 3));
104     }
105   }
106 }
107
Note: See TracBrowser for help on using the browser.