ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronWebResourceCheck.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 {
37  {
38  global $ilLog,$ilDB;
39 
40  $this->log =& $ilLog;
41  $this->db =& $ilDB;
42  }
43 
44  function check()
45  {
46  global $ilObjDataCache,$ilUser;
47 
48  include_once'./classes/class.ilLinkChecker.php';
49 
50 
51  foreach(ilUtil::_getObjectsByOperations('webr','write',$ilUser->getId(),-1) as $node)
52  {
53  if(!is_object($tmp_webr =& ilObjectFactory::getInstanceByRefId($node,false)))
54  {
55  continue;
56  }
57 
58  $tmp_webr->initLinkResourceItemsObject();
59 
60  // Set all link to valid. After check invalid links will be set to invalid
61 
62  $link_checker =& new ilLinkChecker($this->db);
63  $link_checker->setMailStatus(true);
64  $link_checker->setCheckPeriod($this->__getCheckPeriod());
65  $link_checker->setObjId($tmp_webr->getId());
66 
67 
68  $tmp_webr->items_obj->updateValidByCheck($this->__getCheckPeriod());
69  foreach($link_checker->checkWebResourceLinks() as $invalid)
70  {
71  $tmp_webr->items_obj->readItem($invalid['page_id']);
72  $tmp_webr->items_obj->setActiveStatus(false);
73  $tmp_webr->items_obj->setValidStatus(false);
74  $tmp_webr->items_obj->setDisableCheckStatus(true);
75  $tmp_webr->items_obj->setLastCheckDate(time());
76  $tmp_webr->items_obj->update(false);
77  }
78 
79  $tmp_webr->items_obj->updateLastCheck($this->__getCheckPeriod());
80 
81  foreach($link_checker->getLogMessages() as $message)
82  {
83  $this->log->write($message);
84  }
85  }
86  return true;
87  }
88 
89 
90  function __getCheckPeriod()
91  {
92  global $ilias;
93 
94  switch($ilias->getSetting('cron_web_resource_check'))
95  {
96  case 1:
97  $period = 24 * 60 * 60;
98  break;
99 
100  case 2:
101  $period = 7 * 24 * 60 * 60;
102  break;
103 
104  case 3:
105  $period = 30 * 7 * 24 * 60 * 60;
106  break;
107 
108  case 4:
109  $period = 4 * 30 * 7 * 24 * 60 * 60;
110  break;
111 
112  default:
113  $period = 0;
114  }
115  return $period;
116  }
117 }
118 ?>