ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCleanCOPageHistoryCronjob.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
30 {
32  protected ilSetting $settings;
33  protected ilLanguage $lng;
34 
35  public function __construct()
36  {
37  global $DIC;
38 
39  $this->lng = $DIC->language();
40  $this->settings = $DIC->settings();
41  $this->history_manager = $DIC
42  ->copage()
43  ->internal()
44  ->domain()
45  ->history();
46  }
47 
48  public function getId(): string
49  {
50  return "copg_history_cleanup";
51  }
52 
53  public function getTitle(): string
54  {
55  $lng = $this->lng;
56 
57  $lng->loadLanguageModule("copg");
58  return $lng->txt("copg_history_cleanup_cron");
59  }
60 
61  public function getDescription(): string
62  {
63  $lng = $this->lng;
64 
65  $lng->loadLanguageModule("copg");
66  return $lng->txt("copg_history_cleanup_cron_info");
67  }
68 
70  {
71  return JobScheduleType::DAILY;
72  }
73 
74  public function getDefaultScheduleValue(): ?int
75  {
76  return null;
77  }
78 
79  public function hasAutoActivation(): bool
80  {
81  return false;
82  }
83 
84  public function hasFlexibleSchedule(): bool
85  {
86  return false;
87  }
88 
89  public function hasCustomSettings(): bool
90  {
91  return true;
92  }
93 
94  public function run(): JobResult
95  {
96  global $DIC;
97 
99  $log->debug("----- Delete old page history entries, Start -----");
100 
101  $status = JobResult::STATUS_NO_ACTION;
102  $result = new JobResult();
103 
104  $x_days = $this->getCronDays();
105  $keep_entries = $this->getKeepEntries();
106  $log->debug("... $x_days days, keep $keep_entries");
107 
108  if ($this->history_manager->deleteOldHistoryEntries($x_days, $keep_entries)) {
109  $status = JobResult::STATUS_OK;
110  }
111 
112  $log->debug("----- Delete old page history entries, End -----");
113 
114  $result->setStatus($status);
115  return $result;
116  }
117 
118  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
119  {
120  $lng = $this->lng;
121  $lng->loadLanguageModule("copg");
122 
123  $ti = new ilNumberInputGUI(
124  $lng->txt("copg_cron_days"),
125  "copg_cron_days"
126  );
127  $ti->setSize(6);
128  $ti->setSuffix($lng->txt("copg_days"));
129  $ti->setInfo($lng->txt("copg_cron_days_info"));
130  $ti->setValue((string) $this->getCronDays());
131  $a_form->addItem($ti);
132 
133  $ti = new ilNumberInputGUI($lng->txt("copg_cron_keep_entries"), "copg_cron_keep_entries");
134  $ti->setSize(6);
135  $ti->setSuffix($lng->txt("copg_entries"));
136  $ti->setInfo($lng->txt("copg_cron_keep_entries_info"));
137  $ti->setValue((string) $this->getKeepEntries());
138  $a_form->addItem($ti);
139  }
140 
141  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
142  {
143  $this->setCronDays((int) $a_form->getInput("copg_cron_days"));
144  $this->setKeepEntries((int) $a_form->getInput("copg_cron_keep_entries"));
145 
146  return true;
147  }
148 
149  protected function getCronDays(): int
150  {
151  $settings = $this->settings;
152  return (int) $settings->get("copg_cron_days", "3600");
153  }
154 
155  protected function setCronDays(int $days): void
156  {
157  $settings = $this->settings;
158  $settings->set("copg_cron_days", (string) $days);
159  }
160 
161  protected function getKeepEntries(): int
162  {
163  $settings = $this->settings;
164  return (int) $settings->get("copg_cron_keep_entries", "1000");
165  }
166 
167  protected function setKeepEntries(int $entries): void
168  {
169  $settings = $this->settings;
170  $settings->set("copg_cron_keep_entries", (string) $entries);
171  }
172 }
get(string $a_keyword, ?string $a_default_value=null)
get setting
static getLogger(string $a_component_id)
Get component logger.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
set(string $a_key, string $a_val)
loadLanguageModule(string $a_module)
Load language module.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$log
Definition: result.php:32
This class represents a number property in a property form.
global $DIC
Definition: shib_login.php:22
addCustomSettingsToForm(ilPropertyFormGUI $a_form)