public function execute() { try { $migrationsPath = $this->getArgument('migrations_path'); $modelsPath = $this->getArgument('models_path'); $yamlSchemaPath = $this->getArgument('yaml_schema_path'); $migration = new Doctrine_Migration($migrationsPath); $result1 = false; if (!count($migration->getMigrationClasses())) { $builder = new Doctrine_Migration_Builder($migration); $result1 = $builder->generateMigrationsFromModels($modelsPath); } $diff = new Doctrine_Migration_Diff($modelsPath, $yamlSchemaPath, $migration); $changes = $diff->generateMigrationClasses(); $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 models' . (isset($e) ? ': ' . $e->getMessage() : null)); } else { $this->notify('Generated migration classes successfully from models'); } }
/** * Generate a set of migration classes from an existing set of models * * @param string $migrationsPath Path to your Doctrine migration classes * @param string $modelsPath Path to your Doctrine model classes * @param integer $modelLoading Style of model loading to use for loading the models in order to generate migrations * @return void */ public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null, $modelLoading = null) { $builder = new Doctrine_Migration_Builder($migrationsPath); return $builder->generateMigrationsFromModels($modelsPath, $modelLoading); }