OXID eShop CE  4.9.9
 All Classes Files Functions Variables Pages
oxonlinelicensecheck.php
Go to the documentation of this file.
1 <?php
2 
12 {
13 
17  const CONFIG_VAR_NAME = 'iOlcSuccess';
18 
24  protected $_iValidResponseCode = 0;
25 
31  protected $_sValidResponseMessage = 'ACK';
32 
38  protected $_aSerialKeys = array();
39 
45  protected $_sErrorMessage = '';
46 
52  protected $_blIsException = false;
53 
55  protected $_oCaller = null;
56 
58  protected $_oUserCounter = null;
59 
61  protected $_oServersManager = null;
62 
68  public function setServersManager($oServersManager)
69  {
70  $this->_oServersManager = $oServersManager;
71  }
72 
78  public function getServersManager()
79  {
81  }
82 
88  public function setUserCounter($oUserCounter)
89  {
90  $this->_oUserCounter = $oUserCounter;
91  }
92 
98  public function getUserCounter()
99  {
100  return $this->_oUserCounter;
101  }
102 
103 
109  public function __construct($oCaller)
110  {
111  $this->_oCaller = $oCaller;
112  }
113 
119  public function getErrorMessage()
120  {
121  return $this->_sErrorMessage;
122  }
123 
129  public function isException()
130  {
131  return $this->_blIsException;
132  }
133 
139  public function validateShopSerials()
140  {
141  $aSerials = oxRegistry::getConfig()->getConfigParam("aSerials");
142  if (!$this->validate($aSerials) && !$this->isException()) {
143  $this->_startGracePeriod();
144  }
145  }
146 
154  public function validateNewSerial($sSerial)
155  {
156  $aSerials = oxRegistry::getConfig()->getConfigParam("aSerials");
157  $aSerials[] = array('attributes' => array('state' => 'new'), 'value' => $sSerial);
158 
159  return $this->validate($aSerials);
160  }
161 
169  public function validate($aSerials)
170  {
171  $aSerials = (array)$aSerials;
172  $this->_setIsException(false);
173 
174  $blResult = false;
175  try {
176  $oRequest = $this->_formRequest($aSerials);
177 
178  $oCaller = $this->_getCaller();
179  $oResponse = $oCaller->doRequest($oRequest);
180 
181  $blResult = $this->_validateResponse($oResponse);
182 
183  if ($blResult) {
184  $this->_logSuccess();
185  }
186  } catch (oxException $oEx) {
187  $this->_setErrorMessage($oEx->getMessage());
188  $this->_setIsException(true);
189  }
190 
191  return $blResult;
192  }
193 
199  protected function _setErrorMessage($sErrorMessage)
200  {
201  $this->_sErrorMessage = $sErrorMessage;
202  }
203 
209  protected function _getCaller()
210  {
211  return $this->_oCaller;
212  }
213 
223  protected function _validateResponse($oResponse)
224  {
225  if (isset($oResponse->code) && isset($oResponse->message)) {
226  if ($oResponse->code == $this->_iValidResponseCode &&
227  $oResponse->message == $this->_sValidResponseMessage
228  ) {
229  // serial keys are valid
230  $blValid = true;
231  } else {
232  // serial keys are not valid
233  $this->_setErrorMessage(oxRegistry::getLang()->translateString('OLC_ERROR_SERIAL_NOT_VALID'));
234  $blValid = false;
235  }
236  } else {
237  // validation result is unknown
238  throw new oxException('OLC_ERROR_RESPONSE_NOT_VALID');
239  }
240 
241  return $blValid;
242  }
243 
253  protected function _formRequest($aSerials)
254  {
255  $oConfig = oxRegistry::getConfig();
256 
258  $oRequest = oxNew('oxOnlineLicenseCheckRequest');
259 
260  $oRequest->revision = $oConfig->getRevision();
261 
262  $oRequest->keys = array('key' => $aSerials);
263 
264  $oRequest->productSpecificInformation = new stdClass();
265 
266  if (!is_null($this->getServersManager())) {
267  $aServers = $this->getServersManager()->getServers();
268  $oRequest->productSpecificInformation->servers = array('server' => $aServers);
269  }
270 
271  $aCounters = $this->_formCounters();
272  if (!empty($aCounters)) {
273  $oRequest->productSpecificInformation->counters = array('counter' => $aCounters);
274  }
275 
276  return $oRequest;
277  }
278 
284  protected function _formCounters()
285  {
286  $oUserCounter = $this->_getUserCounter();
287 
288  $aCounters = array();
289 
290  if (!is_null($this->getUserCounter())) {
291  $aCounters[] = array(
292  'name' => 'admin users',
293  'value' => $oUserCounter->getAdminCount(),
294  );
295  $aCounters[] = array(
296  'name' => 'active admin users',
297  'value' => $oUserCounter->getActiveAdminCount(),
298  );
299  }
300 
301  $aCounters[] = array(
302  'name' => 'subShops',
303  'value' => oxRegistry::getConfig()->getMandateCount(),
304  );
305 
306  return $aCounters;
307  }
308 
312  protected function _logSuccess()
313  {
314  $iTime = oxRegistry::get("oxUtilsDate")->getTime();
315  $sBaseShop = oxRegistry::getConfig()->getBaseShopId();
316  oxRegistry::getConfig()->saveShopConfVar("str", oxOnlineLicenseCheck::CONFIG_VAR_NAME, $iTime, $sBaseShop);
317  }
318 
324  protected function _setIsException($blIsException)
325  {
326  $this->_blIsException = $blIsException;
327  }
328 
333  protected function _startGracePeriod()
334  {
335  }
336 
342  protected function _getUserCounter()
343  {
344  return $this->_oUserCounter;
345  }
346 }