OXID eShop CE  4.9.7
 All Classes 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  $oProcessor = $this->_getServerProcessor();
132  $oProcessor->process();
133 
134  if ($this->_isSendingShopDataEnabled() && !oxRegistry::getUtils()->isSearchEngine()) {
135  $this->_sendShopInformation();
136  }
137 
138  $this->_validateOffline();
139  }
140 
146  protected function _isSendingShopDataEnabled()
147  {
148  $blSendData = true;
149 
150  $blSendData = (bool) $this->_getConfig()->getConfigParam('blLoadDynContents');
151 
152  return $blSendData;
153  }
154 
158  protected function _sendShopInformation()
159  {
160  if ($this->_needToSendShopInformation()) {
161  $oOnlineLicenseCheck = $this->getOnlineLicenseCheck();
162  $oOnlineLicenseCheck->validateShopSerials();
163  $this->_updateNextCheckTime();
164  }
165  }
166 
173  private function _needToSendShopInformation()
174  {
175  $blNeedToSend = false;
176 
177  if ($this->_getNextCheckTime() < $this->_getCurrentTime()) {
178  $blNeedToSend = true;
179  }
180 
181  return $blNeedToSend;
182  }
183 
189  private function _getNextCheckTime()
190  {
191  return (int) $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseNextCheckTime');
192  }
193 
198  private function _updateNextCheckTime()
199  {
200  $sHourToCheck = $this->_getCheckTime();
201 
203  $oUtilsDate = oxRegistry::get('oxUtilsDate');
204  $iNextCheckTime = $oUtilsDate->formTime('tomorrow', $sHourToCheck);
205 
206  $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseNextCheckTime', $iNextCheckTime);
207  }
208 
215  private function _getCheckTime()
216  {
217  $sCheckTime = $this->_getConfig()->getSystemConfigParameter('sOnlineLicenseCheckTime');
218  if (!$sCheckTime) {
219  $iHourToCheck = rand(8, 23);
220  $iMinuteToCheck = rand(0, 59);
221  $iSecondToCheck = rand(0, 59);
222 
223  $sCheckTime = $iHourToCheck . ':' . $iMinuteToCheck . ':' . $iSecondToCheck;
224  $this->_getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseCheckTime', $sCheckTime);
225  }
226 
227  return $sCheckTime;
228  }
229 
235  private function _getCurrentTime()
236  {
238  $oUtilsDate = oxRegistry::get('oxUtilsDate');
239  $iCurrentTime = $oUtilsDate->getTime();
240 
241  return $iCurrentTime;
242  }
243 
248  private function _validateOffline()
249  {
250  }
251 
257  private function _needValidateShop()
258  {
259  }
260 
266  protected function _getConfig()
267  {
268  return oxRegistry::getConfig();
269  }
270 
276  protected function _getServerProcessor()
277  {
279  $oServerNodesManager = oxNew('oxServersManager');
280 
282  $oServerNodeChecker = oxNew('oxServerChecker');
283 
285  $oUtilsServer = oxNew('oxUtilsServer');
286 
288  $oUtilsDate = oxRegistry::get('oxUtilsDate');
289 
292  return oxNew('oxServerProcessor', $oServerNodesManager, $oServerNodeChecker, $oUtilsServer, $oUtilsDate);
293  }
294 }