Development

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

You must first sign up to be able to contribute.

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

Revision 23810, 2.7 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

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