Ejemplo n.º 1
0
 public function revert(array $migrations)
 {
     $migrations = $this->sort($migrations, SORT_DESC);
     $reverteds = 0;
     try {
         foreach ($migrations as $migration) {
             $this->query->begin();
             if (!$this->storage->isAppliedVersion($migration->version)) {
                 $this->logger->log(sprintf('Revert migration skipped, Already reverted.: {system:"%s", version:"%s"}', $this->storage->system, $migration->version));
                 continue;
             }
             $migration->down();
             $migration->applied = false;
             $this->storage->markReverted($migration->version);
             $this->query->commit();
             $this->logger->log(sprintf('Revert migration successful: {system:"%s", version:"%s"}', $this->storage->system, $migration->version));
             $reverteds++;
         }
         $this->query->commit();
     } catch (Exception $e) {
         if ($this->query->inTransaction()) {
             $this->query->rollback();
         }
         $this->logger->log(sprintf('Revert migration failed: {system:"%s", version:"%s"}', $this->storage->system, $migration->version));
         throw $e;
     }
     return $reverteds;
 }