Exemplo n.º 1
0
 /**
  * @param string self::MODE_CONTINUE|self::MODE_RESET|self::MODE_INIT
  */
 public function run($mode = self::MODE_CONTINUE)
 {
     if ($mode === self::MODE_INIT) {
         $this->printer->printSource($this->driver->getInitTableSource());
         $files = $this->finder->find($this->groups, array_keys($this->extensionsHandlers));
         $files = $this->orderResolver->resolve(array(), $this->groups, $files, self::MODE_RESET);
         $this->printer->printSource($this->driver->getInitMigrationsSource($files));
         return;
     }
     try {
         $this->driver->setupConnection();
         $this->driver->lock();
         if ($mode === self::MODE_RESET) {
             $this->driver->emptyDatabase();
             $this->driver->lock();
             $this->printer->printReset();
             $this->driver->createTable();
         }
         $migrations = $this->driver->getAllMigrations();
         $files = $this->finder->find($this->groups, array_keys($this->extensionsHandlers));
         $toExecute = $this->orderResolver->resolve($migrations, $this->groups, $files, $mode);
         $this->printer->printToExecute($toExecute);
         foreach ($toExecute as $file) {
             $queriesCount = $this->execute($file);
             $this->printer->printExecute($file, $queriesCount);
         }
         $this->printer->printDone();
     } catch (Exception $e) {
         $this->printer->printError($e);
     }
 }