Go to the documentation of this file.00001 <?php
00002
00009 class oxSystemEventHandler
00010 {
00011
00015 private $_oOnlineModuleVersionNotifier = null;
00016
00020 private $_oOnlineLicenseCheck = null;
00021
00027 public function setOnlineLicenseCheck(oxOnlineLicenseCheck $oOnlineLicenseCheck)
00028 {
00029 $this->_oOnlineLicenseCheck = $oOnlineLicenseCheck;
00030 }
00031
00037 public function getOnlineLicenseCheck()
00038 {
00039 if (!$this->_oOnlineLicenseCheck) {
00041 $oCurl = oxNew('oxCurl');
00042
00044 $oEmailBuilder = oxNew('oxOnlineServerEmailBuilder');
00045
00047 $oSimpleXml = oxNew('oxSimpleXml');
00048
00050 $oLicenseCaller = oxNew('oxOnlineLicenseCheckCaller', $oCurl, $oEmailBuilder, $oSimpleXml);
00051
00053 $oUserCounter = oxNew('oxUserCounter');
00054
00056 $oServerManager = oxNew('oxServersManager');
00057
00059 $oOLC = oxNew("oxOnlineLicenseCheck", $oLicenseCaller);
00060 $oOLC->setServersManager($oServerManager);
00061 $oOLC->setUserCounter($oUserCounter);
00062
00063 $this->setOnlineLicenseCheck($oOLC);
00064 }
00065
00066 return $this->_oOnlineLicenseCheck;
00067 }
00068
00074 public function setOnlineModuleVersionNotifier(oxOnlineModuleVersionNotifier $oOnlineModuleVersionNotifier)
00075 {
00076 $this->_oOnlineModuleVersionNotifier = $oOnlineModuleVersionNotifier;
00077 }
00078
00084 public function getOnlineModuleVersionNotifier()
00085 {
00086 if (!$this->_oOnlineModuleVersionNotifier) {
00088 $oCurl = oxNew('oxCurl');
00089
00091 $oMailBuilder = oxNew('oxOnlineServerEmailBuilder');
00092
00094 $oSimpleXml = oxNew('oxSimpleXml');
00095
00097 $oOnlineModuleVersionNotifierCaller = oxNew("oxOnlineModuleVersionNotifierCaller", $oCurl, $oMailBuilder, $oSimpleXml);
00098
00100 $oModuleList = oxNew('oxModuleList');
00101 $oModuleList->getModulesFromDir(oxRegistry::getConfig()->getModulesDir());
00102
00104 $oOnlineModuleVersionNotifier = oxNew("oxOnlineModuleVersionNotifier", $oOnlineModuleVersionNotifierCaller, $oModuleList);
00105
00106 $this->setOnlineModuleVersionNotifier($oOnlineModuleVersionNotifier);
00107 }
00108
00109 return $this->_oOnlineModuleVersionNotifier;
00110 }
00111
00115 public function onAdminLogin()
00116 {
00117
00118
00119
00120 try {
00121 $this->getOnlineModuleVersionNotifier()->versionNotify();
00122 } catch (Exception $o) {
00123 }
00124 }
00125
00129 public function onShopStart()
00130 {
00131 $oProcessor = $this->_getServerProcessor();
00132 $oProcessor->process();
00133
00134 if ($this->_isSendingShopDataEnabled() && !oxRegistry::getUtils()->isSearchEngine()) {
00135 $this->_sendShopInformation();
00136 }
00137
00138 $this->_validateOffline();
00139 }
00140
00146 protected function _isSendingShopDataEnabled()
00147 {
00148 $blSendData = true;
00149
00150 $blSendData = (bool) $this->_getConfig()->getConfigParam('blLoadDynContents');
00151
00152 return $blSendData;
00153 }
00154
00158 protected function _sendShopInformation()
00159 {
00160 if ($this->_needToSendShopInformation()) {
00161 $oOnlineLicenseCheck = $this->getOnlineLicenseCheck();
00162 $oOnlineLicenseCheck->validateShopSerials();
00163 $this->_updateNextCheckTime();
00164 }
00165 }
00166
00173 private function _needToSendShopInformation()
00174 {
00175 $blNeedToSend = false;
00176
00177 if ($this->_getNextCheckTime() < $this->_getCurrentTime()) {
00178 $blNeedToSend = true;
00179 }
00180
00181 return $blNeedToSend;
00182 }
00183
00189 private function _getNextCheckTime()
00190 {
00191 return (int) $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseNextCheckTime');
00192 }
00193
00198 private function _updateNextCheckTime()
00199 {
00200 $sHourToCheck = $this->_getCheckTime();
00201
00203 $oUtilsDate = oxRegistry::get('oxUtilsDate');
00204 $iNextCheckTime = $oUtilsDate->formTime('tomorrow', $sHourToCheck);
00205
00206 $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseNextCheckTime', $iNextCheckTime);
00207 }
00208
00215 private function _getCheckTime()
00216 {
00217 $sCheckTime = $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseCheckTime');
00218 if (!$sCheckTime) {
00219 $iHourToCheck = rand(8, 23);
00220 $iMinuteToCheck = rand(0, 59);
00221 $iSecondToCheck = rand(0, 59);
00222
00223 $sCheckTime = $iHourToCheck . ':' . $iMinuteToCheck . ':' . $iSecondToCheck;
00224 $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseCheckTime', $sCheckTime);
00225 }
00226
00227 return $sCheckTime;
00228 }
00229
00235 private function _getCurrentTime()
00236 {
00238 $oUtilsDate = oxRegistry::get('oxUtilsDate');
00239 $iCurrentTime = $oUtilsDate->getTime();
00240
00241 return $iCurrentTime;
00242 }
00243
00248 private function _validateOffline()
00249 {
00250 }
00251
00257 private function _needValidateShop()
00258 {
00259 }
00260
00266 protected function _getConfig()
00267 {
00268 return oxRegistry::getConfig();
00269 }
00270
00276 protected function _getServerProcessor()
00277 {
00279 $oServerNodesManager = oxNew('oxServersManager');
00280
00282 $oServerNodeChecker = oxNew('oxServerChecker');
00283
00285 $oUtilsServer = oxNew('oxUtilsServer');
00286
00288 $oUtilsDate = oxRegistry::get('oxUtilsDate');
00289
00292 return oxNew('oxServerProcessor', $oServerNodesManager, $oServerNodeChecker, $oUtilsServer, $oUtilsDate);
00293 }
00294 }