ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronCheck.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
36  private $possible_tasks = array();
37  private $default_tasks = array();
38 
39  public function ilCronCheck()
40  {
41  global $ilLog;
42 
43  $this->log = $ilLog;
44 
45  $this->initTasks();
46  }
47 
48  public function start()
49  {
50  global $ilSetting;
51 
52  $ilSetting->set('last_cronjob_start_ts', time());
53 
54  if( $_SERVER['argc'] > 4 )
55  {
56  for($i = 4; $i < $_SERVER['argc']; $i++)
57  {
58  $arg = $_SERVER['argv'][$i];
59 
60  if( !isset($this->possible_tasks[$arg]) )
61  throw new ilException('cron-task "'.$arg.'" is not defined');
62 
63  $task = $this->possible_tasks[$arg];
64 
65  $this->runTask($task);
66  }
67  }
68  else foreach($this->default_tasks as $task)
69  {
70  $task = $this->possible_tasks[$task];
71 
72  $this->runTask($task);
73  }
74  }
75 
76  private function runTask($task)
77  {
78  global $ilLog;
79 
84  $classlocation = $task['location'].'/classes';
85  if( isset($task['sub_location']) && strlen($task['sub_location']) )
86  {
87  $classlocation .= '/'.$task['sub_location'];
88  }
89  $classfile .= $classlocation.'/class.'.$task['classname'].'.php';
90 
91  $classname = $task['classname'];
92  $method = $task['method'];
93 
94  $condition = $task['condition'];
95 
100  if( !file_exists($classfile) )
101  throw new ilException('class file "'.$classfile.'" does not exist');
102 
103  require_once($classfile);
104 
105  if( !class_exists($classname) )
106  throw new ilException('class "'.$classname.'" does not exist');
107 
108  if( !method_exists($classname, $method) )
109  throw new ilException('method "'.$classname.'::'.$method.'()" does not exist');
110 
116  if($condition)
117  {
118  $ilLog->write("CRON - starting task: ".$classname."::".$method);
119 
120  $task = new $classname;
121  $task->$method();
122 
123  $ilLog->write("CRON - finished task: ".$classname."::".$method);
124  }
125  else
126  {
127  $ilLog->write("CRON - task condition failed: ".$classname."::".$method);
128  }
129  }
130 
131  private function initTasks()
132  {
133  global $ilias;
134 
135  require_once('Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php');
136  require_once('Services/Payment/classes/class.ilUserDefinedInvoiceNumber.php');
137 
138  $this->default_tasks = array(
139  'ilLDAPCronSynchronization::start',
140  'ilCronCheckUserAccounts::check',
141  'ilLuceneIndexer::index',
142  'ilCronLinkCheck::check',
143  'ilCronWebResourceCheck::check',
144  'ilCronForumNotification::sendNotifications',
145  'ilCronMailNotification::sendNotifications',
146  'ilCronValidator::check',
147  'ilCronDiskQuotaCheck::updateDiskUsageStatistics',
148  'ilCronDiskQuotaCheck::sendReminderMails',
149  // This entry refers to a task that is not completely implemented
150  #'ilPaymentShoppingCart::__deleteExpiredSessionsPSC',
151  'ilCronDeleteInactiveUserAccounts::run',
152  'ilCronDeleteInactivatedUserAccounts::run',
153  'ilCronPaymentNotification::sendNotifications',
154  'ilCronCourseGroupNotification::check',
155  'ilCronPaymentUDInvoiceNumberReset::check',
156  'ilCronObjectStatisticsCheck::check'
157  );
158 
159  $this->possible_tasks = array(
160 
161  'ilLDAPCronSynchronization::start' => array(
162  'classname' => 'ilLDAPCronSynchronization',
163  'method' => 'start',
164  'location' => 'Services/LDAP',
165  'condition' => true
166  ),
167 
168  // Check user accounts if enabled in settings
169  'ilCronCheckUserAccounts::check' => array(
170  'classname' => 'ilCronCheckUserAccounts',
171  'method' => 'check',
172  'location' => 'cron',
173  'condition' => $ilias->getSetting('cron_user_check')
174  ),
175 
176  // Start lucene indexer
177  'ilLuceneIndexer::index' => array(
178  'classname' => 'ilLuceneIndexer',
179  'method' => 'index',
180  'location' => 'Services/Search',
181  'sub_location' => 'Lucene',
182  'condition' => $ilias->getSetting("cron_lucene_index")
183  ),
184 
185  // Start Link check
186  'ilCronLinkCheck::check' => array(
187  'classname' => 'ilCronLinkCheck',
188  'method' => 'check',
189  'location' => 'cron',
190  'condition' => $ilias->getSetting("cron_link_check")
191  ),
192 
193  // Start web resource check
194  'ilCronWebResourceCheck::check' => array(
195  'classname' => 'ilCronWebResourceCheck',
196  'method' => 'check',
197  'location' => 'cron',
198  'condition' => $ilias->getSetting("cron_web_resource_check")
199  ),
200 
201  // Start sending forum notifications
202  'ilCronForumNotification::sendNotifications' => array(
203  'classname' => 'ilCronForumNotification',
204  'method' => 'sendNotifications',
205  'location' => 'cron',
206  'condition' => ($ilias->getSetting('forum_notification') == 2)
207  ),
208 
209  // Start sending mail notifications
210  'ilCronMailNotification::sendNotifications' => array(
211  'classname' => 'ilCronMailNotification',
212  'method' => 'sendNotifications',
213  'location' => 'cron',
214  'condition' => ($ilias->getSetting('mail_notification') == 1)
215  ),
216 
217  // Start System Check
218  'ilCronValidator::check' => array(
219  'classname' => 'ilCronValidator',
220  'method' => 'check',
221  'location' => 'cron',
222  'condition' => ($ilias->getSetting('systemcheck_cron') == 1)
223  ),
224 
225  // Start Disk Quota Usage Statistics
226  'ilCronDiskQuotaCheck::updateDiskUsageStatistics' => array(
227  'classname' => 'ilCronDiskQuotaCheck',
228  'method' => 'updateDiskUsageStatistics',
229  'location' => 'cron',
231  ),
232 
233  // Send Disk Quota Reminder Mails
234  'ilCronDiskQuotaCheck::sendReminderMails' => array(
235  'classname' => 'ilCronDiskQuotaCheck',
236  'method' => 'sendReminderMails',
237  'location' => 'cron',
239  ),
240 
241  // Send Disk Quota Summary Mails
242  'ilCronDiskQuotaCheck::sendSummaryMails' => array(
243  'classname' => 'ilCronDiskQuotaCheck',
244  'method' => 'sendSummaryMails',
245  'location' => 'cron',
247  ),
248 
253  #// Start Shopping Cart Check
254  #'ilPaymentShoppingCart::__deleteExpiredSessionsPSC' => array(
255  # 'classname' => 'ilPaymentShoppingCart',
256  # 'method' => '__deleteExpiredSessionsPSC',
257  # 'location' => 'Services/Payment',
258  # 'condition' => true
259  #),
260 
261  // Delete Inactive User Accounts depending on "inactivity" period
262  'ilCronDeleteInactiveUserAccounts::run' => array(
263  'classname' => 'ilCronDeleteInactiveUserAccounts',
264  'method' => 'run',
265  'location' => 'Services/User',
266  'condition' => $ilias->getSetting('cron_inactive_user_delete', 0)
267  ),
268 
269  // Delete Inactive User Accounts depending on "inactivation" period
270  'ilCronDeleteInactivatedUserAccounts::run' => array(
271  'classname' => 'ilCronDeleteInactivatedUserAccounts',
272  'method' => 'run',
273  'location' => 'Services/User',
274  'condition' => $ilias->getSetting('cron_inactivated_user_delete', 0)
275  ),
276 
277  // Start sending Payment "Buy Extension" Reminder
278  'ilCronPaymentNotification::sendNotifications' => array(
279  'classname' => 'ilCronPaymentNotification',
280  'method' => 'sendNotifications',
281  'location' => 'cron',
282  'condition' => ($ilias->getSetting('payment_notifications') == 1)
283  ),
284 
285  // Start course group notification check
286  'ilCronCourseGroupNotification::check' => array(
287  'classname' => 'ilCronCourseGroupNotification',
288  'method' => 'sendNotifications',
289  'location' => 'cron',
290  'condition' => $ilias->getSetting("crsgrp_ntf")
291  ),
292 
293  // Reset payment incremental invoice number
294  'ilCronPaymentUDInvoiceNumberReset::check' => array(
295  'classname' => 'ilCronPaymentUDInvoiceNumberReset',
296  'method' => 'check',
297  'location' => 'cron',
299  ),
300 
301  // (object) statistics
302  'ilCronObjectStatisticsCheck::check' => array(
303  'classname' => 'ilCronObjectStatisticsCheck',
304  'method' => 'check',
305  'location' => 'cron',
306  'condition' => true
307  )
308  );
309  }
310 }
311 ?>