/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $softRollback = $this->option('soft');
     //Modulos ja carregados
     $oldLoadedModules = Configs::getConfig(PathHelper::getModuleGeneralConfig(), Strings::CONFIG_LOADED_MODULES);
     if ($oldLoadedModules != Strings::EMPTY_STRING) {
         //Pega modulos carredos em forma de array
         $explodedLoadedModules = ModulesHelper::getLoadedModules($oldLoadedModules);
         if (is_array($explodedLoadedModules)) {
             $lastModule = $explodedLoadedModules[count($explodedLoadedModules) - 1];
             $lastModuleExploded = explode(Strings::MODULE_TYPE_NAME_SEPARATOR, $lastModule);
             if (is_array($lastModuleExploded)) {
                 $lastModuleType = $lastModuleExploded[0];
                 $lastModuleName = $lastModuleExploded[1];
                 $this->info(Strings::rollingBackModuleInfo($lastModuleExploded[0], $lastModuleExploded[1]));
                 $lastModuleRollbackFile = PathHelper::getModuleRollbackFile($lastModuleType, $lastModuleName);
                 if ($softRollback) {
                     RollbackManager::execSoftRollback($lastModuleRollbackFile, $this);
                 } else {
                     RollbackManager::execHardRollback($lastModuleType, $lastModuleName, $this);
                 }
             } else {
                 $this->error(Strings::ERROR_CANT_RESOLVE_MODULE_NAME);
             }
         } else {
             $this->error(Strings::ERROR_CANT_RESOLVE_LOADED_MODULES);
         }
     } else {
         $this->info(Strings::STATUS_NO_MODULES_LOADED);
     }
 }
 /**
  * Faz rollback do arquivo de rollback do modulo
  *
  * @param array $rollback
  * @return array|bool
  */
 public static function execHardRollback($moduleType, $moduleName, Command $command)
 {
     $rollback = PathHelper::getModuleRollbackFile($moduleType, $moduleName);
     RollbackManager::transformRollbackFileToRollbackArrayIfNeeded($rollback);
     while (!empty($rollback)) {
         $errors = [];
         $rollback = PathHelper::getModuleRollbackFile($moduleType, $moduleName);
         RollbackManager::transformRollbackFileToRollbackArrayIfNeeded($rollback);
         if (!RollbackManager::execSoftRollback($rollback, $command)) {
             $errors[] = Strings::ERROR_EXEC_HARD_ROLLBACK;
             break;
         }
         RollbackManager::transformRollbackFileToRollbackArrayIfNeeded($rollback);
     }
     return !empty($errors) ? $errors : true;
 }
 /**
  * Constroi o arquivo de rollback
  *
  * @param string $moduleType
  * @param string $moduleName
  * @param array $rollback
  * @return array|bool
  */
 public static function createRollbackFile($moduleType, $moduleName, array &$rollback)
 {
     $errors = [];
     //Cria registro no rollback dizendo que o arquivo foi copiado
     $rollback[Strings::ROLLBACK_OLD_ROLLBACK_TAG] = EscapeHelper::encode(file_get_contents(PathHelper::getModuleRollbackFile($moduleType, $moduleName)));
     if (RollbackManager::buildRollback($rollback, PathHelper::getModuleRollbackFile($moduleType, $moduleName)) == false) {
         $errors[] = Strings::ERROR_CREATE_ROLLBACK_FILE;
     }
     return !empty($errors) ? $errors : true;
 }