19 declare(strict_types=1);
54 $set = $this->db->query(
55 'SELECT * FROM ' . self::LOG_TABLE_NAME
60 static fn(
string $ret,
string $key,
string $value):
string =>
61 $ret ===
' ORDER BY ' ?
"{$ret} {$key} {$value}" :
"{$ret}, {$key} {$value} " 65 while ($row = $this->db->fetchAssoc($set)) {
66 $row[
'data'] = unserialize($row[
'data'], [
false]);
76 $result = $this->db->fetchObject(
78 'SELECT COUNT(*) as cnt FROM ' . self::LOG_TABLE_NAME .
' WHERE ref_id = ' 90 if ($filter ===
null) {
95 if (isset($filter[
'action'])) {
96 $where[] =
' ' . $this->db->in(
103 if (isset($filter[
'from'])) {
104 $where[] =
' created >= ' . $this->db->quote(
109 if (isset($filter[
'to'])) {
110 $where[] =
' created <= ' . $this->db->quote(
116 if (count($where) > 0) {
117 $where = array_merge([
' AND '], [implode(
' AND ', $where)]);
119 return implode(
'', $where);
127 public static function gatherFaPa(
int $ref_id, array $role_ids,
bool $add_action =
false): array
131 $rbacreview = $DIC->rbac()->review();
138 foreach ($role_ids as $role_id) {
141 $result[
"ops"][$role_id][
"add"] = $rbacreview->getRoleOperationsOnObject($role_id, $ref_id);
143 $result[
"ops"][$role_id] = $rbacreview->getRoleOperationsOnObject($role_id, $ref_id);
151 $result[
"inht"][
"add"] = $rbacreview->getRolesOfRoleFolder($ref_id);
153 $result[
"inht"] = $rbacreview->getRolesOfRoleFolder($ref_id);
160 public static function diffFaPa(array $old, array $new): array
165 foreach ((array) $old[
"ops"] as $role_id => $ops) {
166 $diff = array_diff($ops, $new[
"ops"][$role_id]);
168 $result[
"ops"][$role_id][
"rmv"] = array_values($diff);
170 $diff = array_diff($new[
"ops"][$role_id], $ops);
172 $result[
"ops"][$role_id][
"add"] = array_values($diff);
176 if (isset($old[
"inht"]) || isset($new[
"inht"])) {
177 if (isset($old[
"inht"]) && !isset($new[
"inht"])) {
178 $result[
"inht"][
"rmv"] = $old[
"inht"];
179 } elseif (!isset($old[
"inht"]) && isset($new[
"inht"])) {
180 $result[
"inht"][
"add"] = $new[
"inht"];
182 $diff = array_diff($old[
"inht"], $new[
"inht"]);
184 $result[
"inht"][
"rmv"] = array_values($diff);
186 $diff = array_diff($new[
"inht"], $old[
"inht"]);
188 $result[
"inht"][
"add"] = array_values($diff);
199 $rbacreview = $DIC->rbac()->review();
200 return $rbacreview->getAllOperationsOfRole($role_id, $role_ref_id);
206 $types = array_unique(array_merge(array_keys($old), array_keys($new)));
207 foreach ($types as $type) {
208 if (!isset($old[$type])) {
209 $result[$type][
"add"] = $new[$type];
210 } elseif (!isset($new[$type])) {
211 $result[$type][
"rmv"] = $old[$type];
213 $diff = array_diff($old[$type], $new[$type]);
215 $result[$type][
"rmv"] = array_values($diff);
217 $diff = array_diff($new[$type], $old[$type]);
219 $result[$type][
"add"] = array_values($diff);
226 public static function add(
int $action,
int $ref_id, array $diff,
bool $source_ref_id =
false): bool
230 $ilUser = $DIC->user();
231 $ilDB = $DIC->database();
233 if (self::isValidAction($action) && count($diff)) {
234 if ($source_ref_id) {
235 $diff[
"src"] = $source_ref_id;
237 $id =
$ilDB->nextId(self::LOG_TABLE_NAME);
239 $ilDB->query(
'INSERT INTO ' . self::LOG_TABLE_NAME .
' (log_id, user_id, created, ref_id, action, data)' .
240 " VALUES (" .
$ilDB->quote(
$id,
"integer") .
"," .
$ilDB->quote($ilUser->getId(),
"integer") .
241 "," .
$ilDB->quote(time(),
"integer") .
242 "," .
$ilDB->quote($ref_id,
"integer") .
"," .
$ilDB->quote($action,
"integer") .
243 "," .
$ilDB->quote(serialize($diff),
"text") .
")");
254 self::EDIT_PERMISSIONS,
260 self::EDIT_TEMPLATE_EXISTING,
269 public static function delete(
int $ref_id):
void 273 $ilDB = $DIC->database();
274 $ilDB->query(
'DELETE FROM ' . self::LOG_TABLE_NAME .
' WHERE ref_id = ' .
$ilDB->quote(
$ref_id,
'integer'));
275 self::garbageCollection();
282 $ilDB = $DIC->database();
285 $max = $settings->getRbacLogAge();
287 $ilDB->query(
'DELETE FROM ' . self::LOG_TABLE_NAME .
' WHERE created < ' .
$ilDB->quote(
288 strtotime(
"-" . $max .
"months"),
join($init, callable $fn)
static garbageCollection()
getWhereForFilter(?array $filter)
getLogItemsCount(int $ref_id, array $filter)
static isValidAction(int $action)
Both the subject and the direction need to be specified when expressing an order. ...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static gatherFaPa(int $ref_id, array $role_ids, bool $add_action=false)
getLogItems(int $ref_id, Range $range, Order $order, ?array $filter)
static gatherTemplate(int $role_ref_id, int $role_id)
static add(int $action, int $ref_id, array $diff, bool $source_ref_id=false)
static diffFaPa(array $old, array $new)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static diffTemplate(array $old, array $new)
const EDIT_TEMPLATE_EXISTING
__construct(private readonly ilDBInterface $db)
class ilRbacLog Log changes in Rbac-related settings
A simple class to express a naive range of whole positive numbers.