MigrationVersion::getMigration PHP Method

getMigration() public method

Load and make a instance of the migration
public getMigration ( string $name, string $class, string $type, array $options = [] ) : boolean | CakeMigration
$name string File name where migration resides
$class string Migration class name
$type string Can be 'app' or a plugin name
$options array Extra options to send to CakeMigration class
return boolean | CakeMigration False in case of no file found, instance of the migration
    public function getMigration($name, $class, $type, $options = array())
    {
        if (!class_exists($class) && (!$this->_loadFile($name, $type) || !class_exists($class))) {
            throw new MigrationVersionException(sprintf(__d('migrations', 'Class `%1$s` not found on file `%2$s` for %3$s.'), $class, $name . '.php', $type === 'app' ? 'Application' : Inflector::camelize($type) . ' Plugin'));
        }
        $defaults = array('precheck' => $this->precheck);
        if (!empty($this->migrationConnection)) {
            $defaults['connection'] = $this->migrationConnection;
        }
        $options = array_merge($defaults, $options);
        return new $class($options);
    }

Usage Example

コード例 #1
0
 /**
  * testGetMigration method
  *
  * @return void
  */
 function testGetMigration()
 {
     $result = $this->Version->getMigration('inexistent_migration', 'InexistentMigration', 'test_migration_plugin');
     $this->assertFalse($result);
     $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin');
     $this->assertIsA($result, 'M4af6d40056b04408808500cb58157726');
     $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin');
     // Calling twice to check if it will not try to redeclare the class
     $result = $this->Version->getMigration('001_schema_dump', 'M4af6d40056b04408808500cb58157726', 'test_migration_plugin');
     $this->assertIsA($result, 'M4af6d40056b04408808500cb58157726');
     $this->assertEqual($result->description, 'Version 001 (schema dump) of TestMigrationPlugin');
 }
All Usage Examples Of MigrationVersion::getMigration