Exemple #1
0
 /**
  * Returns upgrade class instance by given file basename
  *
  * Resolving examples:
  * 1.0.0_initial_installation   [Vendor\Module]\Upgrades\InitialInstallation
  * 1.1.0_add_used_id_column     [Vendor\Module]\Upgrades\AddUserIdColumn
  *
  * @param string $filename
  * @return \Swissup\Core\Model\Module\Upgrade
  */
 public function resolve($filename)
 {
     require_once $this->getUpgradesDir() . "/{$filename}.php";
     $className = implode(' ', array_slice(explode('_', $filename), 1));
     $className = str_replace(' ', '', ucwords($className));
     $namespace = str_replace('_', '\\', $this->module->getCode()) . '\\Upgrades';
     $className = $namespace . '\\' . $className;
     $upgrade = $this->objectManager->create($className);
     $upgrade->setMessageLogger($this->getMessageLogger());
     return $upgrade;
 }
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);
 }