35 include_once
'PEAR.php';
36 include_once
'MDB2.php';
45 define(
'INI_FILE_PATH',
'../ilias.ini.php');
46 define(
'CRON_DEBUG',1);
50 register_shutdown_function(array($this,
'__ilCronClients'));
58 die(
'Instance already created');
65 $this->fp = @fopen(
'cron.lock',
'wb');
66 fwrite($this->fp,(
string) time(),strlen((
string) time()));
73 if(@file_exists(
'cron.lock'))
75 $fp = fopen(
'cron.lock',
'r');
77 (int) $timest = fread(
$fp,filesize(
'cron.lock'));
79 if(!CRON_DEBUG and ($timest > time() - 60 * 60 * 12))
90 include_once
'../classes/class.ilIniFile.php';
92 $ini_file_obj =&
new ilIniFile(INI_FILE_PATH);
94 $ini_file_obj->read();
96 $this->log[
'enabled'] = $ini_file_obj->readVariable(
'log',
'enabled');
97 $this->log[
'path'] = $ini_file_obj->readVariable(
'log',
'path');
98 $this->log[
'file'] = $ini_file_obj->readVariable(
'log',
'file');
100 $this->web_enabled = $ini_file_obj->readVariable(
'cron',
'web_enabled');
101 $this->web_pass = $ini_file_obj->readVariable(
'cron',
'web_pass');
105 $this->client_data = $ini_file_obj->readGroup(
'clients');
106 unset($ini_file_obj);
112 $this->client_ini = array();
113 $dp = opendir(
'../'.$this->client_data[
'path']);
114 while((
$file = readdir($dp)) !==
false)
120 if(@file_exists(
'../'.$this->client_data[
'path'].
'/'.
$file.
'/'.$this->client_data[
'inifile']))
122 $tmp_data[
'path'] =
'../'.$this->client_data[
'path'].
'/'.
$file.
'/'.$this->client_data[
'inifile'];
123 $tmp_data[
'name'] =
$file;
125 $this->client_ini[] = $tmp_data;
135 foreach($this->client_ini as $client_data)
137 include_once
'../classes/class.ilIniFile.php';
139 $ini_file_obj =&
new ilIniFile($client_data[
'path']);
141 $ini_file_obj->read();
142 $this->db_data = $ini_file_obj->readGroup(
'db');
148 include_once
'./classes/class.ilCron.php';
151 if($this->log[
'enabled'])
153 $cron_obj->initLog($this->log[
'path'],$this->log[
'file'],$client_data[
'name']);
162 include_once
'../Services/Logging/classes/class.ilLog.php';
164 $log =&
new ilLog($this->log[
'path'],$this->log[
'file']);
165 $log->write(
'Cron: Database not up to date. Aborting');
167 $this->db->disconnect();
174 $dsn = $this->db_data[
'type'].
"://".
175 $this->db_data[
'user'].
":".
176 $this->db_data[
'pass'].
"@".
177 $this->db_data[
'host'].
"/".
178 $this->db_data[
'name'];
180 $this->db = MDB2::connect($dsn,
true);
182 if (MDB2::isError($this->db))
191 $query =
"SELECT value FROM settings ".
192 "WHERE keyword = 'db_version'";
194 $res = $this->db->query($query);
197 $db_version = $row->value;
200 return $db_version == $this->file_version;
205 $this->db_version = 99999;
208 if(!$content = file(
'../setup/sql/dbupdate_02.php'))
210 echo
'Cannot open ../setup/sql/dbupdate_02.php';
213 foreach($content as $row)
215 if(preg_match(
'/^<#([0-9]+)>/',$row,$matches))
217 $this->file_version = $matches[1];
224 if($_SERVER[
'REQUEST_URI'])
226 if(!$this->web_enabled or (
$_GET[
'web_pass'] !== $this->web_pass))
228 if($this->log[
'enabled'])
230 include_once
'../Services/Logging/classes/class.ilLog.php';
232 $this->log =&
new ilLog($this->log[
'path'],$this->log[
'file']);
234 $this->log->write(
'Cron: __checkAccess() failed');