ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWebResourceCronLinkCheck.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Services/Cron/classes/class.ilCronJob.php";
5 
15 {
16  public function getId()
17  {
18  return "webr_link_check";
19  }
20 
21  public function getTitle()
22  {
23  global $lng;
24 
25  return $lng->txt("check_web_resources");
26  }
27 
28  public function getDescription()
29  {
30  global $lng;
31 
32  return $lng->txt("check_web_resources_desc");
33  }
34 
35  public function getDefaultScheduleType()
36  {
37  return self::SCHEDULE_TYPE_DAILY;
38  }
39 
40  public function getDefaultScheduleValue()
41  {
42  return;
43  }
44 
45  public function hasAutoActivation()
46  {
47  return false;
48  }
49 
50  public function hasFlexibleSchedule()
51  {
52  return true;
53  }
54 
55  public function run()
56  {
57  global $ilLog, $ilUser, $ilDB;
58 
60 
61  include_once'./Services/LinkChecker/classes/class.ilLinkChecker.php';
62 
63  $counter = 0;
64  foreach(ilUtil::_getObjectsByOperations('webr','write',$ilUser->getId(),-1) as $node)
65  {
66  if(!is_object($tmp_webr = ilObjectFactory::getInstanceByRefId($node,false)))
67  {
68  continue;
69  }
70 
71  $tmp_webr->initLinkResourceItemsObject();
72 
73  // Set all link to valid. After check invalid links will be set to invalid
74 
75  $link_checker = new ilLinkChecker($ilDB);
76  $link_checker->setMailStatus(true);
77  $link_checker->setCheckPeriod($this->__getCheckPeriod());
78  $link_checker->setObjId($tmp_webr->getId());
79 
80 
81  $tmp_webr->items_obj->updateValidByCheck($this->__getCheckPeriod());
82  foreach($link_checker->checkWebResourceLinks() as $invalid)
83  {
84  $tmp_webr->items_obj->readItem($invalid['page_id']);
85  $tmp_webr->items_obj->setActiveStatus(false);
86  $tmp_webr->items_obj->setValidStatus(false);
87  $tmp_webr->items_obj->setDisableCheckStatus(true);
88  $tmp_webr->items_obj->setLastCheckDate(time());
89  $tmp_webr->items_obj->update(false);
90  }
91 
92  $tmp_webr->items_obj->updateLastCheck($this->__getCheckPeriod());
93 
94  foreach($link_checker->getLogMessages() as $message)
95  {
96  $ilLog->write($message);
97  $counter++;
98  }
99  }
100 
101  if($counter)
102  {
103  $status = ilCronJobResult::STATUS_OK;
104  }
105  $result = new ilCronJobResult();
106  $result->setStatus($status);
107  return $result;
108  }
109 
110  function __getCheckPeriod()
111  {
112  switch($this->getScheduleType())
113  {
114  case self::SCHEDULE_TYPE_DAILY:
115  $period = 24 * 60 * 60;
116  break;
117 
118  case self::SCHEDULE_TYPE_WEEKLY:
119  $period = 7 * 24 * 60 * 60;
120  break;
121 
122  case self::SCHEDULE_TYPE_MONTHLY:
123  $period = 30 * 7 * 24 * 60 * 60;
124  break;
125 
126  case self::SCHEDULE_TYPE_QUARTERLY:
127  $period = 3 * 30 * 7 * 24 * 60 * 60;
128  break;
129 
130  default:
131  $period = 0;
132  }
133  return $period;
134  }
135 
136  public function activationWasToggled($a_currently_active)
137  {
138  global $ilSetting;
139 
140  // propagate cron-job setting to object setting
141  $ilSetting->set("cron_web_resource_check", (bool)$a_currently_active);
142  }
143 }
144 
145 ?>
$result
Cron job application base class.
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive, instead it parses the serialized rbac_pa entries.
class for checking external links in page objects Normally used in Cron jobs, but should be extensibl...
$counter
$ilUser
Definition: imgupload.php:18
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
global $ilDB
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Cron job result data container.
getScheduleType()
Get current schedule type (if flexible)