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