Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
 * Creates database for current model.
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: sfDoctrineBuildDbTask.class.php 24341 2009-11-24 15:01:58Z Kris.Wallsmith $
22
 */
23
class sfDoctrineBuildDbTask extends sfDoctrineBaseTask
24
{
25
  /**
26
   * @see sfTask
27
   */
28
  protected function configure()
29
  {
30
    $this->addArguments(array(
31
      new sfCommandArgument('database', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'A specific database'),
32
    ));
33
 
34
    $this->addOptions(array(
35
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
36
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
37
    ));
38
 
39
    $this->aliases = array('doctrine:create-db');
40
    $this->namespace = 'doctrine';
41
    $this->name = 'build-db';
42
    $this->briefDescription = 'Creates database for current model';
43
 
44
    $this->detailedDescription = <<<EOF
45
The [doctrine:build-db|INFO] task creates one or more databases based on
46
configuration in [config/databases.yml|COMMENT]:
47
 
48
  [./symfony doctrine:build-db|INFO]
49
 
50
You can specify what databases to create by providing their names:
51
 
52
  [./symfony doctrine:build-db slave1 slave2|INFO]
53
EOF;
54
  }
55
 
56
  /**
57
   * @see sfTask
58
   */
59
  protected function execute($arguments = array(), $options = array())
60
  {
61
    $databaseManager = new sfDatabaseManager($this->configuration);
62
    $databases = $this->getDoctrineDatabases($databaseManager, count($arguments['database']) ? $arguments['database'] : null);
63
 
64
    $environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all';
65
 
66
    foreach ($databases as $name => $database)
67
    {
68
      $this->logSection('doctrine', sprintf('Creating "%s" environment "%s" database', $environment, $name));
69
      try
70
      {
71
        $database->getDoctrineConnection()->createDatabase();
72
      }
73
      catch (Exception $e)
74
      {
75
        $this->logSection('doctrine', $e->getMessage(), null, 'ERROR');
76
      }
77
    }
78
  }
79
}