Beispiel #1
0
 /**
  * Returns current schma version found in database
  *
  * @return int
  */
 public function getCurrentVersion()
 {
     if (!($suffix = $this->getTableSuffix())) {
         return parent::getCurrentVersion();
     }
     // if
     $sql = 'SELECT version FROM `s_schema_version_' . $suffix . '` 
             WHERE complete_date IS NOT NULL ORDER BY version DESC';
     $currentVersion = (int) $this->connection->query($sql)->fetchColumn();
     return $currentVersion;
 }
 /**
  * @param  int                                  $offset
  * @param  int                                  $totalCount
  * @return ErrorResult|FinishResult|ValidResult
  */
 public function run($offset, $totalCount = null)
 {
     if ($offset == 0) {
         $this->migrationManager->createSchemaTable();
     }
     $currentVersion = $this->migrationManager->getCurrentVersion();
     if (!$totalCount) {
         $totalCount = count($this->migrationManager->getMigrationsForVersion($currentVersion));
     }
     $migration = $this->migrationManager->getNextMigrationForVersion($currentVersion);
     if (null === $migration) {
         return new FinishResult($offset, $totalCount);
     }
     try {
         $this->migrationManager->apply($migration);
     } catch (\Exception $e) {
         $reflection = new \ReflectionClass(get_class($migration));
         $classFile = $reflection->getFileName();
         return new ErrorResult($e->getMessage(), $e, array('deltaFile' => $classFile, 'deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
     }
     return new ValidResult($offset + 1, $totalCount, array('deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
 }