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');
     }
 }
示例#2
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');
     }
 }
 public function testMigration()
 {
     $migration = new Doctrine_Migration('migration_classes');
     $this->assertFalse($migration->hasMigrated());
     $migration->setCurrentVersion(3);
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertEqual($migration->getLatestVersion(), 11);
     $this->assertEqual($migration->getNextVersion(), 12);
     $current = $migration->getCurrentVersion();
     $migration->setCurrentVersion(100);
     $this->assertEqual($migration->getCurrentVersion(), 100);
     $migration->setCurrentVersion($current);
     $migration->migrate(3);
     $this->assertTrue($migration->hasMigrated());
     $this->assertEqual($migration->getCurrentVersion(), 3);
     $this->assertTrue($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertTrue($this->conn->import->tableExists('migration_user'));
     $this->assertTrue($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(4);
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertTrue($migration->getMigrationClass(1) instanceof AddPhonenumber);
     $this->assertTrue($migration->getMigrationClass(2) instanceof AddUser);
     $this->assertTrue($migration->getMigrationClass(3) instanceof AddProfile);
     $this->assertTrue($migration->getMigrationClass(4) instanceof DropProfile);
     $this->assertFalse($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertFalse($this->conn->import->tableExists('migration_user'));
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
     $this->assertEqual(array(1 => 'AddPhonenumber', 2 => 'AddUser', 3 => 'AddProfile', 4 => 'DropProfile', 5 => 'Test5', 6 => 'Test6', 7 => 'Test7', 8 => 'Test8', 9 => 'Test9', 10 => 'Test10', 11 => 'Test11'), $migration->getMigrationClasses());
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $config = $this->getCliConfig();
     $migration = new Doctrine_Migration($config['migrations_path']);
     $from = $migration->getCurrentVersion();
     if (is_numeric($arguments['version'])) {
         $version = $arguments['version'];
     } else {
         if ($options['up']) {
             $version = $from + 1;
         } else {
             if ($options['down']) {
                 $version = $from - 1;
             } else {
                 $version = $migration->getLatestVersion();
             }
         }
     }
     if ($from == $version) {
         $this->logSection('doctrine', sprintf('Already at migration version %s', $version));
         return;
     }
     $this->logSection('doctrine', sprintf('Migrating from version %s to %s%s', $from, $version, $options['dry-run'] ? ' (dry run)' : ''));
     try {
         $migration_classes = $migration->getMigrationClasses();
         if ($version < $from) {
             for ($i = (int) $from - 1; $i >= (int) $version; $i--) {
                 $this->logSection('doctrine', 'executing migration : ' . $i . ', class: ' . $migration_classes[$i]);
                 $migration->migrate($i, $options['dry-run']);
             }
         } else {
             for ($i = (int) $from + 1; $i <= (int) $version; $i++) {
                 $this->logSection('doctrine', 'executing migration : ' . $i . ', class: ' . $migration_classes[$i]);
                 $migration->migrate($i, $options['dry-run']);
             }
         }
     } catch (Exception $e) {
     }
     // render errors
     if ($migration->hasErrors()) {
         if ($this->commandApplication && $this->commandApplication->withTrace()) {
             $this->logSection('doctrine', 'The following errors occurred:');
             foreach ($migration->getErrors() as $error) {
                 $this->commandApplication->renderException($error);
             }
         } else {
             $this->logBlock(array_merge(array('The following errors occurred:', ''), array_map(create_function('$e', 'return \' - \'.$e->getMessage();'), $migration->getErrors())), 'ERROR_LARGE');
         }
         return 1;
     }
     $this->logSection('doctrine', 'Migration complete');
 }
 public function testTest()
 {
     $migration1 = new Doctrine_Migration(dirname(__FILE__) . '/DC221');
     $migration2 = new Doctrine_Migration(dirname(__FILE__) . '/DC221');
     $this->assertEqual($migration1->getMigrationClasses(), $migration2->getMigrationClasses());
 }
示例#6
0
 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.');
             }
         }
     }
 }
示例#7
0
文件: index.php 项目: podstawski/papu
 if (!$dbtable) {
     $sql = "CREATE DATABASE `" . $dbname . "` CHARACTER SET utf8;\n                CREATE USER '" . $config['db.user'] . "'@'localhost' IDENTIFIED BY '" . $config['db.pass'] . "';\n                GRANT ALL PRIVILEGES ON " . $dbname . ".* TO '" . $config['db.user'] . "'@'%' WITH GRANT OPTION;\n        ";
     $db->exec($sql);
 }
 $conn->close();
 $db = new PDO($config['db.dsn'], $config['db.user'], $config['db.pass']);
 $conn = Doctrine_Manager::connection($db);
 if (isset($google_user)) {
     echo 'user: '******'<br>';
 }
 $migration = new Doctrine_Migration(__DIR__ . '/classes', $conn);
 $migration->setTableName('doctrine_migration_version');
 if (isset($_REQUEST['ver']) && (!isset($google_user) || $google_user->getNickname() == '*****@*****.**')) {
     $version = 0 + intval($_REQUEST['ver']);
 } else {
     $classesKeys = array_keys($migration->getMigrationClasses());
     $version = 0 + array_pop($classesKeys);
 }
 if (isset($_SERVER['HTTP_HOST'])) {
     echo '<h1>';
 }
 if ($migration->getCurrentVersion() == $version) {
     echo 'Database at version ' . $version . PHP_EOL;
 } else {
     $migration->migrate($version);
     echo 'Migrated succesfully to version ' . $migration->getCurrentVersion() . PHP_EOL;
 }
 if (isset($_SERVER['HTTP_HOST'])) {
     echo '</h1>';
 }
 if (isset($_SERVER['SERVER_SOFTWARE']) && strstr(strtolower($_SERVER['SERVER_SOFTWARE']), 'engine')) {