• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

setup/classes/class.ilCronClients.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 // include pear
00026 //require_once("DB.php");
00027 
00035 include_once 'PEAR.php';
00036 include_once 'DB.php';
00037 
00038 class ilCronClients extends PEAR
00039 {
00040         var $fp;
00041 
00042         // PRIVATE CONTRUCTOR
00043         function ilCronClients()
00044         {
00045                 define('INI_FILE_PATH','../ilias.ini.php');
00046                 define('CRON_DEBUG',1);
00047 
00048                 $this->__createLock();
00049                 $this->__readClients();
00050                 register_shutdown_function(array($this,'__ilCronClients'));
00051         }
00052 
00053 
00054         function &_getInstance()
00055         {
00056                 if(ilCronClients::_lockExists())
00057                 {
00058                         die('Instance already created');
00059                 }
00060                 return new ilCronClients();
00061         }
00062 
00063         function __createLock()
00064         {
00065                 $this->fp = @fopen('cron.lock','wb');
00066                 fwrite($this->fp,(string) time(),strlen((string) time()));
00067 
00068                 return true;
00069         }
00070 
00071         function _lockExists()
00072         {
00073                 if(@file_exists('cron.lock'))
00074                 {
00075                         $fp = fopen('cron.lock','r');
00076 
00077                         (int) $timest = fread($fp,filesize('cron.lock'));
00078                         
00079                         if(!CRON_DEBUG and ($timest > time() - 60 * 60 * 12))
00080                         {
00081                                 return true;
00082                         }
00083                         unlink('cron.lock');
00084                 }
00085                 return false;
00086         }
00087 
00088         function __readClients()
00089         {
00090                 include_once '../classes/class.ilIniFile.php';
00091 
00092                 $ini_file_obj =& new ilIniFile(INI_FILE_PATH);
00093 
00094                 $ini_file_obj->read();
00095 
00096                 $this->log['enabled'] = $ini_file_obj->readVariable('log','enabled');
00097                 $this->log['path'] = $ini_file_obj->readVariable('log','path');
00098                 $this->log['file'] = $ini_file_obj->readVariable('log','file');
00099 
00100                 $this->web_enabled = $ini_file_obj->readVariable('cron','web_enabled');
00101                 $this->web_pass = $ini_file_obj->readVariable('cron','web_pass');
00102                 $this->__checkAccess();
00103 
00104 
00105                 $this->client_data = $ini_file_obj->readGroup('clients');
00106                 unset($ini_file_obj);
00107 
00108                 // open client.ini.php
00109 
00110                 // set path to directory where clients reside
00111 
00112                 $this->client_ini = array();
00113                 $dp = opendir('../'.$this->client_data['path']);
00114                 while(($file = readdir($dp)) !== false)
00115                 {
00116                         if($file == '.' or $file == '..' or $file == 'CVS')
00117                         {
00118                                 continue;
00119                         }
00120                         if(@file_exists('../'.$this->client_data['path'].'/'.$file.'/'.$this->client_data['inifile']))
00121                         {
00122                                 $tmp_data['path'] = '../'.$this->client_data['path'].'/'.$file.'/'.$this->client_data['inifile'];
00123                                 $tmp_data['name'] = $file;
00124 
00125                                 $this->client_ini[] = $tmp_data;
00126                                 unset($tmp_data);
00127                         }
00128                 }
00129 
00130                 $this->__startChecks();
00131         }
00132 
00133         function __startChecks()
00134         {
00135                 foreach($this->client_ini as $client_data)
00136                 {
00137                         include_once '../classes/class.ilIniFile.php';
00138 
00139                         $ini_file_obj =& new ilIniFile($client_data['path']);
00140 
00141                         $ini_file_obj->read();
00142                         $this->db_data = $ini_file_obj->readGroup('db');
00143 
00144                         $this->__readFileDBVersion();
00145 
00146                         if($this->__openDb())
00147                         {
00148                                 include_once './classes/class.ilCron.php';
00149                                 
00150                                 $cron_obj =& new ilCron($this->db);
00151                                 if($this->log['enabled'])
00152                                 {
00153                                         $cron_obj->initLog($this->log['path'],$this->log['file'],$client_data['name']);
00154                                 }
00155                                 
00156                                 if($this->__checkDBVersion())
00157                                 {
00158                                         $cron_obj->start();
00159                                 }
00160                                 else
00161                                 {
00162                                         include_once '../Services/Logging/classes/class.ilLog.php';
00163                                         
00164                                         $log =& new ilLog($this->log['path'],$this->log['file']);
00165                                         $log->write('Cron: Database not up to date. Aborting');
00166                                 }
00167                                 $this->db->disconnect();
00168                         }
00169                 }
00170         }
00171 
00172         function __openDb()
00173         {
00174                 $dsn = $this->db_data['type']."://".
00175                         $this->db_data['user'].":".
00176                         $this->db_data['pass']."@".
00177                         $this->db_data['host']."/".
00178                         $this->db_data['name'];
00179 
00180                 $this->db = DB::connect($dsn,true);
00181 
00182                 if (DB::isError($this->db))
00183                 {
00184                         return false;
00185                 }
00186                 return true;
00187         }
00188 
00189         function __checkDBVersion()
00190         {
00191                 $query = "SELECT value FROM settings ".
00192                         "WHERE keyword = 'db_version'";
00193 
00194                 $res = $this->db->query($query);
00195                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00196                 {
00197                         $db_version = $row->value;
00198                 }
00199 
00200                 return $db_version == $this->file_version;
00201         }
00202 
00203         function __readFileDBVersion()
00204         {
00205                 $this->db_version = 99999;
00206 
00207                 // GET FILE VERSION
00208                 if(!$content = file('../setup/sql/dbupdate_02.php'))
00209                 {
00210                         echo 'Cannot open ../setup/sql/dbupdate_02.php';
00211                         return false;
00212                 }
00213                 foreach($content as $row)
00214                 {
00215                         if(preg_match('/^<#([0-9]+)>/',$row,$matches))
00216                         {
00217                                 $this->file_version = $matches[1];
00218                         }
00219                 }
00220         }
00221 
00222         function __checkAccess()
00223         {
00224                 if($_SERVER['REQUEST_URI'])
00225                 {
00226                         if(!$this->web_enabled or ($_GET['web_pass'] !== $this->web_pass))
00227                         {
00228                                 if($this->log['enabled'])
00229                                 {
00230                                         include_once '../Services/Logging/classes/class.ilLog.php';
00231 
00232                                         $this->log =& new ilLog($this->log['path'],$this->log['file']);
00233 
00234                                         $this->log->write('Cron: __checkAccess() failed');
00235                                         
00236                                         exit;
00237                                 }
00238                         }
00239                 }
00240                 return true;
00241         }
00242 
00243 
00244 
00245         function __ilCronClients()
00246         {
00247                 fclose($this->fp);
00248         }
00249 }
00250                 

Generated on Fri Dec 13 2013 17:57:03 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1