| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: GenerateMigrationsDb.php 2761 2007-10-07 23:42:29Z zYne $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information, see
|
|
|
19 |
* <http://www.doctrine-project.org>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Doctrine_Task_GenerateMigrationsDb
|
|
|
24 |
*
|
|
|
25 |
* @package Doctrine
|
|
|
26 |
* @subpackage Task
|
|
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
28 |
* @link www.doctrine-project.org
|
|
|
29 |
* @since 1.0
|
|
|
30 |
* @version $Revision: 2761 $
|
|
|
31 |
* @author Jonathan H. Wage <jwage@mac.com>
|
|
|
32 |
*/
|
|
|
33 |
class Doctrine_Task_GenerateMigrationsDb extends Doctrine_Task
|
|
|
34 |
{
|
|
|
35 |
public $description = 'Generate migration classes for an existing database',
|
|
|
36 |
$requiredArguments = array('migrations_path' => 'Specify the complete path to your migration classes folder.'),
|
|
|
37 |
$optionalArguments = array();
|
|
|
38 |
|
|
|
39 |
public function execute()
|
|
|
40 |
{
|
|
|
41 |
try {
|
|
|
42 |
$migrationsPath = $this->getArgument('migrations_path');
|
|
|
43 |
$yamlSchemaPath = $this->getArgument('yaml_schema_path');
|
|
|
44 |
$migration = new Doctrine_Migration($migrationsPath);
|
|
|
45 |
$result1 = false;
|
|
|
46 |
if ( ! count($migration->getMigrationClasses())) {
|
|
|
47 |
$result1 = Doctrine_Core::generateMigrationsFromDb($migrationsPath);
|
|
|
48 |
}
|
|
|
49 |
$connections = array();
|
|
|
50 |
foreach (Doctrine_Manager::getInstance() as $connection) {
|
|
|
51 |
$connections[] = $connection->getName();
|
|
|
52 |
}
|
|
|
53 |
$changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath, $connections, $yamlSchemaPath);
|
|
|
54 |
$numChanges = count($changes, true) - count($changes);
|
|
|
55 |
$result = ($result1 || $numChanges) ? true:false;
|
|
|
56 |
} catch (Exception $e) {
|
|
|
57 |
$result = false;
|
|
|
58 |
}
|
|
|
59 |
if ( ! $result) {
|
|
|
60 |
throw new Doctrine_Task_Exception('Could not generate migration classes from database');
|
|
|
61 |
} else {
|
|
|
62 |
$this->notify('Generated migration classes successfully from database');
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
}
|