public function execute(MigrationStep $step)
 {
     // base checks
     parent::execute($step);
     if (!isset($step->dsl['mode'])) {
         throw new \Exception("Invalid step definition: missing 'mode'");
     }
     $action = $step->dsl['mode'];
     if (!in_array($action, $this->supportedActions)) {
         throw new \Exception("Invalid step definition: value '{$action}' is not allowed for 'mode'");
     }
     $this->dsl = $step->dsl;
     $this->context = $step->context;
     if (isset($this->dsl['lang'])) {
         $this->setLanguageCode($this->dsl['lang']);
     }
     if (method_exists($this, $action)) {
         $previousUserId = $this->loginUser(self::ADMIN_USER_ID);
         try {
             $output = $this->{$action}();
         } catch (\Exception $e) {
             $this->loginUser($previousUserId);
             throw $e;
         }
         // reset the environment as much as possible as we had found it before the migration
         $this->loginUser($previousUserId);
         return $output;
     } else {
         throw new \Exception("Invalid step definition: value '{$action}' is not a method of " . get_class($this));
     }
 }
Ejemplo n.º 2
0
 /**
  * @param MigrationStep $step
  * @return void
  * @throws \Exception if migration step is not for this type of db
  */
 public function execute(MigrationStep $step)
 {
     parent::execute($step);
     $conn = $this->dbHandler->getConnection();
     // @see http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/platforms.html
     $dbType = strtolower(preg_replace('/([0-9]+|Platform)/', '', $conn->getDatabasePlatform()->getName()));
     $dsl = $step->dsl;
     if (!isset($dsl[$dbType])) {
         throw new \Exception("Current database type '{$dbType}' is not supported by the SQL migration");
     }
     $sql = $dsl[$dbType];
     return $conn->exec($sql);
 }
Ejemplo n.º 3
0
 /**
  * @param MigrationStep $step
  * @return void
  * @throws \Exception
  */
 public function execute(MigrationStep $step)
 {
     parent::execute($step);
     $dsl = $step->dsl;
     if (!isset($dsl['class'])) {
         throw new \Exception("Missing 'class' for php migration step");
     }
     $class = $dsl['class'];
     if (!class_exists($class) && isset($step->context['path'])) {
         if (!is_file($step->context['path'])) {
             throw new \Exception("Missing file '{$step->context['path']}' for php migration step to load class definition from");
         }
         include_once $step->context['path'];
     }
     if (!class_exists($class)) {
         throw new \Exception("Class '{$class}' for php migration step does not exist");
     }
     $interfaces = class_implements($class);
     if (!in_array($this->mandatoryInterface, $interfaces)) {
         throw new \Exception("The migration definition class '{$class}' should implement the interface '{$this->mandatoryInterface}'");
     }
     return call_user_func(array($class, 'execute'), $this->container);
 }