ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCleanCOPageHistoryCronjob.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
30{
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 {
56
57 $lng->loadLanguageModule("copg");
58 return $lng->txt("copg_history_cleanup_cron");
59 }
60
61 public function getDescription(): string
62 {
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 {
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 {
152 return (int) $settings->get("copg_cron_days", "3600");
153 }
154
155 protected function setCronDays(int $days): void
156 {
158 $settings->set("copg_cron_days", (string) $days);
159 }
160
161 protected function getKeepEntries(): int
162 {
164 return (int) $settings->get("copg_cron_keep_entries", "1000");
165 }
166
167 protected function setKeepEntries(int $entries): void
168 {
170 $settings->set("copg_cron_keep_entries", (string) $entries);
171 }
172}
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
language handling
loadLanguageModule(string $a_module)
Load language module.
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...
static getLogger(string $a_component_id)
Get component logger.
This class represents a number property in a property form.
This class represents a property form user interface.
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-...
ILIAS Setting Class.
set(string $a_key, string $a_val)
get(string $a_keyword, ?string $a_default_value=null)
get setting
$log
Definition: ltiresult.php:34
global $DIC
Definition: shib_login.php:26