implemented debugging of the repo

This commit is contained in:
Unknown 2018-03-08 20:53:40 +01:00
parent 1c513acaa4
commit 3b853644e0
6 changed files with 94 additions and 8 deletions

View File

@ -5,7 +5,8 @@
use \api\core\AuthSystem;
use \api\core\ModuleFactory;
use \api\core\Config;
use \error\core\Error;
use database\core\Repo;
use \error\core\Error;
use \error\core\Err;
@ -503,6 +504,11 @@
/* (3) On ajoute les données */
$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 */
return $response;

View File

@ -63,9 +63,11 @@ class excelController
$addEU = function() use (&$UECode,&$allUE,&$UE){
//determine if UE is disabled (if cours+td+tp = 0)
$totalVH = 0;
foreach ($UE["groups"] as $groups){
foreach ($groups as $group){
$totalVH += $group["VH"];
if(is_array($UE["groups"]) && count($UE["groups"]) > 0){
foreach ($UE["groups"] as $groups){
foreach ($groups as $group){
$totalVH += $group["VH"];
}
}
}
@ -428,7 +430,8 @@ class excelController
Repo::flushStack();
return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
//return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
return["data" => true];
}catch (Exception $e){
return [ 'error' => new Error(Err::UnknownError) ];
}

View File

@ -61,7 +61,7 @@
* @password<String> Database password
*
*/
private function __construct($host, $dbname, $username, $password){
private function __construct($host, $dbname, $username, $password, $debug = false){
/* (2) Stores configuration */
$this->host = $host;
$this->dbname = $dbname;
@ -79,6 +79,10 @@
$this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
if($debug){
$this->pdo->enableDebug();
}
// On signale que tout s'est bien passe
$this->error = new Error(Err::Success);
@ -120,7 +124,7 @@
/* (1) If local -> instanciates with local configuration */
// 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 */
// else
// 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();
}
public function getDebug() : array{
return $this->pdo->getDebug();
}
public function isDebugEnabled() : bool {
return $this->pdo->isDebugEnabled();
}
}

View File

@ -13,6 +13,8 @@ class PDOWrapper extends \PDO
{
private $statements = [];
private $stacking = false;
private $debug = [];
private $debugEnabled = false;
public function __construct(String $dsn, String $username, String $passwd, array $options = [])
{
@ -21,6 +23,10 @@ class PDOWrapper extends \PDO
public function prepare($statement, $options = [])
{
if($this->debugEnabled){
$this->storeDebug();
}
if($this->stacking){
return new PDOStatementWrapper($statement, $this);
}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(){
$this->stacking = true;
}
public function isDebugEnabled() : bool{
return $this->debugEnabled;
}
public function stackStatement(PDOStatementWrapper $st){
array_push($this->statements,$st);
}
public function enableDebug(){
$this->debugEnabled = true;
}
public function disableDebug(){
$this->debugEnabled = false;
}
public function executeStack(){
//init the statements and the generator of number
$finalStatement = '';

View File

@ -69,6 +69,14 @@
static::$driver->flushStack();
}
public static function getDebug() : array{
return static::$driver->getDebug();
}
public static function isDebugEnabled() : bool{
return static::$driver->isDebugEnabled();
}

View File

@ -4,7 +4,8 @@
"host" : "mariadb",
"dbname" : "vhost",
"user" : "php",
"password" : "4JB1dtbrIC8pT935"
"password" : "4JB1dtbrIC8pT935",
"debug" : true
},
"remote": {
"host" : "db_remote_host",