/** * 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 . ''); } }
/** * buildSession * @param array $p_params * @param array $p_params[code_user] * @param array $p_params[password] * @param array $p_params[dbPassword] * @return string */ public function buildSession($p_params) { try { $v_code_user = $p_params["code_user"]; $v_key = ""; //Detruit les veilles clés $params = new SimpleObject\OdaPrepareReqSql(); $params->sql = "DELETE FROM `api_tab_session`\n WHERE 1=1\n AND `datas` like '%\"code_user\":\"" . $v_code_user . "\"%'\n AND (`dateCreation` + INTERVAL `periodeValideMinute` MINUTE) < NOW()\n AND `periodeValideMinute` != 0\n ;"; $params->typeSQL = OdaLibBd::SQL_SCRIPT; $retour = $this->BD_AUTH->reqODASQL($params); //Vérifie la présence d'une clé $params = new SimpleObject\OdaPrepareReqSql(); $params->sql = "SELECT *\n FROM `api_tab_session` a\n WHERE 1=1\n AND a.`datas` like '%\"code_user\":\"" . $v_code_user . "\"%'\n AND (a.`dateCreation` + INTERVAL a.`periodeValideMinute` MINUTE) > NOW()\n ;"; $params->typeSQL = OdaLibBd::SQL_GET_ONE; $retour = $this->BD_AUTH->reqODASQL($params); if ($retour->data) { $v_key = $retour->data->key; } else { //Check log pass $checkPass = true; if (!OdaLib::startsWith($p_params['password'], "authByGoogle-")) { $checkPass = password_verify($p_params['password'], $p_params['dbPassword']); } if ($checkPass) { //Construit une nouvelle clé $v_strDate = \date('YmdHis'); $v_key = \md5($v_code_user . "_" . $v_strDate); $json = new stdClass(); $json->code_user = $v_code_user; $json->date = $v_strDate; $params = new SimpleObject\OdaPrepareReqSql(); $params->sql = "INSERT INTO `api_tab_session`(\n `id` ,\n `key` ,\n `datas` ,\n `dateCreation` ,\n `periodeValideMinute`\n )\n VALUES (\n NULL , '" . $v_key . "', '" . \json_encode($json) . "', NOW(), 720\n )\n ;"; $params->typeSQL = OdaLibBd::SQL_INSERT_ONE; $retour = $this->BD_ENGINE->reqODASQL($params); } else { $this->dieInError('Auth impossible.(Password wrong)', self::STATE_ERROR_AUTH); } } return $v_key; } catch (Exception $ex) { $this->object_retour->strErreur = $ex . ''; $this->object_retour->statut = self::STATE_ERROR; die; } }