OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxsystemeventhandler.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
16 
20  private $_oOnlineLicenseCheck = null;
21 
27  public function setOnlineLicenseCheck(oxOnlineLicenseCheck $oOnlineLicenseCheck)
28  {
29  $this->_oOnlineLicenseCheck = $oOnlineLicenseCheck;
30  }
31 
37  public function getOnlineLicenseCheck()
38  {
39  if (!$this->_oOnlineLicenseCheck) {
41  $oCurl = oxNew('oxCurl');
42 
44  $oEmailBuilder = oxNew('oxOnlineServerEmailBuilder');
45 
47  $oSimpleXml = oxNew('oxSimpleXml');
48 
50  $oLicenseCaller = oxNew('oxOnlineLicenseCheckCaller', $oCurl, $oEmailBuilder, $oSimpleXml);
51 
53  $oUserCounter = oxNew('oxUserCounter');
54 
56  $oServerManager = oxNew('oxServersManager');
57 
59  $oOLC = oxNew("oxOnlineLicenseCheck", $oLicenseCaller);
60  $oOLC->setServersManager($oServerManager);
61  $oOLC->setUserCounter($oUserCounter);
62 
63  $this->setOnlineLicenseCheck($oOLC);
64  }
65 
67  }
68 
74  public function setOnlineModuleVersionNotifier(oxOnlineModuleVersionNotifier $oOnlineModuleVersionNotifier)
75  {
76  $this->_oOnlineModuleVersionNotifier = $oOnlineModuleVersionNotifier;
77  }
78 
85  {
86  if (!$this->_oOnlineModuleVersionNotifier) {
88  $oCurl = oxNew('oxCurl');
89 
91  $oMailBuilder = oxNew('oxOnlineServerEmailBuilder');
92 
94  $oSimpleXml = oxNew('oxSimpleXml');
95 
97  $oOnlineModuleVersionNotifierCaller = oxNew("oxOnlineModuleVersionNotifierCaller", $oCurl, $oMailBuilder, $oSimpleXml);
98 
100  $oModuleList = oxNew('oxModuleList');
101  $oModuleList->getModulesFromDir(oxRegistry::getConfig()->getModulesDir());
102 
104  $oOnlineModuleVersionNotifier = oxNew("oxOnlineModuleVersionNotifier", $oOnlineModuleVersionNotifierCaller, $oModuleList);
105 
106  $this->setOnlineModuleVersionNotifier($oOnlineModuleVersionNotifier);
107  }
108 
110  }
111 
115  public function onAdminLogin()
116  {
117  // Checks if newer versions of modules are available.
118  // Will be used by the upcoming online one click installer.
119  // Is still under development - still changes at the remote server are necessary - therefore ignoring the results for now
120  try {
121  $this->getOnlineModuleVersionNotifier()->versionNotify();
122  } catch (Exception $o) {
123  }
124  }
125 
129  public function onShopStart()
130  {
131  $this->_validateOnline();
132 
133  $this->_validateOffline();
134  }
135 
139  protected function _validateOnline()
140  {
141  try {
142  $oProcessor = $this->_getServerProcessor();
143  $oProcessor->process();
144 
145  if ($this->_isSendingShopDataEnabled() && !oxRegistry::getUtils()->isSearchEngine()) {
146  $this->_sendShopInformation();
147  }
148  } catch (Exception $eException) {
149  oxRegistry::getUtils()->logger("OLC-Error: " . $eException->getMessage());
150  }
151  }
152 
158  protected function _isSendingShopDataEnabled()
159  {
160  $blSendData = true;
161 
162  $blSendData = (bool) $this->_getConfig()->getConfigParam('blLoadDynContents');
163 
164  return $blSendData;
165  }
166 
170  protected function _sendShopInformation()
171  {
172  if ($this->_needToSendShopInformation()) {
173  $oOnlineLicenseCheck = $this->getOnlineLicenseCheck();
174  $oOnlineLicenseCheck->validateShopSerials();
175  $this->_updateNextCheckTime();
176  }
177  }
178 
185  private function _needToSendShopInformation()
186  {
187  $blNeedToSend = false;
188 
189  if ($this->_getNextCheckTime() < $this->_getCurrentTime()) {
190  $blNeedToSend = true;
191  }
192 
193  return $blNeedToSend;
194  }
195 
201  private function _getNextCheckTime()
202  {
203  return (int) $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseNextCheckTime');
204  }
205 
210  private function _updateNextCheckTime()
211  {
212  $sHourToCheck = $this->_getCheckTime();
213 
215  $oUtilsDate = oxRegistry::get('oxUtilsDate');
216  $iNextCheckTime = $oUtilsDate->formTime('tomorrow', $sHourToCheck);
217 
218  $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseNextCheckTime', $iNextCheckTime);
219  }
220 
227  private function _getCheckTime()
228  {
229  $sCheckTime = $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseCheckTime');
230  if (!$sCheckTime) {
231  $iHourToCheck = rand(8, 23);
232  $iMinuteToCheck = rand(0, 59);
233  $iSecondToCheck = rand(0, 59);
234 
235  $sCheckTime = $iHourToCheck . ':' . $iMinuteToCheck . ':' . $iSecondToCheck;
236  $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseCheckTime', $sCheckTime);
237  }
238 
239  return $sCheckTime;
240  }
241 
247  private function _getCurrentTime()
248  {
250  $oUtilsDate = oxRegistry::get('oxUtilsDate');
251  $iCurrentTime = $oUtilsDate->getTime();
252 
253  return $iCurrentTime;
254  }
255 
260  private function _validateOffline()
261  {
262  }
263 
269  private function _needValidateShop()
270  {
271  }
272 
278  protected function _getConfig()
279  {
280  return oxRegistry::getConfig();
281  }
282 
288  protected function _getServerProcessor()
289  {
291  $oServerNodesManager = oxNew('oxServersManager');
292 
294  $oServerNodeChecker = oxNew('oxServerChecker');
295 
297  $oUtilsServer = oxNew('oxUtilsServer');
298 
300  $oUtilsDate = oxRegistry::get('oxUtilsDate');
301 
304  return oxNew('oxServerProcessor', $oServerNodesManager, $oServerNodeChecker, $oUtilsServer, $oUtilsDate);
305  }
306 }