Development

/branches/1.4/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDataLoadTask.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDataLoadTask.class.php

Revision 23922, 2.6 kB (checked in by fabien, 4 years ago)

[1.4] removed deprecated stuff

  • 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) 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  * Loads YAML fixture data.
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$
22  */
23 class sfDoctrineDataLoadTask extends sfDoctrineBaseTask
24 {
25   /**
26    * @see sfTask
27    */
28   protected function configure()
29   {
30     $this->addArguments(array(
31       new sfCommandArgument('dir_or_file', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'Directory or file to load'),
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       new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'),
38     ));
39
40     $this->namespace = 'doctrine';
41     $this->name = 'data-load';
42     $this->briefDescription = 'Loads YAML fixture data';
43
44     $this->detailedDescription = <<<EOF
45 The [doctrine:data-load|INFO] task loads data fixtures into the database:
46
47   [./symfony doctrine:data-load|INFO]
48
49 The task loads data from all the files found in [data/fixtures/|COMMENT].
50
51 If you want to load data from specific files or directories, you can append
52 them as arguments:
53
54   [./symfony doctrine:data-load data/fixtures/dev data/fixtures/users.yml|INFO]
55
56 If you don't want the task to remove existing data in the database,
57 use the [--append|COMMENT] option:
58
59   [./symfony doctrine:data-load --append|INFO]
60 EOF;
61   }
62
63   /**
64    * @see sfTask
65    */
66   protected function execute($arguments = array(), $options = array())
67   {
68     $databaseManager = new sfDatabaseManager($this->configuration);
69
70     if (!count($arguments['dir_or_file']))
71     {
72       // pull default from CLI config array
73       $config = $this->getCliConfig();
74       $arguments['dir_or_file'] = $config['data_fixtures_path'];
75     }
76
77     $doctrineArguments = array(
78       'data_fixtures_path' => $arguments['dir_or_file'],
79       'append'             => $options['append'],
80     );
81
82     foreach ($arguments['dir_or_file'] as $target)
83     {
84       $this->logSection('doctrine', sprintf('Loading data fixtures from "%s"', $target));
85     }
86
87     $this->callDoctrineCli('load-data', $doctrineArguments);
88   }
89 }
90
Note: See TracBrowser for help on using the browser.