DbObject: add deleteAll() method

This commit is contained in:
Benjamin Renard 2024-09-19 20:01:41 +02:00
parent 5e7bdb1d3d
commit b1c5878608
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -6,6 +6,7 @@ use EesyPHP\Hook;
use EesyPHP\Log;
use function EesyPHP\implode_with_keys;
use function EesyPHP\vardump;
/**
* @property-read array<string,Attr> $_schema
@ -337,6 +338,30 @@ class DbObject {
return True;
}
/**
* Delete all matching objects
* @param array|string $where Where clauses as associative array of field name and value
* @return boolean
*/
public static function deleteAll($where) {
if (!is_array($where) || empty($where)) {
Log :: warning(
"%s::deleteAll(): invalid where clauses provided (%s)",
get_called_class(), vardump($where)
);
return false;
}
if (
!static :: DB_CLASS :: delete(
static :: TABLE,
static :: _compute_where_clauses($where),
false
)
)
return False;
return True;
}
/**
* List objects
* @param array<string,mixed> $where Where clauses as associative array of field name and value