implemented debugging of the repo
This commit is contained in:
parent
1c513acaa4
commit
3b853644e0
|
@ -5,7 +5,8 @@
|
||||||
use \api\core\AuthSystem;
|
use \api\core\AuthSystem;
|
||||||
use \api\core\ModuleFactory;
|
use \api\core\ModuleFactory;
|
||||||
use \api\core\Config;
|
use \api\core\Config;
|
||||||
use \error\core\Error;
|
use database\core\Repo;
|
||||||
|
use \error\core\Error;
|
||||||
use \error\core\Err;
|
use \error\core\Err;
|
||||||
|
|
||||||
|
|
||||||
|
@ -503,6 +504,11 @@
|
||||||
/* (3) On ajoute les données */
|
/* (3) On ajoute les données */
|
||||||
$response->appendAll($returned);
|
$response->appendAll($returned);
|
||||||
|
|
||||||
|
/* (4) Si le Debug est actif on ajoute le debug des repo */
|
||||||
|
if(Repo::isDebugEnabled()){
|
||||||
|
$response->append("repoDebug" , Repo::getDebug());
|
||||||
|
}
|
||||||
|
|
||||||
/* (4) On retourne la réponse */
|
/* (4) On retourne la réponse */
|
||||||
return $response;
|
return $response;
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,13 @@ class excelController
|
||||||
$addEU = function() use (&$UECode,&$allUE,&$UE){
|
$addEU = function() use (&$UECode,&$allUE,&$UE){
|
||||||
//determine if UE is disabled (if cours+td+tp = 0)
|
//determine if UE is disabled (if cours+td+tp = 0)
|
||||||
$totalVH = 0;
|
$totalVH = 0;
|
||||||
|
if(is_array($UE["groups"]) && count($UE["groups"]) > 0){
|
||||||
foreach ($UE["groups"] as $groups){
|
foreach ($UE["groups"] as $groups){
|
||||||
foreach ($groups as $group){
|
foreach ($groups as $group){
|
||||||
$totalVH += $group["VH"];
|
$totalVH += $group["VH"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$UE["disabled"] = $totalVH == 0;
|
$UE["disabled"] = $totalVH == 0;
|
||||||
|
|
||||||
|
@ -428,7 +430,8 @@ class excelController
|
||||||
|
|
||||||
Repo::flushStack();
|
Repo::flushStack();
|
||||||
|
|
||||||
return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
|
//return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
|
||||||
|
return["data" => true];
|
||||||
}catch (Exception $e){
|
}catch (Exception $e){
|
||||||
return [ 'error' => new Error(Err::UnknownError) ];
|
return [ 'error' => new Error(Err::UnknownError) ];
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
* @password<String> Database password
|
* @password<String> Database password
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function __construct($host, $dbname, $username, $password){
|
private function __construct($host, $dbname, $username, $password, $debug = false){
|
||||||
/* (2) Stores configuration */
|
/* (2) Stores configuration */
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->dbname = $dbname;
|
$this->dbname = $dbname;
|
||||||
|
@ -79,6 +79,10 @@
|
||||||
$this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
|
$this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
|
||||||
$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
|
|
||||||
|
if($debug){
|
||||||
|
$this->pdo->enableDebug();
|
||||||
|
}
|
||||||
|
|
||||||
// On signale que tout s'est bien passe
|
// On signale que tout s'est bien passe
|
||||||
$this->error = new Error(Err::Success);
|
$this->error = new Error(Err::Success);
|
||||||
|
|
||||||
|
@ -120,7 +124,7 @@
|
||||||
|
|
||||||
/* (1) If local -> instanciates with local configuration */
|
/* (1) If local -> instanciates with local configuration */
|
||||||
// if( !checkdnsrr($_SERVER['SERVER_NAME'], 'NS') )
|
// if( !checkdnsrr($_SERVER['SERVER_NAME'], 'NS') )
|
||||||
self::$instance[$label] = new DatabaseDriver($conf[$label]['local']['host'], $conf[$label]['local']['dbname'], $conf[$label]['local']['user'], $conf[$label]['local']['password']);
|
self::$instance[$label] = new DatabaseDriver($conf[$label]['local']['host'], $conf[$label]['local']['dbname'], $conf[$label]['local']['user'], $conf[$label]['local']['password'],$conf[$label]['local']['debug']);
|
||||||
/* (2) If Remote -> instanciates with Remote configuration */
|
/* (2) If Remote -> instanciates with Remote configuration */
|
||||||
// else
|
// else
|
||||||
// self::$instance[$label] = new DatabaseDriver($conf[$label]['remote']['host'], $conf[$label]['remote']['dbname'], $conf[$label]['remote']['user'], $conf[$label]['remote']['password']);
|
// self::$instance[$label] = new DatabaseDriver($conf[$label]['remote']['host'], $conf[$label]['remote']['dbname'], $conf[$label]['remote']['user'], $conf[$label]['remote']['password']);
|
||||||
|
@ -204,6 +208,14 @@
|
||||||
$this->pdo->executeStack();
|
$this->pdo->executeStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDebug() : array{
|
||||||
|
return $this->pdo->getDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDebugEnabled() : bool {
|
||||||
|
return $this->pdo->isDebugEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ class PDOWrapper extends \PDO
|
||||||
{
|
{
|
||||||
private $statements = [];
|
private $statements = [];
|
||||||
private $stacking = false;
|
private $stacking = false;
|
||||||
|
private $debug = [];
|
||||||
|
private $debugEnabled = false;
|
||||||
|
|
||||||
public function __construct(String $dsn, String $username, String $passwd, array $options = [])
|
public function __construct(String $dsn, String $username, String $passwd, array $options = [])
|
||||||
{
|
{
|
||||||
|
@ -21,6 +23,10 @@ class PDOWrapper extends \PDO
|
||||||
|
|
||||||
public function prepare($statement, $options = [])
|
public function prepare($statement, $options = [])
|
||||||
{
|
{
|
||||||
|
if($this->debugEnabled){
|
||||||
|
$this->storeDebug();
|
||||||
|
}
|
||||||
|
|
||||||
if($this->stacking){
|
if($this->stacking){
|
||||||
return new PDOStatementWrapper($statement, $this);
|
return new PDOStatementWrapper($statement, $this);
|
||||||
}else{
|
}else{
|
||||||
|
@ -30,14 +36,64 @@ class PDOWrapper extends \PDO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function storeDebug(){
|
||||||
|
//get all the debug info about the repo
|
||||||
|
$prepareStack = debug_backtrace(0,3)[1];
|
||||||
|
$stack = debug_backtrace(0,3)[2];
|
||||||
|
//create the reflection object
|
||||||
|
$f = new \ReflectionMethod($stack["class"],$stack["function"]);
|
||||||
|
//get only the repo name
|
||||||
|
$className = explode("\\",$stack["class"]);
|
||||||
|
$className = $className[count($className)-1];
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
//if we are flushing a stack, just count the number of request stacked
|
||||||
|
if($stack["function"] == "executeStack"){
|
||||||
|
|
||||||
|
$result["StackedRequest"] = true;
|
||||||
|
$result["numberOfStackedRequest"] = substr_count($prepareStack["args"][0],";");
|
||||||
|
//if we are not stacking, log the repo call
|
||||||
|
}else if(!$this->stacking){
|
||||||
|
//store results
|
||||||
|
$result["repoName"] = $className;
|
||||||
|
$result["methodName"] = $stack["function"];
|
||||||
|
$result["args"] = [];
|
||||||
|
|
||||||
|
foreach ($f->getParameters() as $key => $param) {
|
||||||
|
$result["args"][$param->name] = $stack["args"][$key];
|
||||||
|
}
|
||||||
|
//else we are stacking a request, we should not log it
|
||||||
|
}else{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->debug[] = $result;
|
||||||
|
}
|
||||||
|
public function getDebug() : array{
|
||||||
|
return $this->debug;
|
||||||
|
}
|
||||||
|
|
||||||
public function enableStacking(){
|
public function enableStacking(){
|
||||||
$this->stacking = true;
|
$this->stacking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDebugEnabled() : bool{
|
||||||
|
return $this->debugEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
public function stackStatement(PDOStatementWrapper $st){
|
public function stackStatement(PDOStatementWrapper $st){
|
||||||
array_push($this->statements,$st);
|
array_push($this->statements,$st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enableDebug(){
|
||||||
|
$this->debugEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableDebug(){
|
||||||
|
$this->debugEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
public function executeStack(){
|
public function executeStack(){
|
||||||
//init the statements and the generator of number
|
//init the statements and the generator of number
|
||||||
$finalStatement = '';
|
$finalStatement = '';
|
||||||
|
|
|
@ -69,6 +69,14 @@
|
||||||
static::$driver->flushStack();
|
static::$driver->flushStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getDebug() : array{
|
||||||
|
return static::$driver->getDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isDebugEnabled() : bool{
|
||||||
|
return static::$driver->isDebugEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
"host" : "mariadb",
|
"host" : "mariadb",
|
||||||
"dbname" : "vhost",
|
"dbname" : "vhost",
|
||||||
"user" : "php",
|
"user" : "php",
|
||||||
"password" : "4JB1dtbrIC8pT935"
|
"password" : "4JB1dtbrIC8pT935",
|
||||||
|
"debug" : true
|
||||||
},
|
},
|
||||||
"remote": {
|
"remote": {
|
||||||
"host" : "db_remote_host",
|
"host" : "db_remote_host",
|
||||||
|
|
Loading…
Reference in New Issue