Development

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

You must first sign up to be able to contribute.

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

Revision 22422, 3.2 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] changed doctrine and propel data-load tasks so directories or files are passed as arguments

  • 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->aliases = array('propel-load-data');
40     $this->namespace = 'propel';
41     $this->name = 'data-load';
42     $this->briefDescription = 'Loads YAML fixture data';
43
44     $this->detailedDescription = <<<EOF
45 The [propel:data-load|INFO] task loads data fixtures into the database:
46
47   [./symfony propel:data-load|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 specific files or directories, you can append
52 them as arguments:
53
54   [./symfony propel:data-load data/fixtures/dev data/fixtures/users.yml|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"|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|INFO]
65
66 If you want to use a specific database configuration from an application, you can use
67 the [application|COMMENT] option:
68
69   [./symfony propel:data-load --application=frontend|INFO]
70 EOF;
71   }
72
73   /**
74    * @see sfTask
75    */
76   protected function execute($arguments = array(), $options = array())
77   {
78     $databaseManager = new sfDatabaseManager($this->configuration);
79
80     if (count($arguments['dir_or_file']))
81     {
82       $fixturesDirs = $arguments['dir_or_file'];
83     }
84     else
85     {
86       $fixturesDirs = array_merge(array(sfConfig::get('sf_data_dir').'/fixtures'), $this->configuration->getPluginSubPaths('/data/fixtures'));
87     }
88
89     $data = new sfPropelData();
90     $data->setDeleteCurrentData(!$options['append']);
91
92     $dirs = array();
93     foreach ($fixturesDirs as $fixturesDir)
94     {
95       if (!is_readable($fixturesDir))
96       {
97         continue;
98       }
99
100       $this->logSection('propel', sprintf('load data from "%s"', $fixturesDir));
101       $dirs[] = $fixturesDir;
102     }
103
104     $data->loadData($dirs, $options['connection']);
105   }
106 }
107
Note: See TracBrowser for help on using the browser.