public function testGetExecutedMigrations() { $this->_adapter->versions = array(); $expectDownFiles = array(array('version' => '20090122193325', 'class' => 'AddNewTable', 'file' => '20090122193325_AddNewTable.php'), array('version' => 3, 'class' => 'AddIndexToBlogs', 'file' => '003_AddIndexToBlogs.php'), array('version' => 1, 'class' => 'CreateUsers', 'file' => '001_CreateUsers.php')); $this->_adapter->versions = $expectDownFiles; $expectedVersions = array(1, 3, '20090122193325'); $actualMigrateVersions = $this->object->getExecutedMigrations(); $this->assertEquals($expectedVersions, $actualMigrateVersions); $this->_adapter->versions = array(); $expectDownFiles = array(); $this->_adapter->versions = $expectDownFiles; $expectedVersions = array(); $actualMigrateVersions = $this->object->getExecutedMigrations(); $this->assertEquals($expectedVersions, $actualMigrateVersions); }
/** * Primary task entry point * * @param array $args Arguments to task * * @return string */ public function execute($args) { $return = 'Started: ' . date('Y-m-d g:ia T') . "\n\n" . "[db:status]:\n"; require_once 'Phigrate/Util/Migrator.php'; $util = new Phigrate_Util_Migrator($this->_adapter); $migrations = $util->getExecutedMigrations(); $this->_logger->debug('Migrations: ' . var_export($migrations, true)); $files = $util->getMigrationFiles($this->_migrationDir, 'up'); $this->_logger->debug('Files: ' . var_export($files, true)); $applied = array(); $notApplied = array(); foreach ($files as $file) { $key = array_search($file['version'], $migrations); require_once $this->_migrationDir . '/' . $file['file']; $class = new $file['class']($this->_adapter); // Get comment of migration limited to 50 caracters $comment = $class->getComment(); if (!empty($comment)) { // if comment is more than 50 caracters, cut string if (strlen($comment) > 50) { $comment = substr($comment, 0, 50) . '...'; } $comment = self::PURPLE_COLOR . ' (' . $comment . ')'; } unset($class); if (false !== $key) { $applied[] = self::GREEN_COLOR . $file['class'] . ' [ ' . $file['version'] . ' ]' . $comment . self::END_COLOR; unset($migrations[$key]); } else { $notApplied[] = self::ORANGE_COLOR . $file['class'] . ' [ ' . $file['version'] . ' ]' . $comment . self::END_COLOR; } } if (count($applied) > 0) { $return .= $this->_displayMigrations($applied, 'APPLIED'); } if (count($notApplied) > 0) { $return .= $this->_displayMigrations($notApplied, 'NOT APPLIED'); } if (count($migrations) > 0) { foreach ($migrations as $key => $migration) { $migrations[$key] = self::RED_COLOR . '??? [ ' . $migration . ' ]' . self::END_COLOR; } $return .= $this->_displayMigrations($migrations, 'APPLIED WITHOUT MIGRATION FILE'); } $return .= "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n"; return $return; }