/** * @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); } }
/** * @param string $mode self::MODE_CONTINUE|self::MODE_RESET|self::MODE_INIT * @param IConfiguration $config * @return void */ public function run($mode = self::MODE_CONTINUE, IConfiguration $config = NULL) { if ($config) { foreach ($config->getGroups() as $group) { $this->addGroup($group); } foreach ($config->getExtensionHandlers() as $ext => $handler) { $this->addExtensionHandler($ext, $handler); } } if ($mode === self::MODE_INIT) { $this->printer->printSource($this->driver->getInitTableSource() . "\n"); $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(); $this->printer->printIntro($mode); if ($mode === self::MODE_RESET) { $this->driver->emptyDatabase(); } $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) { $time = microtime(TRUE); $queriesCount = $this->execute($file); $this->printer->printExecute($file, $queriesCount, microtime(TRUE) - $time); } $this->driver->unlock(); $this->printer->printDone(); } catch (Exception $e) { $this->driver->unlock(); $this->printer->printError($e); } }