protected function doApply()
 {
     $dataDir = $this->dataDir->getAbsolutePath();
     $htmlDir = $this->htmlDir->getAbsolutePath();
     define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/');
     require_once HTML_REALDIR . '/define.php';
     require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php';
     $query = SC_Query_Ex::getSingletonInstance();
     $storage = new Zeclib_DefaultMigrationStorage($query, $this->system);
     $storage->versionTable = $this->versionTable;
     $storage->containerDirectories[] = $this->containerDir->getPath();
     $migrator = new Zeclib_Migrator($storage, $query);
     $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this);
     $migrations = array();
     $versions = preg_split('/[,\\s]+/', $this->version, 0, PREG_SPLIT_NO_EMPTY);
     foreach ($versions as $version) {
         try {
             $migrations[] = $migrator->loadMigration($version);
         } catch (Zeclib_MigrationException $e) {
             $message = $e->getMessage();
             $this->log($message, Zeclib_MigrationLogger::TYPE_WARNING);
         }
     }
     $num = $migrator->apply($migrations);
     $this->log(sprintf('%d migrations are applied.', $num));
 }
Exemple #2
0
 public static function getDefaultLogger()
 {
     if (!self::$defaultLogger) {
         self::$defaultLogger = new Zeclib_NullMigrationLogger();
     }
     return self::$defaultLogger;
 }
 protected function doApply()
 {
     $dataDir = $this->dataDir->getAbsolutePath();
     $htmlDir = $this->htmlDir->getAbsolutePath();
     define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/');
     require_once HTML_REALDIR . '/define.php';
     require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php';
     $query = SC_Query_Ex::getSingletonInstance();
     $storage = new Zeclib_DefaultMigrationStorage($query, $this->system);
     $storage->versionTable = $this->versionTable;
     $storage->containerDirectories[] = $this->containerDir->getPath();
     $migrator = new Zeclib_Migrator($storage, $query);
     $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this);
     $from = $this->from === '' ? null : $this->from;
     $to = $this->to === '' ? null : $this->to;
     $num = $migrator->up($from, $to);
     $this->log(sprintf('%d migrations are applied.', $num));
 }
 protected function doReset()
 {
     $dataDir = $this->dataDir->getAbsolutePath();
     $htmlDir = $this->htmlDir->getAbsolutePath();
     define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/');
     require_once HTML_REALDIR . '/define.php';
     require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php';
     $query = SC_Query_Ex::getSingletonInstance();
     $storage = new Zeclib_DefaultMigrationStorage($query, $this->system);
     $storage->versionTable = $this->versionTable;
     $storage->containerDirectories[] = $this->containerDir->getPath();
     $migrator = new Zeclib_Migrator($storage, $query);
     $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this);
     $ignoreMissing = strncmp(strtolower($this->ignoreMissing), 'y', 1) == 0;
     $num = $migrator->down(null, null, $ignoreMissing);
     $this->log(sprintf('%d migrations are reverted.', $num));
     $migrator->clear();
     $this->log(sprintf('All migrations are removed from storage.', $num));
 }
 /**
  * @dataProvider provideDownPattern
  */
 public function testDown($versions, $from, $to)
 {
     $this->storage->expects($this->once())->method('getAppliedVersions')->will($this->returnValue($versions));
     $this->storage->expects($this->any())->method('isAppliedVersion')->willReturn(true);
     $returnValues = array();
     foreach ($versions as $index => $version) {
         $migra = $this->getMockForAbstractClass('Zeclib_Migration', array($version, $this->query));
         $migra->applied = true;
         $cond = $this->isIncludedVersion($version, $from, $to) ? $this->once() : $this->never();
         $migra->expects($cond)->method('down');
         $returnValues[] = array($version, $migra);
     }
     $this->storage->expects($this->any())->method('loadMigration')->will($this->returnValueMap($returnValues));
     $migrator = new Zeclib_Migrator($this->storage, $this->query);
     $migrator->down($from, $to);
     foreach ($returnValues as $values) {
         list($version, $migra) = $values;
         $expected = !$this->isIncludedVersion($version, $from, $to);
         $this->assertEquals($expected, $migra->applied, 'Migration version:' . $version);
     }
 }