Development

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

You must first sign up to be able to contribute.

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

Revision 12163, 2.2 kB (checked in by fabien, 6 years ago)

[1.2] fixed typo

  • 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  * Creates a schema.xml from an existing database.
15  *
16  * @package    symfony
17  * @subpackage command
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelBuildSchemaTask extends sfPropelBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addOptions(array(
29       new sfCommandOption('xml', null, sfCommandOption::PARAMETER_NONE, 'Creates an XML schema instead of a YML one'),
30     ));
31
32     $this->aliases = array('propel-build-schema');
33     $this->namespace = 'propel';
34     $this->name = 'build-schema';
35     $this->briefDescription = 'Creates a schema from an existing database';
36
37     $this->detailedDescription = <<<EOF
38 The [propel:build-schema|INFO] task introspects a database to create a schema:
39
40   [./symfony propel:build-schema|INFO]
41
42 By default, the task creates a YML file, but you can also create a XML file:
43
44   [./symfony --xml propel:build-schema|INFO]
45
46 The XML format contains more information than the YML one.
47 EOF;
48   }
49
50   /**
51    * @see sfTask
52    */
53   protected function execute($arguments = array(), $options = array())
54   {
55     $this->callPhing('creole', self::DO_NOT_CHECK_SCHEMA);
56
57     $xmlSchemaPath = sfConfig::get('sf_config_dir').'/schema.xml';
58     $ymlSchemaPath = sfConfig::get('sf_config_dir').'/schema.yml';
59
60     // Fix database name
61     if (file_exists($xmlSchemaPath))
62     {
63       $schema = file_get_contents($xmlSchemaPath);
64       $schema = preg_replace('/<database\s+name="[^"]+"/s', '<database name="propel" package="lib.model"', $schema);
65       file_put_contents($xmlSchemaPath, $schema);
66     }
67
68     if (!$options['xml'])
69     {
70       $this->schemaToYML(self::DO_NOT_CHECK_SCHEMA, '');
71       $this->cleanup();
72
73       if (file_exists($xmlSchemaPath))
74       {
75         unlink($xmlSchemaPath);
76       }
77     }
78     else
79     {
80       if (file_exists($ymlSchemaPath))
81       {
82         unlink($ymlSchemaPath);
83       }
84     }
85   }
86 }
87
Note: See TracBrowser for help on using the browser.