Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71c9fd401d | |||
| 0a885f215c | |||
| dad6b797e0 | |||
| 2d7c3c2bba | |||
| fb8216ae86 | |||
| df5070ffbb | |||
| 872409ef54 | |||
| c4d5cad9e8 | |||
| 90550746ab | |||
| 724031b944 |
@@ -1 +1 @@
|
|||||||
9.7.4
|
9.7.9
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class EditBase
|
|||||||
$q = "UPDATE " . $table_name
|
$q = "UPDATE " . $table_name
|
||||||
. " SET order_number = " . $row_data_order[$i]
|
. " SET order_number = " . $row_data_order[$i]
|
||||||
. " WHERE " . $table_name . "_id = " . $row_data_id[$i];
|
. " WHERE " . $table_name . "_id = " . $row_data_id[$i];
|
||||||
$q = $this->form->dbExec($q);
|
$q = $this->form->dba->dbExec($q);
|
||||||
}
|
}
|
||||||
} // for all article ids ...
|
} // for all article ids ...
|
||||||
} // if write
|
} // if write
|
||||||
@@ -173,7 +173,7 @@ class EditBase
|
|||||||
$options_name = [];
|
$options_name = [];
|
||||||
$options_selected = [];
|
$options_selected = [];
|
||||||
// DB read data for menu
|
// DB read data for menu
|
||||||
while (is_array($res = $this->form->dbReturn($q))) {
|
while (is_array($res = $this->form->dba->dbReturn($q))) {
|
||||||
$row_data[] = [
|
$row_data[] = [
|
||||||
"id" => $res[$table_name . "_id"],
|
"id" => $res[$table_name . "_id"],
|
||||||
"name" => $res["name"],
|
"name" => $res["name"],
|
||||||
@@ -431,9 +431,9 @@ class EditBase
|
|||||||
$elements[] = $this->form->formCreateElement('template');
|
$elements[] = $this->form->formCreateElement('template');
|
||||||
break;
|
break;
|
||||||
case 'edit_pages':
|
case 'edit_pages':
|
||||||
if (!isset($this->form->table_array['edit_page_id']['value'])) {
|
if (!isset($this->form->dba->getTableArray()['edit_page_id']['value'])) {
|
||||||
$q = "DELETE FROM temp_files";
|
$q = "DELETE FROM temp_files";
|
||||||
$this->form->dbExec($q);
|
$this->form->dba->dbExec($q);
|
||||||
// gets all files in the current dir and dirs given ending with .php
|
// gets all files in the current dir and dirs given ending with .php
|
||||||
$folders = ['../admin/', '../frontend/'];
|
$folders = ['../admin/', '../frontend/'];
|
||||||
$files = ['*.php'];
|
$files = ['*.php'];
|
||||||
@@ -461,16 +461,16 @@ class EditBase
|
|||||||
if ($t_q) {
|
if ($t_q) {
|
||||||
$t_q .= ', ';
|
$t_q .= ', ';
|
||||||
}
|
}
|
||||||
$t_q .= "('" . $this->form->dbEscapeString($pathinfo['dirname']) . "', '"
|
$t_q .= "('" . $this->form->dba->dbEscapeString($pathinfo['dirname']) . "', '"
|
||||||
. $this->form->dbEscapeString($pathinfo['basename']) . "')";
|
. $this->form->dba->dbEscapeString($pathinfo['basename']) . "')";
|
||||||
}
|
}
|
||||||
$this->form->dbExec($q . $t_q, 'NULL');
|
$this->form->dba->dbExec($q . $t_q, 'NULL');
|
||||||
$elements[] = $this->form->formCreateElement('filename');
|
$elements[] = $this->form->formCreateElement('filename');
|
||||||
} else {
|
} else {
|
||||||
// show file menu
|
// show file menu
|
||||||
// just show name of file ...
|
// just show name of file ...
|
||||||
$this->DATA['filename_exist'] = 1;
|
$this->DATA['filename_exist'] = 1;
|
||||||
$this->DATA['filename'] = $this->form->table_array['filename']['value'];
|
$this->DATA['filename'] = $this->form->dba->getTableArray()['filename']['value'];
|
||||||
} // File Name View IF
|
} // File Name View IF
|
||||||
$elements[] = $this->form->formCreateElement('hostname');
|
$elements[] = $this->form->formCreateElement('hostname');
|
||||||
$elements[] = $this->form->formCreateElement('name');
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
{
|
{
|
||||||
// main calss variables
|
// main calss variables
|
||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
public array $table_array; // the array from the table to work on
|
private array $table_array; // the array from the table to work on
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public string $table_name; // the table_name
|
private string $table_name; // the table_name
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public string $pk_name = ''; // the primary key from this table
|
private string $pk_name = ''; // the primary key from this table
|
||||||
/** @var int|string|null */
|
/** @var int|string|null */
|
||||||
public int|string|null $pk_id; // the PK id
|
private int|string|null $pk_id; // the PK id
|
||||||
// security values
|
// security values
|
||||||
/** @var int base acl for current page */
|
/** @var int base acl for current page */
|
||||||
private int $base_acl_level = 0;
|
private int $base_acl_level = 0;
|
||||||
@@ -74,24 +74,21 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
// instance db_io class
|
// instance db_io class
|
||||||
parent::__construct($db_config, $log);
|
parent::__construct($db_config, $log);
|
||||||
// more error vars for this class
|
// more error vars for this class
|
||||||
$this->error_string['1999'] = 'No table array or table name set';
|
$this->error_string['1998'] = 'No table name set';
|
||||||
|
$this->error_string['1999'] = 'No table array set';
|
||||||
$this->error_string['1021'] = 'No Primary Key given';
|
$this->error_string['1021'] = 'No Primary Key given';
|
||||||
$this->error_string['1022'] = 'Could not run Array Query';
|
$this->error_string['1022'] = 'Could not run Array Query';
|
||||||
|
|
||||||
$this->table_array = $table_array;
|
$this->setTableArray($table_array);
|
||||||
$this->table_name = $table_name;
|
$this->setTableName($table_name);
|
||||||
|
|
||||||
// error abort if no table array or no table name
|
|
||||||
if (empty($table_array) || empty($table_name)) {
|
|
||||||
$this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing');
|
|
||||||
throw new \RuntimeException('MAJOR ERROR: Core settings missing', 1999);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set primary key for given table_array
|
// set primary key for given table_array
|
||||||
foreach ($this->table_array as $key => $value) {
|
foreach ($this->table_array as $key => $value) {
|
||||||
if (!empty($value['pk'])) {
|
if (empty($value['pk'])) {
|
||||||
$this->pk_name = $key;
|
continue;
|
||||||
}
|
}
|
||||||
|
$this->setPkName($key);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$this->dbArrayIOSetAcl($base_acl_level, $acl_admin);
|
$this->dbArrayIOSetAcl($base_acl_level, $acl_admin);
|
||||||
}
|
}
|
||||||
@@ -104,6 +101,144 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
parent::__destruct();
|
parent::__destruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the overall table array
|
||||||
|
*
|
||||||
|
* @param array<mixed> $table_array
|
||||||
|
* @return void
|
||||||
|
* @throws \RuntimeException 1999 for empty table array
|
||||||
|
*/
|
||||||
|
public function setTableArray(array $table_array): void
|
||||||
|
{
|
||||||
|
$this->table_array = $table_array;
|
||||||
|
if (empty($this->table_array)) {
|
||||||
|
$this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing: table_arrry');
|
||||||
|
throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_array', 1999);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return full table array, or [] if empty
|
||||||
|
* of reset is set to true, will reset array first
|
||||||
|
*
|
||||||
|
* @param bool $reset [=false] run a reset before returning
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function getTableArray(bool $reset = false): array
|
||||||
|
{
|
||||||
|
if (!$reset) {
|
||||||
|
return $this->table_array ?? [];
|
||||||
|
}
|
||||||
|
$table_array = $this->table_array ?? [];
|
||||||
|
reset($table_array);
|
||||||
|
return $table_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a table array entry under the key with element pos
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getTableArrayEntry(string $key, string $pos): mixed
|
||||||
|
{
|
||||||
|
return $this->table_array[$key][$pos] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set a new value at key with pos
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTableArrayEntry(mixed $value, string $key, string $pos): void
|
||||||
|
{
|
||||||
|
$this->table_array[$key][$pos] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unset entry at key with pos
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unsetTableArrayEntry(string $key, string $pos): void
|
||||||
|
{
|
||||||
|
unset($this->table_array[$key][$pos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set table name
|
||||||
|
*
|
||||||
|
* @param string $table_name
|
||||||
|
* @return void
|
||||||
|
* @throws \RuntimeException 1998 for empty table name
|
||||||
|
*/
|
||||||
|
public function setTableName(string $table_name): void
|
||||||
|
{
|
||||||
|
$this->table_name = $table_name;
|
||||||
|
if (empty($this->table_name)) {
|
||||||
|
$this->__dbError(1998, false, 'MAJOR ERROR: Core settings missing: table_name');
|
||||||
|
throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_name', 1998);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return table name or empty string if not net
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTableName(): string
|
||||||
|
{
|
||||||
|
return $this->table_name ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set primary key name
|
||||||
|
*
|
||||||
|
* @param string $pk_name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPkName(string $pk_name): void
|
||||||
|
{
|
||||||
|
$this->pk_name = $pk_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get primary key name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPkName(): string
|
||||||
|
{
|
||||||
|
return $this->pk_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set primary key id, can be null for not yet set
|
||||||
|
*
|
||||||
|
* @param int|string|null $pk_id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPkId(int|string|null $pk_id): void
|
||||||
|
{
|
||||||
|
$this->pk_id = $pk_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return primary key id, or null if not set
|
||||||
|
*
|
||||||
|
* @return int|string|null
|
||||||
|
*/
|
||||||
|
public function getPkId(): int|string|null
|
||||||
|
{
|
||||||
|
return $this->pk_id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the base acl level and admin acl flag
|
* set the base acl level and admin acl flag
|
||||||
* This is needed for table array ACL checks
|
* This is needed for table array ACL checks
|
||||||
@@ -198,8 +333,8 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
public function dbCheckPkSet(): bool
|
public function dbCheckPkSet(): bool
|
||||||
{
|
{
|
||||||
// if pk_id is set, overrule ...
|
// if pk_id is set, overrule ...
|
||||||
if ($this->pk_id) {
|
if (!empty($this->getPkId())) {
|
||||||
$this->table_array[$this->pk_name]['value'] = $this->pk_id;
|
$this->table_array[$this->pk_name]['value'] = $this->getPkId();
|
||||||
}
|
}
|
||||||
// if not set ... produce error
|
// if not set ... produce error
|
||||||
if (!$this->table_array[$this->pk_name]['value']) {
|
if (!$this->table_array[$this->pk_name]['value']) {
|
||||||
@@ -287,7 +422,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$q .= ' AND ' . $q_where;
|
$q .= ' AND ' . $q_where;
|
||||||
}
|
}
|
||||||
// if 0, error
|
// if 0, error
|
||||||
$this->pk_id = null;
|
$this->setPkId(null);
|
||||||
if (!$this->dbExec($q)) {
|
if (!$this->dbExec($q)) {
|
||||||
$this->__dbError(1022);
|
$this->__dbError(1022);
|
||||||
}
|
}
|
||||||
@@ -374,7 +509,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// possible dbFetchArray errors ...
|
// possible dbFetchArray errors ...
|
||||||
$this->pk_id = $this->table_array[$this->pk_name]['value'];
|
$this->setPkId($this->table_array[$this->pk_name]['value']);
|
||||||
} else {
|
} else {
|
||||||
$this->__dbError(1022);
|
$this->__dbError(1022);
|
||||||
}
|
}
|
||||||
@@ -397,10 +532,6 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
if (count($table_array)) {
|
if (count($table_array)) {
|
||||||
$this->table_array = $table_array;
|
$this->table_array = $table_array;
|
||||||
}
|
}
|
||||||
// PK ID check
|
|
||||||
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"]) {
|
|
||||||
// $this->table_array[$this->pk_name]["value"]=$this->pk_id;
|
|
||||||
// }
|
|
||||||
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
|
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
|
||||||
if (!$this->table_array[$this->pk_name]['value']) {
|
if (!$this->table_array[$this->pk_name]['value']) {
|
||||||
$insert = 1;
|
$insert = 1;
|
||||||
@@ -624,16 +755,11 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$q .= ' AND ' . $q_where;
|
$q .= ' AND ' . $q_where;
|
||||||
}
|
}
|
||||||
// set pk_id ... if it has changed or so
|
// set pk_id ... if it has changed or so
|
||||||
$this->pk_id = $this->table_array[$this->pk_name]['value'];
|
$this->setPkId($this->table_array[$this->pk_name]['value']);
|
||||||
} else {
|
} else {
|
||||||
$q = 'INSERT INTO ' . $this->table_name . ' ';
|
$q = 'INSERT INTO ' . $this->table_name . ' ';
|
||||||
$q .= '(' . $q_vars . ') ';
|
$q .= '(' . $q_vars . ') ';
|
||||||
$q .= 'VALUES (' . $q_data . ')';
|
$q .= 'VALUES (' . $q_data . ')';
|
||||||
// write primary key too
|
|
||||||
// if ($q_data)
|
|
||||||
// $q .= ", ";
|
|
||||||
// $q .= $this->pk_name." = ".$this->table_array[$this->pk_name]['value']." ";
|
|
||||||
// $this->pk_id = $this->table_array[$this->pk_name]['value'];
|
|
||||||
}
|
}
|
||||||
// return success or not
|
// return success or not
|
||||||
if (!$this->dbExec($q)) {
|
if (!$this->dbExec($q)) {
|
||||||
@@ -646,7 +772,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$insert_id = 0;
|
$insert_id = 0;
|
||||||
}
|
}
|
||||||
$this->table_array[$this->pk_name]['value'] = $insert_id;
|
$this->table_array[$this->pk_name]['value'] = $insert_id;
|
||||||
$this->pk_id = $insert_id;
|
$this->setPkId($insert_id);
|
||||||
}
|
}
|
||||||
// return the table if needed
|
// return the table if needed
|
||||||
return $this->table_array;
|
return $this->table_array;
|
||||||
|
|||||||
@@ -3232,7 +3232,7 @@ class IO
|
|||||||
*
|
*
|
||||||
* @param array<mixed> $write_array list of elements to write
|
* @param array<mixed> $write_array list of elements to write
|
||||||
* @param array<mixed> $not_write_array list of elements not to write
|
* @param array<mixed> $not_write_array list of elements not to write
|
||||||
* @param int $primary_key id key to decide if we write insert or update
|
* @param int|null $primary_key id key to decide if we write insert or update
|
||||||
* @param string $table name for the target table
|
* @param string $table name for the target table
|
||||||
* @param array<mixed> $data data array to override _POST data
|
* @param array<mixed> $data data array to override _POST data
|
||||||
* @return int|false primary key
|
* @return int|false primary key
|
||||||
@@ -3240,7 +3240,7 @@ class IO
|
|||||||
public function dbWriteData(
|
public function dbWriteData(
|
||||||
array $write_array,
|
array $write_array,
|
||||||
array $not_write_array,
|
array $not_write_array,
|
||||||
int $primary_key,
|
?int $primary_key,
|
||||||
string $table,
|
string $table,
|
||||||
array $data = []
|
array $data = []
|
||||||
): int|false {
|
): int|false {
|
||||||
@@ -3260,19 +3260,19 @@ class IO
|
|||||||
* PARAM INFO: $primary key
|
* PARAM INFO: $primary key
|
||||||
* this can be a plain string/int and will be internal transformed into the array form
|
* this can be a plain string/int and will be internal transformed into the array form
|
||||||
* or it takes the array form of array [row => column, value => pk value]
|
* or it takes the array form of array [row => column, value => pk value]
|
||||||
* @param array<mixed> $write_array list of elements to write
|
* @param array<mixed> $write_array list of elements to write
|
||||||
* @param int|string|array<mixed> $primary_key primary key string or array set
|
* @param null|int|string|array<mixed> $primary_key primary key string or array set
|
||||||
* @param string $table name for the target table
|
* @param string $table name for the target table
|
||||||
* @param array<mixed> $not_write_array list of elements not to write (optional)
|
* @param array<mixed> $not_write_array list of elements not to write (optional)
|
||||||
* @param array<mixed> $not_write_update_array list of elements not
|
* @param array<mixed> $not_write_update_array list of elements not
|
||||||
* to write during update (optional)
|
* to write during update (optional)
|
||||||
* @param array<mixed> $data optional array with data
|
* @param array<mixed> $data optional array with data
|
||||||
* if not _POST vars are used
|
* if not _POST vars are used
|
||||||
* @return int|false primary key
|
* @return int|false primary key
|
||||||
*/
|
*/
|
||||||
public function dbWriteDataExt(
|
public function dbWriteDataExt(
|
||||||
array $write_array,
|
array $write_array,
|
||||||
int|string|array $primary_key,
|
null|int|string|array $primary_key,
|
||||||
string $table,
|
string $table,
|
||||||
array $not_write_array = [],
|
array $not_write_array = [],
|
||||||
array $not_write_update_array = [],
|
array $not_write_update_array = [],
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class ErrorMessage
|
|||||||
{
|
{
|
||||||
/** @var array<int,array{id:string,level:string,str:string,target:string,target_style:string,highlight:string[]}> */
|
/** @var array<int,array{id:string,level:string,str:string,target:string,target_style:string,highlight:string[]}> */
|
||||||
private array $error_str = [];
|
private array $error_str = [];
|
||||||
|
/** @var array<string,string> */
|
||||||
|
private array $jump_targets;
|
||||||
/** @var \CoreLibs\Logging\Logging $log */
|
/** @var \CoreLibs\Logging\Logging $log */
|
||||||
public \CoreLibs\Logging\Logging $log;
|
public \CoreLibs\Logging\Logging $log;
|
||||||
|
|
||||||
@@ -27,13 +29,19 @@ class ErrorMessage
|
|||||||
* init ErrorMessage
|
* init ErrorMessage
|
||||||
*
|
*
|
||||||
* @param \CoreLibs\Logging\Logging $log
|
* @param \CoreLibs\Logging\Logging $log
|
||||||
* @param bool $log_error [=false]
|
* @param null|bool $log_error [=null], defaults to false if log is not level debug
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\Logging\Logging $log,
|
\CoreLibs\Logging\Logging $log,
|
||||||
bool $log_error = false
|
?bool $log_error = null
|
||||||
) {
|
) {
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
// if log default logging is debug then log_error is default set to true
|
||||||
|
if ($this->log->loggingLevelIsDebug() && $log_error === null) {
|
||||||
|
$log_error = true;
|
||||||
|
} else {
|
||||||
|
$log_error = $log_error ?? false;
|
||||||
|
}
|
||||||
$this->log_error = $log_error;
|
$this->log_error = $log_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +50,7 @@ class ErrorMessage
|
|||||||
* error_id: internal Error ID (should be unique)
|
* error_id: internal Error ID (should be unique)
|
||||||
* level: error level, can only be ok, info, warn, error, abort, crash
|
* level: error level, can only be ok, info, warn, error, abort, crash
|
||||||
* ok and info are positive response: success
|
* ok and info are positive response: success
|
||||||
|
* notice: a debug message for information only
|
||||||
* warn: success, but there might be some things that are not 100% ok
|
* warn: success, but there might be some things that are not 100% ok
|
||||||
* error: input error or error in executing request
|
* error: input error or error in executing request
|
||||||
* abort: an internal error happened as mandatory information that normally is
|
* abort: an internal error happened as mandatory information that normally is
|
||||||
@@ -54,6 +63,8 @@ class ErrorMessage
|
|||||||
* highlight is a list of other target points to highlight
|
* highlight is a list of other target points to highlight
|
||||||
* for highlight targets css names are $level without a prefix and should be
|
* for highlight targets css names are $level without a prefix and should be
|
||||||
* nested in the target element "input .error { ... }"
|
* nested in the target element "input .error { ... }"
|
||||||
|
* jump_target: a target id for to jump and message, is stored in separate jump array
|
||||||
|
* where the target is unique, first one set is used for info message
|
||||||
* target_style: if not set uses 'error-' $level as css style. applies to targets or main only
|
* target_style: if not set uses 'error-' $level as css style. applies to targets or main only
|
||||||
*
|
*
|
||||||
* @param string $error_id Any internal error ID for this error
|
* @param string $error_id Any internal error ID for this error
|
||||||
@@ -63,6 +74,9 @@ class ErrorMessage
|
|||||||
* @param string $target_style Alternate color style for the error message
|
* @param string $target_style Alternate color style for the error message
|
||||||
* @param array<string> $highlight Any additional error data as error OR
|
* @param array<string> $highlight Any additional error data as error OR
|
||||||
* highlight points for field highlights
|
* highlight points for field highlights
|
||||||
|
* @param array{}|array{target:string,info?:string} $jump_target with "target" for where to jump and
|
||||||
|
* "info" for string to show in jump list
|
||||||
|
* target must be set, if info not set, default message used
|
||||||
* @param string|null $message If abort/crash, non localized $str
|
* @param string|null $message If abort/crash, non localized $str
|
||||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||||
@@ -75,6 +89,7 @@ class ErrorMessage
|
|||||||
string $target = '',
|
string $target = '',
|
||||||
string $target_style = '',
|
string $target_style = '',
|
||||||
array $highlight = [],
|
array $highlight = [],
|
||||||
|
array $jump_target = [],
|
||||||
?string $message = null,
|
?string $message = null,
|
||||||
array $context = [],
|
array $context = [],
|
||||||
?bool $log_error = null,
|
?bool $log_error = null,
|
||||||
@@ -96,8 +111,16 @@ class ErrorMessage
|
|||||||
'target_style' => $target_style,
|
'target_style' => $target_style,
|
||||||
'highlight' => $highlight,
|
'highlight' => $highlight,
|
||||||
];
|
];
|
||||||
|
// set a jump target
|
||||||
|
$this->setJumpTarget($jump_target['target'] ?? null, $jump_target['info'] ?? null);
|
||||||
// write to log for abort/crash
|
// write to log for abort/crash
|
||||||
switch ($level) {
|
switch ($level) {
|
||||||
|
case 'notice':
|
||||||
|
$this->log->notice($message ?? $str, array_merge([
|
||||||
|
'id' => $error_id,
|
||||||
|
'level' => $original_level,
|
||||||
|
], $context));
|
||||||
|
break;
|
||||||
case 'error':
|
case 'error':
|
||||||
if ($log_error) {
|
if ($log_error) {
|
||||||
$this->log->error($message ?? $str, array_merge([
|
$this->log->error($message ?? $str, array_merge([
|
||||||
@@ -139,6 +162,9 @@ class ErrorMessage
|
|||||||
* @param string $target_style Alternate color style for the error message
|
* @param string $target_style Alternate color style for the error message
|
||||||
* @param array<string> $highlight Any additional error data as error OR
|
* @param array<string> $highlight Any additional error data as error OR
|
||||||
* highlight points for field highlights
|
* highlight points for field highlights
|
||||||
|
* @param array{}|array{target:string,info?:string} $jump_target with "target" for where to jump and
|
||||||
|
* "info" for string to show in jump list
|
||||||
|
* target must be set, if info not set, default message used
|
||||||
* @param string|null $message If abort/crash, non localized $str
|
* @param string|null $message If abort/crash, non localized $str
|
||||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||||
@@ -151,6 +177,7 @@ class ErrorMessage
|
|||||||
string $target = '',
|
string $target = '',
|
||||||
string $target_style = '',
|
string $target_style = '',
|
||||||
array $highlight = [],
|
array $highlight = [],
|
||||||
|
array $jump_target = [],
|
||||||
?string $message = null,
|
?string $message = null,
|
||||||
array $context = [],
|
array $context = [],
|
||||||
?bool $log_error = null,
|
?bool $log_error = null,
|
||||||
@@ -162,12 +189,38 @@ class ErrorMessage
|
|||||||
$target,
|
$target,
|
||||||
$target_style,
|
$target_style,
|
||||||
$highlight,
|
$highlight,
|
||||||
|
$jump_target,
|
||||||
$message,
|
$message,
|
||||||
$context,
|
$context,
|
||||||
$log_error
|
$log_error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a jump target. This can be used to jump directly a frontend html block
|
||||||
|
* with the target id set
|
||||||
|
*
|
||||||
|
* @param string|null $target
|
||||||
|
* @param string|null $info
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setJumpTarget(
|
||||||
|
?string $target,
|
||||||
|
?string $info,
|
||||||
|
): void {
|
||||||
|
if (
|
||||||
|
empty($target) ||
|
||||||
|
!empty($this->jump_targets[$target])
|
||||||
|
// also check if this is an alphanumeric string? css id compatible?
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (empty($info)) {
|
||||||
|
$info = 'Jump to: ' . $target;
|
||||||
|
}
|
||||||
|
$this->jump_targets[$target] = $info;
|
||||||
|
}
|
||||||
|
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
// GETTERS
|
// GETTERS
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
@@ -210,6 +263,16 @@ class ErrorMessage
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the jump target list
|
||||||
|
*
|
||||||
|
* @return array{}|array{string,string} List of jump targets with info text, or empty array if not set
|
||||||
|
*/
|
||||||
|
public function getJumpTarget(): array
|
||||||
|
{
|
||||||
|
return $this->jump_targets ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
// FLAG SETTERS
|
// FLAG SETTERS
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ enum MessageLevel: int
|
|||||||
{
|
{
|
||||||
case ok = 100;
|
case ok = 100;
|
||||||
case info = 200;
|
case info = 200;
|
||||||
|
case notice = 250;
|
||||||
case warn = 300;
|
case warn = 300;
|
||||||
case error = 400;
|
case error = 400;
|
||||||
case abort = 500;
|
case abort = 500;
|
||||||
@@ -30,6 +31,7 @@ enum MessageLevel: int
|
|||||||
return match (strtolower($name)) {
|
return match (strtolower($name)) {
|
||||||
'ok' => self::ok,
|
'ok' => self::ok,
|
||||||
'info' => self::info,
|
'info' => self::info,
|
||||||
|
'notice' => self::notice,
|
||||||
'warn', 'warning' => self::warn,
|
'warn', 'warning' => self::warn,
|
||||||
'error' => self::error,
|
'error' => self::error,
|
||||||
'abort' => self::abort,
|
'abort' => self::abort,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'str' => 'INFO',
|
'str' => 'INFO',
|
||||||
'expected' => 'info',
|
'expected' => 'info',
|
||||||
],
|
],
|
||||||
|
'notice' => [
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE',
|
||||||
|
'expected' => 'notice',
|
||||||
|
],
|
||||||
'warn' => [
|
'warn' => [
|
||||||
'level' => 'warn',
|
'level' => 'warn',
|
||||||
'str' => 'WARN',
|
'str' => 'WARN',
|
||||||
@@ -91,9 +96,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
public function testErrorMessageLevelOk(string $level, string $str, string $expected): void
|
public function testErrorMessageLevelOk(string $level, string $str, string $expected): void
|
||||||
{
|
{
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
'log_file_id' => 'testErrorMessages',
|
'log_file_id' => 'testErrorMessagesLevelOk',
|
||||||
'log_folder' => self::LOG_FOLDER,
|
'log_folder' => self::LOG_FOLDER,
|
||||||
'log_level' => Level::Debug,
|
'log_level' => Level::Error,
|
||||||
]);
|
]);
|
||||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
$em->setMessage(
|
$em->setMessage(
|
||||||
@@ -123,9 +128,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
public function testErrorMessageOk(): void
|
public function testErrorMessageOk(): void
|
||||||
{
|
{
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
'log_file_id' => 'testErrorMessages',
|
'log_file_id' => 'testErrorMessagesOk',
|
||||||
'log_folder' => self::LOG_FOLDER,
|
'log_folder' => self::LOG_FOLDER,
|
||||||
'log_level' => Level::Debug
|
'log_level' => Level::Error
|
||||||
]);
|
]);
|
||||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
$em->setErrorMsg(
|
$em->setErrorMsg(
|
||||||
@@ -238,6 +243,22 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'log_error' => true,
|
'log_error' => true,
|
||||||
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||||
],
|
],
|
||||||
|
'notice' => [
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'expected' => '<NOTICE> NOTICE MESSAGE',
|
||||||
|
],
|
||||||
|
'notice, message' => [
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE MESSAGE',
|
||||||
|
'message' => 'OTHER NOTICE MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
|
||||||
|
],
|
||||||
'crash' => [
|
'crash' => [
|
||||||
'id' => '300',
|
'id' => '300',
|
||||||
'level' => 'crash',
|
'level' => 'crash',
|
||||||
@@ -293,7 +314,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @dataProvider providerErrorMessageLog
|
* @dataProvider providerErrorMessageLog
|
||||||
* @testdox Test Log writing [$_dataName]
|
* @testdox Test Log writing with log level Error [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $level
|
* @param string $level
|
||||||
@@ -303,7 +324,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testErrorMessageLog(
|
public function testErrorMessageLogErrorLevel(
|
||||||
string $id,
|
string $id,
|
||||||
string $level,
|
string $level,
|
||||||
string $str,
|
string $str,
|
||||||
@@ -312,7 +333,63 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
string $expected
|
string $expected
|
||||||
): void {
|
): void {
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
'log_file_id' => 'testErrorMessages',
|
'log_file_id' => 'testErrorMessagesLogError',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Notice,
|
||||||
|
'log_per_run' => true
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setErrorMsg(
|
||||||
|
$id,
|
||||||
|
$level,
|
||||||
|
$str,
|
||||||
|
message: $message,
|
||||||
|
log_error: $log_error
|
||||||
|
);
|
||||||
|
$file_content = '';
|
||||||
|
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
}
|
||||||
|
// if error, if null or false, it will not be logged
|
||||||
|
if ($level == 'error' && ($log_error === null || $log_error === false)) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider providerErrorMessageLog
|
||||||
|
* @testdox Test Log writing with log Level Debug [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $level
|
||||||
|
* @param string $str
|
||||||
|
* @param string|null $message
|
||||||
|
* @param bool|null $log_error
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErrorMessageLogErrorDebug(
|
||||||
|
string $id,
|
||||||
|
string $level,
|
||||||
|
string $str,
|
||||||
|
?string $message,
|
||||||
|
?bool $log_error,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||||
'log_folder' => self::LOG_FOLDER,
|
'log_folder' => self::LOG_FOLDER,
|
||||||
'log_level' => Level::Debug,
|
'log_level' => Level::Debug,
|
||||||
'log_per_run' => true
|
'log_per_run' => true
|
||||||
@@ -331,8 +408,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
$log->getLogFolder() . $log->getLogFile()
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
) ?: '';
|
) ?: '';
|
||||||
}
|
}
|
||||||
// if n
|
// if error, and log is debug level, only explicit false are not logged
|
||||||
if ($level == 'error' && ($log_error === null || $log_error === false)) {
|
if ($level == 'error' && $log_error === false) {
|
||||||
$this->assertStringNotContainsString(
|
$this->assertStringNotContainsString(
|
||||||
$expected,
|
$expected,
|
||||||
$file_content
|
$file_content
|
||||||
@@ -344,6 +421,70 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox Test jump target set and reporting
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testJumpTarget(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_per_run' => true
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-f',
|
||||||
|
'Target text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'target-f' => 'Target text'
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// set same target, keep as before
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-f',
|
||||||
|
'Other text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'target-f' => 'Target text'
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// add new now two messages
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-s',
|
||||||
|
'More text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'target-f' => 'Target text',
|
||||||
|
'target-s' => 'More text'
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// add empty info
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-e',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'target-f' => 'Target text',
|
||||||
|
'target-s' => 'More text',
|
||||||
|
'target-e' => 'Jump to: target-e'
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
Reference in New Issue
Block a user