| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: GenerateMigrationsModels.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_GenerateMigrationsDiff
|
|
|
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_GenerateMigrationsDiff extends Doctrine_Task
|
|
|
34 |
{
|
|
|
35 |
public $description = 'Generate migration classes from a generated difference between your models and yaml schema files',
|
|
|
36 |
$requiredArguments = array('migrations_path' => 'Specify the path to your migration classes folder.',
|
|
|
37 |
'yaml_schema_path' => 'Specify the path to your yaml schema files folder.'),
|
|
|
38 |
$optionalArguments = array('models_path' => 'Specify the path to your doctrine models folder.');
|
|
|
39 |
|
|
|
40 |
public function execute()
|
|
|
41 |
{
|
|
|
42 |
$migrationsPath = $this->getArgument('migrations_path');
|
|
|
43 |
$modelsPath = $this->getArgument('models_path');
|
|
|
44 |
$yamlSchemaPath = $this->getArgument('yaml_schema_path');
|
|
|
45 |
|
|
|
46 |
$migration = new Doctrine_Migration($migrationsPath);
|
|
|
47 |
$diff = new Doctrine_Migration_Diff($modelsPath, $yamlSchemaPath, $migration);
|
|
|
48 |
$changes = $diff->generateMigrationClasses();
|
|
|
49 |
|
|
|
50 |
$numChanges = count($changes, true) - count($changes);
|
|
|
51 |
|
|
|
52 |
if ( ! $numChanges) {
|
|
|
53 |
throw new Doctrine_Task_Exception('Could not generate migration classes from difference');
|
|
|
54 |
} else {
|
|
|
55 |
$this->notify('Generated migration classes successfully from difference');
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|