| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
* (c) Jonathan H. Wage <jonwage@gmail.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php');
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* Dumps data to the fixtures directory.
|
|
|
16 |
*
|
|
|
17 |
* @package symfony
|
|
|
18 |
* @subpackage doctrine
|
|
|
19 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
20 |
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
21 |
* @version SVN: $Id: sfDoctrineDataDumpTask.class.php 23922 2009-11-14 14:58:38Z fabien $
|
|
|
22 |
*/
|
|
|
23 |
class sfDoctrineDataDumpTask extends sfDoctrineBaseTask
|
|
|
24 |
{
|
|
|
25 |
/**
|
|
|
26 |
* @see sfTask
|
|
|
27 |
*/
|
|
|
28 |
protected function configure()
|
|
|
29 |
{
|
|
|
30 |
$this->addArguments(array(
|
|
|
31 |
new sfCommandArgument('target', sfCommandArgument::OPTIONAL, 'The target filename'),
|
|
|
32 |
));
|
|
|
33 |
|
|
|
34 |
$this->addOptions(array(
|
|
|
35 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
|
|
|
36 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
|
|
|
37 |
));
|
|
|
38 |
|
|
|
39 |
$this->namespace = 'doctrine';
|
|
|
40 |
$this->name = 'data-dump';
|
|
|
41 |
$this->briefDescription = 'Dumps data to the fixtures directory';
|
|
|
42 |
|
|
|
43 |
$this->detailedDescription = <<<EOF
|
|
|
44 |
The [doctrine:data-dump|INFO] task dumps database data:
|
|
|
45 |
|
|
|
46 |
[./symfony doctrine:data-dump|INFO]
|
|
|
47 |
|
|
|
48 |
The task dumps the database data in [data/fixtures/%target%|COMMENT].
|
|
|
49 |
|
|
|
50 |
The dump file is in the YML format and can be reimported by using
|
|
|
51 |
the [doctrine:data-load|INFO] task.
|
|
|
52 |
|
|
|
53 |
[./symfony doctrine:data-load|INFO]
|
|
|
54 |
EOF;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* @see sfTask
|
|
|
59 |
*/
|
|
|
60 |
protected function execute($arguments = array(), $options = array())
|
|
|
61 |
{
|
|
|
62 |
$databaseManager = new sfDatabaseManager($this->configuration);
|
|
|
63 |
$config = $this->getCliConfig();
|
|
|
64 |
|
|
|
65 |
$args = array(
|
|
|
66 |
'data_fixtures_path' => $config['data_fixtures_path'][0],
|
|
|
67 |
);
|
|
|
68 |
|
|
|
69 |
if (!is_dir($args['data_fixtures_path']))
|
|
|
70 |
{
|
|
|
71 |
$this->getFilesystem()->mkdirs($args['data_fixtures_path']);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
if ($arguments['target'])
|
|
|
75 |
{
|
|
|
76 |
$filename = $arguments['target'];
|
|
|
77 |
|
|
|
78 |
if (!sfToolkit::isPathAbsolute($filename))
|
|
|
79 |
{
|
|
|
80 |
$filename = $args['data_fixtures_path'].'/'.$filename;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
$this->getFilesystem()->mkdirs(dirname($filename));
|
|
|
84 |
|
|
|
85 |
$args['data_fixtures_path'] = $filename;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
$this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $args['data_fixtures_path']));
|
|
|
89 |
$this->callDoctrineCli('dump-data', $args);
|
|
|
90 |
}
|
|
|
91 |
}
|