ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.HistoryDBRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
27 {
28  protected \ilDBInterface $db;
29 
30  public function __construct(\ilDBInterface $db)
31  {
32  $this->db = $db;
33  }
34 
39  public function getMaxHistEntryPerPageOlderThanX(int $xdays): \Iterator
40  {
41  $db = $this->db;
42 
43  $hdate = new \ilDateTime(date("Y-m-d H:i:s"), IL_CAL_DATETIME);
44  $hdate->increment(\ilDateTime::DAY, (-1 * $xdays));
45 
46  $set = $db->queryF(
47  "SELECT MAX(nr) max_nr, parent_type, page_id, lang FROM page_history " .
48  " WHERE nr > %s AND hdate < %s GROUP BY parent_type, page_id, lang ",
49  ["integer", "timestamp"],
50  [0, $hdate]
51  );
52  while ($rec = $db->fetchAssoc($set)) {
53  yield [
54  "parent_type" => $rec["parent_type"],
55  "page_id" => $rec["page_id"],
56  "lang" => $rec["lang"],
57  "max_nr" => (int) $rec["max_nr"]
58  ];
59  }
60  }
61 
66  public function getMaxDeletableNr(
67  int $keep_entries,
68  string $parent_type,
69  int $page_id,
70  string $lang
71  ): int {
72  $db = $this->db;
73 
74  $set = $db->queryF(
75  "SELECT MAX(nr) mnr FROM page_history " .
76  " WHERE parent_type = %s AND page_id = %s AND lang = %s ",
77  ["text", "integer", "text"],
78  [$parent_type, $page_id, $lang]
79  );
80  $max_old_nr = 0;
81  if ($rec = $db->fetchAssoc($set)) {
82  $max_old_nr = (int) $rec["mnr"];
83  }
84  $max_old_nr -= $keep_entries;
85  if ($max_old_nr < 0) {
86  $max_old_nr = 0;
87  }
88  return $max_old_nr;
89  }
90 
92  int $delete_lower_than_nr,
93  string $parent_type,
94  int $page_id,
95  string $lang
96  ): void {
97  $db = $this->db;
98 
99  // main entries in history
100  $q = "DELETE FROM page_history " .
101  " WHERE parent_type = " . $db->quote($parent_type, "text") .
102  " AND page_id = " . $db->quote($page_id, "integer") .
103  " AND lang = " . $db->quote($lang, "text") .
104  " AND nr <= " . $db->quote($delete_lower_than_nr, "integer");
105  $db->manipulate($q);
106  }
107 
109  int $delete_lower_than_nr,
110  string $parent_type,
111  int $page_id,
112  string $lang
113  ): \Iterator {
114  $db = $this->db;
115 
116  $set = $db->queryF(
117  "SELECT nr FROM page_history " .
118  " WHERE parent_type = %s " .
119  " AND page_id = %s " .
120  " AND lang = %s " .
121  " AND nr <= %s ",
122  ["text", "integer", "text", "integer"],
123  [$parent_type, $page_id, $lang, $delete_lower_than_nr]
124  );
125  while ($rec = $db->fetchAssoc($set)) {
126  yield (int) $rec["nr"];
127  }
128  }
129 }
getMaxDeletableNr(int $keep_entries, string $parent_type, int $page_id, string $lang)
Get the maximum deletable history nr for a single page, if $keep_entries entries should be kept...
const IL_CAL_DATETIME
quote($value, string $type)
getHistoryNumbersOlderEqualThanNr(int $delete_lower_than_nr, string $parent_type, int $page_id, string $lang)
getMaxHistEntryPerPageOlderThanX(int $xdays)
Get the maximum history nr, that es older than x days for each page (and all pages) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
queryF(string $query, array $types, array $values)
$lang
Definition: xapiexit.php:26
deleteHistoryEntriesOlderEqualThanNr(int $delete_lower_than_nr, string $parent_type, int $page_id, string $lang)