Development

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

You must first sign up to be able to contribute.

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

Revision 13139, 3.2 kB (checked in by Kris.Wallsmith, 6 years ago)

[1.1] Renamed task filenames to match classes.

  • 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  * Loads data from 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 sfPropelLoadDataTask 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     ));
31
32     $this->addOptions(array(
33       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
34       new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'),
35       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
36       new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'The directories to look for fixtures'),
37     ));
38
39     $this->aliases = array('propel-load-data');
40     $this->namespace = 'propel';
41     $this->name = 'data-load';
42     $this->briefDescription = 'Loads data from fixtures directory';
43
44     $this->detailedDescription = <<<EOF
45 The [propel:data-load|INFO] task loads data fixtures into the database:
46
47   [./symfony propel:data-load frontend|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 other directories, you can use
52 the [--dir|COMMENT] option:
53
54   [./symfony propel:data-load --dir="data/fixtures" --dir="data/data" frontend|INFO]
55
56 The task use the [propel|COMMENT] connection as defined in [config/databases.yml|COMMENT].
57 You can use another connection by using the [--connection|COMMENT] option:
58
59   [./symfony propel:data-load --connection="name" frontend|INFO]
60
61 If you don't want the task to remove existing data in the database,
62 use the [--append|COMMENT] option:
63
64   [./symfony propel:data-load --append frontend|INFO]
65 EOF;
66   }
67
68   /**
69    * @see sfTask
70    */
71   protected function execute($arguments = array(), $options = array())
72   {
73     $databaseManager = new sfDatabaseManager($this->configuration);
74     
75     if (count($options['dir']))
76     {
77       $fixturesDirs = $options['dir'];
78     }
79     else
80     {
81       if (!$pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/data'))
82       {
83         $pluginDirs = array();
84       }
85       $fixturesDirs = sfFinder::type('dir')->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir'))));
86     }
87
88     $data = new sfPropelData();
89     $data->setDeleteCurrentData(isset($options['append']) ? ($options['append'] ? false : true) : true);
90
91     foreach ($fixturesDirs as $fixturesDir)
92     {
93       if (!is_readable($fixturesDir))
94       {
95         continue;
96       }
97
98       $this->logSection('propel', sprintf('load data from "%s"', $fixturesDir));
99       $data->loadData($fixturesDir, $options['connection']);
100     }
101   }
102 }
103
Note: See TracBrowser for help on using the browser.