Esempio n. 1
0
 public function getAll($all = false)
 {
     $classes = new ArrayIterator();
     $iterator = new GlobIterator(sprintf('%s/Version_*.php', $this->config->getDir()), FilesystemIterator::KEY_AS_FILENAME);
     foreach ($iterator as $item) {
         /** @var $item \SplFileInfo */
         if (preg_match('/(Version_(\\d+))\\.php/', $item->getFilename(), $matches)) {
             $applied = $this->versionTable->applied($matches[2]);
             if ($all || !$applied) {
                 $className = $this->config->getNamespace() . '\\' . $matches[1];
                 if (!class_exists($className)) {
                     /** @noinspection PhpIncludeInspection */
                     require_once $this->config->getDir() . '/' . $item->getFilename();
                 }
                 if (class_exists($className)) {
                     $reflectionClass = new ReflectionClass($className);
                     $reflectionDescription = new ReflectionProperty($className, 'description');
                     if ($reflectionClass->implementsInterface(MigrationInterface::class)) {
                         $classes->append(['version' => $matches[2], 'class' => $className, 'description' => $reflectionDescription->getValue(), 'applied' => $applied]);
                     }
                 }
             }
         }
     }
     $classes->uasort(function ($a, $b) {
         if ($a['version'] == $b['version']) {
             return 0;
         }
         return $a['version'] < $b['version'] ? -1 : 1;
     });
     return $classes;
 }
Esempio n. 2
0
 public function onDispatch(MvcEvent $e)
 {
     if (!$e->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     $response = sprintf("Current version %s\n", $this->table->getCurrentVersion());
     $e->setResult($response);
     return $response;
 }
Esempio n. 3
0
 public function testGetCurrentVersion()
 {
     $result = $this->prophesize('Zend\\Db\\ResultSet\\ResultSet');
     $version = $this->prophesize('T4web\\Migrations\\Version\\Version');
     $this->tableGataway->select(Argument::type('callable'))->willReturn($result);
     $result->count()->willReturn(1);
     $result->current()->willReturn($version->reveal());
     $version->getVersion()->willReturn(2);
     $result = $this->table->getCurrentVersion();
     $this->assertEquals(2, $result);
 }
Esempio n. 4
0
 protected function applyMigration(array $migration, $down = false)
 {
     try {
         /** @var $migrationObject AbstractMigration */
         $migrationObject = new $migration['class']($this->serviceLocator);
         $this->console->writeLine(sprintf("%s Execute migration class %s.", $migration['class'], $down ? 'down' : 'up'));
         if ($down) {
             $migrationObject->down();
             $this->versionTable->delete($migration['version']);
         } else {
             $migrationObject->up();
             $this->versionTable->save($migration['version']);
         }
     } catch (InvalidQueryException $e) {
         $previousMessage = $e->getPrevious() ? $e->getPrevious()->getMessage() : null;
         $msg = sprintf('%s: "%s"; File: %s; Line #%d', $e->getMessage(), $previousMessage, $e->getFile(), $e->getLine());
         throw new \Exception($msg, $e->getCode(), $e);
     } catch (\Exception $e) {
         $msg = sprintf('%s; File: %s; Line #%d', $e->getMessage(), $e->getFile(), $e->getLine());
         throw new \Exception($msg, $e->getCode(), $e);
     }
 }