Ejemplo n.º 1
0
 /**
  * exe
  *
  * @access public
  * @return boolean
  */
 public function exe($file)
 {
     try {
         echo "Script selected : " . $file . PHP_EOL;
         if ($this->params['checkDb']) {
             $params = new OdaPrepareReqSql();
             $params->sql = "\n                    SELECT COUNT(*) as 'nb'\n                    FROM `" . self::$config->BD_ENGINE->prefixTable . "api_tab_migration`\n                    WHERE 1=1\n                    AND `name` = '" . str_replace('\\', '/', $file) . "'\n                ";
             $params->typeSQL = OdaLibBd::SQL_GET_ONE;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             $exist = $retour->data->nb;
             if ($exist && $this->params['option'] == "do") {
                 echo "Status for the migration: {$file}: already done" . PHP_EOL;
                 return true;
             } else {
                 if (!$exist && $this->params['option'] == "do") {
                     echo "Status for the migration: {$file}: clear to done" . PHP_EOL;
                 }
             }
             if (!$exist && $this->params['option'] == "unDo") {
                 echo "Status for the migration: {$file}: nothing to unDo" . PHP_EOL;
                 return true;
             } else {
                 if ($exist && $this->params['option'] == "unDo") {
                     echo "Status for the migration: {$file}: check ok to unDo" . PHP_EOL;
                 }
             }
         }
         $contentScript = file_get_contents($file, FILE_USE_INCLUDE_PATH);
         $contentScript = str_replace("@prefix@", self::$config->BD_ENGINE->prefixTable, $contentScript);
         $params = new OdaPrepareReqSql();
         $params->sql = $contentScript;
         $params->typeSQL = OdaLibBd::SQL_SCRIPT;
         $retour = $this->BD_ENGINE->reqODASQL($params);
         echo "Status for the migration : " . $retour->strStatut . ($retour->strStatut != 5 ? " (error : " . $retour->strErreur . ")" : "") . PHP_EOL;
         if ($this->params['option'] == "do") {
             $params = new OdaPrepareReqSql();
             $params->sql = "\n                    INSERT INTO `" . self::$config->BD_ENGINE->prefixTable . "api_tab_migration`\n                    (`name`, `dateMigration`)\n                    VALUES\n                    ('" . str_replace('\\', '/', $file) . "', NOW())\n                ";
             $params->typeSQL = OdaLibBd::SQL_SCRIPT;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             echo "Status for the trace record : " . $retour->strStatut . ($retour->strStatut != 5 ? " (error : " . $retour->strErreur . ")" : "") . PHP_EOL;
         } elseif ($this->params['option'] == "unDo") {
             $params = new OdaPrepareReqSql();
             $file = str_replace('unDo', 'do', $file);
             $params->sql = "\n                    DELETE FROM `" . self::$config->BD_ENGINE->prefixTable . "api_tab_migration`\n                    WHERE 1=1\n                    AND `name` = '" . str_replace('\\', '/', $file) . "'\n                ";
             $params->typeSQL = OdaLibBd::SQL_SCRIPT;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             echo "Status for the trace record : " . $retour->strStatut . ($retour->strStatut != 5 ? " (error : " . $retour->strErreur . ")" : "") . PHP_EOL;
         }
         return $this;
     } catch (Exception $ex) {
         die($ex . '');
     }
 }
Ejemplo n.º 2
0
 /**
  * @name setParameter
  * @desc met à jour la valeur du param
  * @return boolean
  */
 function setParameter($p_param, $p_valeur)
 {
     try {
         $params = new \stdClass();
         $params->nameObj = "api_tab_parametres";
         $params->keyObj = ["param_name" => $p_param];
         $params->setObj = ["param_value" => $p_valeur];
         $id = $this->BD_ENGINE->setSingleObj($params);
         return $id;
     } catch (Exception $ex) {
         $this->object_retour->strErreur = $ex . '';
         $this->object_retour->statut = self::STATE_ERROR;
         die;
     }
 }
Ejemplo n.º 3
0
 /**
  * @name getListTables
  * @param array
  */
 public function getListTables()
 {
     try {
         $results = array();
         if (self::$config->type == 'mysql') {
             $params = new stdClass();
             $params->sql = "SHOW TABLES LIKE '" . self::$config->prefixTable . "%';";
             $req = $this->connection->prepare($params->sql);
             $req->execute();
             $resultats = $req->fetchAll();
             $req->closeCursor();
             foreach ($resultats as $value) {
                 $strTables = str_replace(self::$config->prefixTable, "", $value[0]);
                 $results[] = $strTables;
             }
         }
         return $results;
     } catch (Exception $ex) {
         throw new Exception($ex);
     }
 }