Compare commits

...

4 Commits

Author SHA1 Message Date
Clemens Schwaighofer
9eb78f40fd Warning in DB IO if we couldn't get any return PK 2017-03-31 15:28:36 +09:00
Clemens Schwaighofer
f599033a38 Bug fixes for unique per run logging 2017-03-17 14:50:58 +09:00
Clemens Schwaighofer
61f1b92bad Make per run log flag in Class Basic 2017-03-17 14:24:48 +09:00
Clemens Schwaighofer
1dfe246e0f Remove print_r on multiple returning data warning 2017-03-15 14:04:25 +09:00
4 changed files with 42 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
$LOG_PER_RUN = 1;
define('USE_DATABASE', true);
require("header.inc");

View File

@@ -119,10 +119,12 @@
private $log_file_name_ext = 'log'; // use this for date rotate
public $log_max_filesize = 0; // set in kilobytes
private $log_print_file = 'error_msg##LEVEL####CLASS####PAGENAME####DATE##';
private $log_file_unique_id; // a unique ID set only once for call derived from this class
public $log_print_file_date = 1; // if set add Y-m-d and do automatic daily rotation
public $log_per_level = 0; // set, it will split per level (first parameter in debug call)
public $log_per_class = 0; // set, will split log per class
public $log_per_page = 0; // set, will split log per called file
public $log_per_run = 0; // create a new log file per run (time stamp + unique ID)
public $starttime; // start time if time debug is used
public $endtime; // end time if time debug is used
@@ -215,6 +217,18 @@
if (isset($GLOBALS['PRINT_ALL']))
$this->print_output_all = $GLOBALS['PRINT_ALL'];
// GLOBAL rules for log writing
if (isset($GLOBALS['LOG_PRINT_FILE_DATE']))
$this->log_print_file_date = $GLOBALS['LOG_PRINT_FILE_DATE'];
if (isset($GLOBALS['LOG_PER_LEVEL']))
$this->log_per_level = $GLOBALS['LOG_PER_LEVEL'];
if (isset($GLOBALS['LOG_PER_CLASS']))
$this->log_per_class = $GLOBALS['LOG_PER_CLASS'];
if (isset($GLOBALS['LOG_PER_PAGE']))
$this->log_per_page = $GLOBALS['LOG_PER_PAGE'];
if (isset($GLOBALS['LOG_PER_RUN']))
$this->log_per_run = $GLOBALS['LOG_PER_RUN'];
// set the regex for checking emails
$this->email_regex = "^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,6}){1}$";
// this is for error check parts in where the email regex failed
@@ -326,7 +340,7 @@
// this has to be changed, not returned here, this is the last class to close
// return $this->error_msg;
// close open file handles
$this->fdebug_fp('c');
// $this->fdebug_fp('c');
}
// *************************************************************
@@ -598,7 +612,18 @@
// init base file path
$fn = ROOT.LOG.$this->log_print_file.'.'.$this->log_file_name_ext;
$rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file
if ($this->log_per_run)
{
if ($GLOBALS['LOG_FILE_UNIQUE_ID'])
$this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
if (!$this->log_file_unique_id)
$GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid(mt_rand(), true)), 0, 8);
$rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string
}
else
{
$rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file
}
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file

View File

@@ -344,6 +344,7 @@
$this->error_string['30'] = 'Query call in a possible endless loop. Was called more than '.$this->MAX_QUERY_CALL.' times';
$this->error_string['31'] = 'Could not fetch PK after query insert';
$this->error_string['32'] = 'Multiple PK return as array';
$this->error_string['33'] = 'returning PK was not found';
$this->error_string['40'] = 'Query async call failed.';
$this->error_string['41'] = 'Connection is busy with a different query. Cannot execute.';
$this->error_string['42'] = 'Cannot check for async query, none has been started yet.';
@@ -779,13 +780,20 @@
$this->insert_id = $this->insert_id[0][$this->pk_name];
}
}
elseif (count($this->insert_id) == 0)
{
// failed to get insert id
$this->insert_id = '';
$this->warning_id = 33;
$this->_db_error($this->cursor, '[db_exec]');
}
}
// this warning handling is only for pgsql
// we returned an array of PKs instread of a single one
if (is_array($this->insert_id))
{
$this->warning_id = 32;
$this->_db_error(print_r($this->insert_id), '[db_exec]');
$this->_db_error($this->cursor, '[db_exec]');
}
}
}
@@ -1514,7 +1522,7 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
if (is_array($this->insert_id))
{
$this->warning_id = 32;
$this->_db_error(print_r($this->insert_id));
$this->_db_error();
$this->_db_debug('db', '<span style="color: orange;"><b>DB-Warning</b> '.$stm_name.': insert id data returned as array</span>', 'DB_WARNING');
}
elseif (!$this->insert_id)

View File

@@ -90,6 +90,9 @@
// DESC : cunstroctuor, does ALL, opens db, works through connection checks, closes itself
public function __construct($db_config, $lang = 'en_utf8', $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// log login data for this class only
$this->log_per_class = 1;
// create db connection and init base class
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
@@ -100,9 +103,6 @@
exit;
}
// log login data for this class only
$this->log_per_class = 1;
// get the language sub class & init it
_spl_autoload('Class.l10n.inc');
$this->l = new l10n($lang);
@@ -1015,7 +1015,7 @@ EOM;
}
$q .= "'".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->username)."', NULL, '".$this->db_escape_string($this->login_error)."', NULL, NULL, '".$this->db_escape_string($this->permission_okay)."', NULL)";
$this->db_exec($q);
$this->db_exec($q, 'NULL');
}
// METHOD: login_check_edit_access_id