Development

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

You must first sign up to be able to contribute.

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

Revision 14213, 2.9 kB (checked in by Jonathan.Wage, 6 years ago)

[1.2] sfDoctrinePlugin: fixes issue with application option in tasks (closes #5238)

  • Property svn:keywords set to Id Date Author Revision HeadURL
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 data from 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$
22  */
23 class sfDoctrineLoadDataTask extends sfDoctrineBaseTask
24 {
25   /**
26    * @see sfTask
27    */
28   protected function configure()
29   {
30     $this->addOptions(array(
31       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
32       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
33       new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'),
34       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
35       new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'The directories to look for fixtures'),
36     ));
37
38     $this->aliases = array('doctrine-load-data');
39     $this->namespace = 'doctrine';
40     $this->name = 'data-load';
41     $this->briefDescription = 'Loads data from fixtures directory';
42
43     $this->detailedDescription = <<<EOF
44 The [doctrine:data-load|INFO] task loads data fixtures into the database:
45
46   [./symfony doctrine:data-load frontend|INFO]
47
48 The task loads data from all the files found in [data/fixtures/|COMMENT].
49
50 If you want to load data from other directories, you can use
51 the [--dir|COMMENT] option:
52
53   [./symfony doctrine:data-load --dir="data/fixtures" --dir="data/data" frontend|INFO]
54
55 If you don't want the task to remove existing data in the database,
56 use the [--append|COMMENT] option:
57
58   [./symfony doctrine:data-load --append frontend|INFO]
59 EOF;
60   }
61
62   /**
63    * @see sfTask
64    */
65   protected function execute($arguments = array(), $options = array())
66   {
67     $databaseManager = new sfDatabaseManager($this->configuration);
68
69     $arguments = array();
70     if (isset($options['append']) && $options['append'])
71     {
72       $arguments['append'] = $options['append'];
73     }
74
75     if (isset($options['dir']) && $options['dir'])
76     {
77       $arguments['data_fixtures_path'] = $options['dir'];
78       foreach ($options['dir'] as $dir)
79       {
80         $this->logSection('doctrine', sprintf('loading data fixtures from "%s"', $dir));
81       }
82     } else {
83       $config = $this->getCliConfig();
84       $this->logSection('doctrine', sprintf('loading data fixtures from "%s"', $config['data_fixtures_path'][0]));
85     }
86
87     $this->callDoctrineCli('load-data', $arguments);
88   }
89 }
Note: See TracBrowser for help on using the browser.