Allow enable or disable cache in Entity and some minor fixes

This commit is contained in:
fbsanchez 2021-09-30 12:23:37 +02:00
parent 18b1a1e14e
commit 9dff230b65
6 changed files with 31 additions and 13 deletions

View File

@ -248,7 +248,11 @@ class CredentialStore extends Wizard
);
} else {
$groups = [ $filter['filter_id_group'] ];
$childrens = groups_get_children($id_group, null, true);
$childrens = groups_get_children(
$filter['filter_id_group'],
null,
true
);
if (!empty($childrens)) {
foreach ($childrens as $child) {
$groups[] = (int) $child['id_grupo'];
@ -353,6 +357,10 @@ class CredentialStore extends Wizard
$return = db_get_all_rows_sql($sql);
if ($return === false) {
$return = [];
}
// Filter out those items of group all that cannot be edited by user.
$return = array_filter(
$return,

View File

@ -883,7 +883,7 @@ function mysql_db_get_row_sql($sql, $search_history_db=false, $cache=true)
*
* @return mixed Array of the row or false in case of error.
*/
function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $historydb=false)
function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $historydb=false, $cache=true)
{
if (empty($fields)) {
$fields = '*';
@ -905,7 +905,7 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN
$sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter);
return db_get_row_sql($sql, $historydb);
return db_get_row_sql($sql, $historydb, $cache);
}

View File

@ -1041,7 +1041,7 @@ function oracle_db_get_row_sql($sql, $search_history_db=false, $cache=true)
*
* @return mixed Array of the row or false in case of error.
*/
function oracle_db_get_row_filter($table, $filter, $fields=false, $where_join='AND')
function oracle_db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $history_db=false, $cache=true)
{
if (empty($fields)) {
$fields = '*';
@ -1063,7 +1063,7 @@ function oracle_db_get_row_filter($table, $filter, $fields=false, $where_join='A
$sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter);
return db_get_row_sql($sql);
return db_get_row_sql($sql, $history_db, $cache);
}

View File

@ -750,7 +750,7 @@ function postgresql_db_get_row_sql($sql, $search_history_db=false, $cache=true)
*
* @return mixed Array of the row or false in case of error.
*/
function postgresql_db_get_row_filter($table, $filter, $fields=false, $where_join='AND')
function postgresql_db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $historydb=false, $cache=true)
{
if (empty($fields)) {
$fields = '*';
@ -772,7 +772,7 @@ function postgresql_db_get_row_filter($table, $filter, $fields=false, $where_joi
$sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter);
return db_get_row_sql($sql);
return db_get_row_sql($sql, $historydb, $cache);
}

View File

@ -518,24 +518,25 @@ function db_get_row($table, $field_search, $condition, $fields=false, $cache=tru
* @param mixed Fields of the table to retrieve. Can be an array or a coma
* separated string. All fields are retrieved by default
* @param string Condition to join the filters (AND, OR).
* @param boolean $cache Use cache or not.
*
* @return mixed Array of the row or false in case of error.
*/
function db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $historydb=false)
function db_get_row_filter($table, $filter, $fields=false, $where_join='AND', $historydb=false, $cache=true)
{
global $config;
switch ($config['dbtype']) {
case 'mysql':
return mysql_db_get_row_filter($table, $filter, $fields, $where_join, $historydb);
return mysql_db_get_row_filter($table, $filter, $fields, $where_join, $historydb, $cache);
break;
case 'postgresql':
return postgresql_db_get_row_filter($table, $filter, $fields, $where_join);
return postgresql_db_get_row_filter($table, $filter, $fields, $where_join, $historydb, $cache);
break;
case 'oracle':
return oracle_db_get_row_filter($table, $filter, $fields, $where_join);
return oracle_db_get_row_filter($table, $filter, $fields, $where_join, $historydb, $cache);
break;
}

View File

@ -98,13 +98,15 @@ abstract class Entity
* @param string $table Table.
* @param array|null $filters Filters, for instance ['id' => $id].
* @param string|null $enterprise_class Enterprise class name.
* @param boolean $cache Use cache or not.
*
* @throws \Exception On error.
*/
public function __construct(
string $table,
?array $filters=null,
?string $enterprise_class=null
?string $enterprise_class=null,
bool $cache=true
) {
if (empty($table) === true) {
throw new \Exception(
@ -116,7 +118,14 @@ abstract class Entity
if (is_array($filters) === true) {
// New one.
$data = \db_get_row_filter($this->table, $filters);
$data = \db_get_row_filter(
$this->table,
$filters,
false,
'AND',
false,
$cache
);
if ($data === false) {
throw new \Exception(