Exemple #1
0
 public function execute()
 {
     try {
         $migrationsPath = $this->getArgument('migrations_path');
         $yamlSchemaPath = $this->getArgument('yaml_schema_path');
         $migration = new Doctrine_Migration($migrationsPath);
         $result1 = false;
         if (!count($migration->getMigrationClasses())) {
             $result1 = Doctrine_Core::generateMigrationsFromDb($migrationsPath);
         }
         $connections = array();
         foreach (Doctrine_Manager::getInstance() as $connection) {
             $connections[] = $connection->getName();
         }
         $changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath, $connections, $yamlSchemaPath);
         $numChanges = count($changes, true) - count($changes);
         $result = $result1 || $numChanges ? true : false;
     } catch (Exception $e) {
         $result = false;
     }
     if (!$result) {
         throw new Doctrine_Task_Exception('Could not generate migration classes from database');
     } else {
         $this->notify('Generated migration classes successfully from database');
     }
 }
function generate_migrations()
{
    $path = makeMigrationsDir();
    Doctrine_Core::generateMigrationsFromDb($path);
}
 public function generateMigration($className = null, $dFromDatabase = false, $mFromModels = false)
 {
     $this->_initDoctrineResource();
     $migratePath = $this->_getMigrationsDirectoryPath();
     if ($className) {
         Doctrine_Core::generateMigrationClass($className, $migratePath);
         $this->_print('Successfully generated migration class ' . $className . '.', array('color' => 'green'));
         $this->_print('Destination Directory: ' . $migratePath);
     } else {
         if ($dFromDatabase) {
             $yamlSchemaPath = $this->_getYamlDirectoryPath();
             $migration = new Doctrine_Migration($migrationsPath);
             $result1 = false;
             if (!count($migration->getMigrationClasses())) {
                 $result1 = Doctrine_Core::generateMigrationsFromDb($migrationsPath);
             }
             $connections = array();
             foreach (Doctrine_Manager::getInstance() as $connection) {
                 $connections[] = $connection->getName();
             }
             $changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath, $connections, $yamlSchemaPath);
             $numChanges = count($changes, true) - count($changes);
             $result = $result1 || $numChanges ? true : false;
             if ($result) {
                 $this->_print('Generated migration classes from the database successfully.');
             } else {
                 throw new Exception('Could not generate migration classes from database');
             }
         } else {
             if ($mFromModels) {
                 $this->_loadDoctrineModels();
                 Doctrine_Core::generateMigrationsFromModels($migrationsPath, null);
                 $this->_print('Generated migration classes from the model successfully.');
             }
         }
     }
 }