27        include_once 
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
 
   29        if ($settings->enabledRbacLog()) {
 
   35    public static function gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action = 
false)
 
   39        $rbacreview = 
$DIC[
'rbacreview'];
 
   47        foreach ($a_role_ids as $role_id) {
 
   48            if ($role_id != SYSTEM_ROLE_ID) {
 
   50                    $result[
"ops"][$role_id][
"add"] = $rbacreview->getRoleOperationsOnObject($role_id, $a_ref_id);
 
   52                    $result[
"ops"][$role_id] = $rbacreview->getRoleOperationsOnObject($role_id, $a_ref_id);
 
   58        if ($a_ref_id && $a_ref_id != ROLE_FOLDER_ID) {
 
   60                $result[
"inht"][
"add"] = $rbacreview->getRolesOfRoleFolder($a_ref_id);
 
   62                $result[
"inht"] = $rbacreview->getRolesOfRoleFolder($a_ref_id);
 
   69    public static function diffFaPa(array $a_old, array $a_new)
 
   74        foreach ((array) $a_old[
"ops"] as $role_id => $ops) {
 
   75            $diff = array_diff($ops, $a_new[
"ops"][$role_id]);
 
   77                $result[
"ops"][$role_id][
"rmv"] = array_values($diff);
 
   79            $diff = array_diff($a_new[
"ops"][$role_id], $ops);
 
   81                $result[
"ops"][$role_id][
"add"] = array_values($diff);
 
   85        if (isset($a_old[
"inht"]) || isset($a_new[
"inht"])) {
 
   86            if (isset($a_old[
"inht"]) && !isset($a_new[
"inht"])) {
 
   87                $result[
"inht"][
"rmv"] = $a_old[
"inht"];
 
   88            } elseif (!isset($a_old[
"inht"]) && isset($a_new[
"inht"])) {
 
   89                $result[
"inht"][
"add"] = $a_new[
"inht"];
 
   91                $diff = array_diff($a_old[
"inht"], $a_new[
"inht"]);
 
   93                    $result[
"inht"][
"rmv"] = array_values($diff);
 
   95                $diff = array_diff($a_new[
"inht"], $a_old[
"inht"]);
 
   97                    $result[
"inht"][
"add"] = array_values($diff);
 
  109        $rbacreview = 
$DIC[
'rbacreview'];
 
  111        return $rbacreview->getAllOperationsOfRole($a_role_id, $a_role_ref_id);
 
  117        $types = array_unique(array_merge(array_keys($a_old), array_keys($a_new)));
 
  118        foreach ($types as 
$type) {
 
  119            if (!isset($a_old[
$type])) {
 
  121            } elseif (!isset($a_new[
$type])) {
 
  124                $diff = array_diff($a_old[
$type], $a_new[
$type]);
 
  128                $diff = array_diff($a_new[
$type], $a_old[
$type]);
 
  137    public static function add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id = 
false)
 
  144        if (self::isValidAction($a_action) && 
sizeof($a_diff)) {
 
  145            if ($a_source_ref_id) {
 
  146                $a_diff[
"src"] = $a_source_ref_id;
 
  148            $id = 
$ilDB->nextId(
'rbac_log');
 
  150            $ilDB->query(
"INSERT INTO rbac_log (log_id, user_id, created, ref_id, action, data)" .
 
  151                " VALUES (" . 
$ilDB->quote($id, 
"integer") . 
"," . 
$ilDB->quote(
$ilUser->getId(), 
"integer") .
 
  152                "," . 
$ilDB->quote(time(), 
"integer") .
 
  153                "," . 
$ilDB->quote($a_ref_id, 
"integer") . 
"," . 
$ilDB->quote($a_action, 
"integer") .
 
  154                "," . 
$ilDB->quote(serialize($a_diff), 
"text") . 
")");
 
  162        if (in_array($a_action, array(self::EDIT_PERMISSIONS, self::MOVE_OBJECT, self::LINK_OBJECT,
 
  163            self::COPY_OBJECT, self::CREATE_OBJECT, self::EDIT_TEMPLATE, self::EDIT_TEMPLATE_EXISTING,
 
  164            self::CHANGE_OWNER))) {
 
  170    public static function getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter = 
null)
 
  175        $rbacreview = 
$DIC[
'rbacreview'];
 
  179            if ($a_filter[
"action"]) {
 
  180                $where[] = 
"action = " . 
$ilDB->quote($a_filter[
"action"], 
"integer");
 
  182            if ($a_filter[
"date"][
"from"]) {
 
  183                $from = $a_filter[
"date"][
"from"]->get(
IL_CAL_UNIX);
 
  184                $from = strtotime(
"00:00:00", $from);
 
  185                $where[] = 
"created >= " . 
$ilDB->quote($from, 
"integer");
 
  187            if ($a_filter[
"date"][
"to"]) {
 
  189                $to = strtotime(
"23:59:59", $to);
 
  190                $where[] = 
"created <= " . 
$ilDB->quote($to, 
"integer");
 
  193            if (count($where) > 0) {
 
  194                $where = array_merge([
' AND '], [implode(
' AND ', $where)]);
 
  198        $set = 
$ilDB->query(
"SELECT COUNT(*) FROM rbac_log WHERE ref_id = " . 
$ilDB->quote($a_ref_id, 
"integer") . implode(
'', $where));
 
  199        $count = array_pop(
$ilDB->fetchAssoc($set));
 
  201        $ilDB->setLimit($a_limit, $a_offset);
 
  202        $set = 
$ilDB->query(
"SELECT * FROM rbac_log WHERE ref_id = " . 
$ilDB->quote($a_ref_id, 
"integer") .
 
  203            implode(
'', $where) . 
" ORDER BY created DESC");
 
  205        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  206            $row[
"data"] = unserialize($row[
"data"]);
 
  209        return array(
"cnt" => $count, 
"set" => 
$result);
 
  212    public static function delete($a_ref_id)
 
  218        $ilDB->query(
"DELETE FROM rbac_log WHERE ref_id = " . 
$ilDB->quote($a_ref_id, 
"integer"));
 
  229        include_once 
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
 
  231        $max = $settings->getRbacLogAge();
 
  233        $ilDB->query(
"DELETE FROM rbac_log WHERE created < " . 
$ilDB->quote(strtotime(
"-" . $max . 
"months"), 
"integer"));
 
An exception for terminatinating execution or to throw for unit testing.
static _getInstance()
Get instance of ilPrivacySettings.
class ilRbacLog Log changes in Rbac-related settings
static diffTemplate(array $a_old, array $a_new)
static getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter=null)
static diffFaPa(array $a_old, array $a_new)
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
static gatherTemplate($a_role_ref_id, $a_role_id)
const EDIT_TEMPLATE_EXISTING
static garbageCollection()
static gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action=false)
static isValidAction($a_action)