Пример #1
0
 /**
  * Executes the specified migration on this environment.
  *
  * @param MigrationInterface $migration Migration
  * @param string $direction Direction
  * @return void
  */
 public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
 {
     $startTime = time();
     $direction = $direction == MigrationInterface::UP ? MigrationInterface::UP : MigrationInterface::DOWN;
     $migration->setAdapter($this->getAdapter());
     // begin the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->beginTransaction();
     }
     // Run the migration
     if (method_exists($migration, MigrationInterface::CHANGE)) {
         if ($direction == MigrationInterface::DOWN) {
             // Create an instance of the ProxyAdapter so we can record all
             // of the migration commands for reverse playback
             $proxyAdapter = AdapterFactory::instance()->getWrapper('proxy', $this->getAdapter());
             $migration->setAdapter($proxyAdapter);
             /** @noinspection PhpUndefinedMethodInspection */
             $migration->change();
             $proxyAdapter->executeInvertedCommands();
             $migration->setAdapter($this->getAdapter());
         } else {
             /** @noinspection PhpUndefinedMethodInspection */
             $migration->change();
         }
     } else {
         $migration->{$direction}();
     }
     // commit the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->commitTransaction();
     }
     // Record it in the database
     $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time()));
 }
Пример #2
0
 /**
  * Executes the specified migration on this environment.
  *
  * @param MigrationInterface $migration Migration
  * @param string $direction Direction
  * @return void
  */
 public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
 {
     $startTime = time();
     $direction = $direction == MigrationInterface::UP ? MigrationInterface::UP : MigrationInterface::DOWN;
     $migration->setAdapter($this->getAdapter());
     // begin the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->beginTransaction();
     }
     // force UTF-8 encoding for MySQL
     // TODO - this code will need to be abstracted when we support other db vendors
     //$this->getAdapter()->execute('SET NAMES UTF8');
     // Run the migration
     if (method_exists($migration, MigrationInterface::CHANGE)) {
         if ($direction == MigrationInterface::DOWN) {
             // Create an instance of the ProxyAdapter so we can record all
             // of the migration commands for reverse playback
             $proxyAdapter = new ProxyAdapter($this->getAdapter(), $this->getOutput());
             $migration->setAdapter($proxyAdapter);
             $migration->change();
             $proxyAdapter->executeInvertedCommands();
             $migration->setAdapter($this->getAdapter());
         } else {
             $migration->change();
         }
     } else {
         $migration->{$direction}();
     }
     // commit the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->commitTransaction();
     }
     // Record it in the database
     $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time()));
 }