Exemple #1
0
 /**
  * Returns loded module object with copied new_store_ids and skip_upgrade
  * instructions into it
  *
  * @return Swissup\Core\Model\Module
  */
 protected function getModuleObject($code)
 {
     $module = $this->moduleFactory->create()->load($code)->setNewStores($this->module->getNewStores());
     if (!$module->getIdentityKey()) {
         $module->setIdentityKey($this->module->getIdentityKey());
     }
     return $module;
 }
Exemple #2
0
 /**
  * Validate module using curl request
  *
  * @return boolean|array
  */
 public function validate()
 {
     if (!$this->canValidate()) {
         return true;
     }
     $key = trim($this->module->getIdentityKey());
     if (empty($key)) {
         return ['error' => ['Identity key is required']];
     }
     // key format is: encoded_site:secret_key:optional_suffix
     $parts = explode(':', $key);
     if (count($parts) < 3) {
         return ['error' => ['Identity key is not valid']];
     }
     list($site, $secret, $suffix) = explode(':', $key);
     try {
         $client = $this->httpClientFactory->create();
         $client->setUri($this->getUrl($site));
         $client->setConfig(['maxredirects' => 5, 'timeout' => 30]);
         $client->setParameterGet('key', $secret);
         $client->setParameterGet('suffix', $suffix);
         $purchaseCode = $this->module->getRemote()->getPurchaseCode();
         if (!$purchaseCode) {
             $purchaseCode = $this->module->getCode();
         }
         $client->setParameterGet('module', $purchaseCode);
         $client->setParameterGet('module_code', $this->module->getCode());
         if ($this->module->getConfigSection()) {
             $client->setParameterGet('config_section', $this->module->getConfigSection());
         }
         $client->setParameterGet('domain', $this->request->getHttpHost());
         $response = $client->request();
         $responseBody = $response->getBody();
     } catch (\Exception $e) {
         return ['error' => ['Response error: %1', $e->getMessage()], 'response' => $e->getTraceAsString()];
     }
     return $this->parseResponse($responseBody);
 }