Development

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

You must first sign up to be able to contribute.

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

Revision 20545, 3.2 kB (checked in by fabien, 5 years ago)

[1.2, 1.3] fixed linked data when using multiple dirs in propel:data-load task (closes #6877)

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