Development

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

You must first sign up to be able to contribute.

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

Revision 18726, 3.2 kB (checked in by fabien, 5 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 command
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('application', sfCommandArgument::REQUIRED, 'The application name'),
30       new sfCommandArgument('target', sfCommandArgument::OPTIONAL, 'The target filename'),
31     ));
32
33     $this->addOptions(array(
34       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'dev'),
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 frontend > 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 frontend 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" frontend|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" frontend|INFO]
68 EOF;
69   }
70
71   /**
72    * @see sfTask
73    */
74   protected function execute($arguments = array(), $options = array())
75   {
76     $databaseManager = new sfDatabaseManager($this->configuration);
77
78     $filename = $arguments['target'];
79     if (!is_null($filename) && !sfToolkit::isPathAbsolute($filename))
80     {
81       $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures';
82       $this->getFilesystem()->mkdirs($dir);
83       $filename = $dir.DIRECTORY_SEPARATOR.$filename;
84
85       $this->logSection('propel', sprintf('dumping data to "%s"', $filename));
86     }
87
88     $data = new sfPropelData();
89
90     $classes = is_null($options['classes']) ? 'all' : explode(',', $options['classes']);
91
92     if (!is_null($filename))
93     {
94       $data->dumpData($filename, $classes, $options['connection']);
95     }
96     else
97     {
98       fwrite(STDOUT, sfYaml::dump($data->getData($classes, $options['connection']), 3));
99     }
100   }
101 }
102
Note: See TracBrowser for help on using the browser.