Development

/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelDataLoadTask.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelDataLoadTask.class.php

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

[1.4] removed deprecated stuff

  • 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 YAML fixture data.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelDataLoadTask extends sfPropelBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addArguments(array(
29       new sfCommandArgument('dir_or_file', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'Directory or file to load'),
30     ));
31
32     $this->addOptions(array(
33       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
34       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'cli'),
35       new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'),
36       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
37     ));
38
39     $this->namespace = 'propel';
40     $this->name = 'data-load';
41     $this->briefDescription = 'Loads YAML fixture data';
42
43     $this->detailedDescription = <<<EOF
44 The [propel:data-load|INFO] task loads data fixtures into the database:
45
46   [./symfony propel:data-load|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 specific files or directories, you can append
51 them as arguments:
52
53   [./symfony propel:data-load data/fixtures/dev data/fixtures/users.yml|INFO]
54
55 The task use the [propel|COMMENT] connection as defined in [config/databases.yml|COMMENT].
56 You can use another connection by using the [--connection|COMMENT] option:
57
58   [./symfony propel:data-load --connection="name"|INFO]
59
60 If you don't want the task to remove existing data in the database,
61 use the [--append|COMMENT] option:
62
63   [./symfony propel:data-load --append|INFO]
64
65 If you want to use a specific database configuration from an application, you can use
66 the [application|COMMENT] option:
67
68   [./symfony propel:data-load --application=frontend|INFO]
69 EOF;
70   }
71
72   /**
73    * @see sfTask
74    */
75   protected function execute($arguments = array(), $options = array())
76   {
77     $databaseManager = new sfDatabaseManager($this->configuration);
78
79     if (count($arguments['dir_or_file']))
80     {
81       $fixturesDirs = $arguments['dir_or_file'];
82     }
83     else
84     {
85       $fixturesDirs = array_merge(array(sfConfig::get('sf_data_dir').'/fixtures'), $this->configuration->getPluginSubPaths('/data/fixtures'));
86     }
87
88     $data = new sfPropelData();
89     $data->setDeleteCurrentData(!$options['append']);
90
91     $dirs = array();
92     foreach ($fixturesDirs as $fixturesDir)
93     {
94       if (!is_readable($fixturesDir))
95       {
96         continue;
97       }
98
99       $this->logSection('propel', sprintf('load data from "%s"', $fixturesDir));
100       $dirs[] = $fixturesDir;
101     }
102
103     $data->loadData($dirs, $options['connection']);
104   }
105 }
106
Note: See TracBrowser for help on using the browser.