ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCleanCOPageHistoryCronjob.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
28 {
30  protected ilSetting $settings;
31  protected ilLanguage $lng;
32 
33  public function __construct()
34  {
35  global $DIC;
36 
37  $this->lng = $DIC->language();
38  $this->settings = $DIC->settings();
39  $this->history_manager = $DIC
40  ->copage()
41  ->internal()
42  ->domain()
43  ->history();
44  }
45 
46  public function getId(): string
47  {
48  return "copg_history_cleanup";
49  }
50 
51  public function getTitle(): string
52  {
53  $lng = $this->lng;
54 
55  $lng->loadLanguageModule("copg");
56  return $lng->txt("copg_history_cleanup_cron");
57  }
58 
59  public function getDescription(): string
60  {
61  $lng = $this->lng;
62 
63  $lng->loadLanguageModule("copg");
64  return $lng->txt("copg_history_cleanup_cron_info");
65  }
66 
68  {
69  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
70  }
71 
72  public function getDefaultScheduleValue(): ?int
73  {
74  return null;
75  }
76 
77  public function hasAutoActivation(): bool
78  {
79  return false;
80  }
81 
82  public function hasFlexibleSchedule(): bool
83  {
84  return false;
85  }
86 
87  public function hasCustomSettings(): bool
88  {
89  return true;
90  }
91 
92  public function run(): ilCronJobResult
93  {
94  global $DIC;
95 
97  $log->debug("----- Delete old page history entries, Start -----");
98 
100  $result = new ilCronJobResult();
101 
102  $x_days = $this->getCronDays();
103  $keep_entries = $this->getKeepEntries();
104  $log->debug("... $x_days days, keep $keep_entries");
105 
106  if ($this->history_manager->deleteOldHistoryEntries($x_days, $keep_entries)) {
107  $status = ilCronJobResult::STATUS_OK;
108  }
109 
110  $log->debug("----- Delete old page history entries, End -----");
111 
112  $result->setStatus($status);
113  return $result;
114  }
115 
116  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
117  {
118  $lng = $this->lng;
119  $lng->loadLanguageModule("copg");
120 
121  $ti = new ilNumberInputGUI(
122  $lng->txt("copg_cron_days"),
123  "copg_cron_days"
124  );
125  $ti->setSize(6);
126  $ti->setSuffix($lng->txt("copg_days"));
127  $ti->setInfo($lng->txt("copg_cron_days_info"));
128  $ti->setValue((string) $this->getCronDays());
129  $a_form->addItem($ti);
130 
131  $ti = new ilNumberInputGUI($lng->txt("copg_cron_keep_entries"), "copg_cron_keep_entries");
132  $ti->setSize(6);
133  $ti->setSuffix($lng->txt("copg_entries"));
134  $ti->setInfo($lng->txt("copg_cron_keep_entries_info"));
135  $ti->setValue((string) $this->getKeepEntries());
136  $a_form->addItem($ti);
137  }
138 
139  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
140  {
141  $this->setCronDays((int) $a_form->getInput("copg_cron_days"));
142  $this->setKeepEntries((int) $a_form->getInput("copg_cron_keep_entries"));
143 
144  return true;
145  }
146 
147  protected function getCronDays(): int
148  {
149  $settings = $this->settings;
150  return (int) $settings->get("copg_cron_days", "3600");
151  }
152 
153  protected function setCronDays(int $days): void
154  {
155  $settings = $this->settings;
156  $settings->set("copg_cron_days", (string) $days);
157  }
158 
159  protected function getKeepEntries(): int
160  {
161  $settings = $this->settings;
162  return (int) $settings->get("copg_cron_keep_entries", "1000");
163  }
164 
165  protected function setKeepEntries(int $entries): void
166  {
167  $settings = $this->settings;
168  $settings->set("copg_cron_keep_entries", (string) $entries);
169  }
170 }
get(string $a_keyword, ?string $a_default_value=null)
get setting
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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-...
global $DIC
Definition: feed.php:28
$log
Definition: result.php:33
final const STATUS_NO_ACTION
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...