public function getMapping($type, $cache = true)
{
if ($type !== 'app') {
$type = Inflector::camelize($type);
}
if ($cache && !empty($this->_mapping[$type])) {
return $this->_mapping[$type];
}
$mapping = $this->_enumerateMigrations($type);
if (empty($mapping)) {
return false;
}
$migrated = $this->Version->find('all', array('conditions' => array('OR' => array(array($this->Version->alias . '.type' => Inflector::underscore($type)), array($this->Version->alias . '.type' => $type))), 'recursive' => -1));
// For BC, 002 was not applied yet.
$bc = $this->Version->schema('class') === null;
if ($bc) {
$migrated = Hash::combine($migrated, '{n}.' . $this->Version->alias . '.version', '{n}.' . $this->Version->alias . '.created');
} else {
$migrated = Hash::combine($migrated, '{n}.' . $this->Version->alias . '.class', '{n}.' . $this->Version->alias . '.created');
}
$bcMapping = array();
if ($type === 'Migrations') {
$bcMapping = array('InitMigrations' => 'M4af6e0f0a1284147a0b100ca58157726', 'ConvertVersionToClassNames' => 'M4ec50d1f7a284842b1b770fdcbdd56cb');
}
ksort($mapping);
foreach ($mapping as $version => $migration) {
list($name, $class) = each($migration);
$mapping[$version] = array('version' => $version, 'name' => $name, 'class' => $class, 'type' => $type, 'migrated' => null);
if ($bc) {
if (isset($migrated[$version])) {
$mapping[$version]['migrated'] = $migrated[$version];
}
} else {
if (isset($migrated[$class])) {
$mapping[$version]['migrated'] = $migrated[$class];
} elseif (isset($bcMapping[$class]) && !empty($migrated[$bcMapping[$class]])) {
$mapping[$version]['migrated'] = $migrated[$bcMapping[$class]];
}
}
}
$this->_mapping[$type] = $mapping;
return $mapping;
}
/** * testGetMapping method * * @return void */ public function testGetMapping() { CakePlugin::load('TestMigrationPlugin'); $result = $this->Version->getMapping('test_migration_plugin'); $expected = array(1 => array('version' => 1, 'name' => '001_schema_dump', 'class' => 'M4af6d40056b04408808500cb58157726', 'type' => 'TestMigrationPlugin', 'migrated' => null), 2 => array('version' => 2, 'name' => '002_another_migration_plugin_test_migration', 'class' => 'AnotherMigrationPluginTestMigration', 'type' => 'TestMigrationPlugin', 'migrated' => null)); $this->assertEqual($result, $expected); $result = $this->Version->getMapping('migrations'); $expected = array(1 => array('version' => 1, 'name' => '001_init_migrations', 'class' => 'InitMigrations', 'type' => 'Migrations', 'migrated' => '2009-11-10 00:55:34'), 2 => array('version' => 2, 'name' => '002_convert_version_to_class_names', 'class' => 'ConvertVersionToClassNames', 'type' => 'Migrations', 'migrated' => '2011-11-18 13:53:32'), 3 => array('version' => 3, 'name' => '003_increase_class_name_length', 'class' => 'IncreaseClassNameLength', 'type' => 'Migrations', 'migrated' => null)); $this->assertEqual($result, $expected); }