/** * Check if extension can be registered * @param string $extension */ protected function checkActivation($extension) { $wsUrl = sprintf(self::WS_URL, $this->_version); $ext = "" . strtolower(str_replace("./", "", $extension["value"])); $activationKey = $this->_coreHelper->getDefaultConfigUncrypted($ext . "/license/activation_key"); $activationFlag = $this->_coreHelper->getDefaultConfig($ext . "/license/activation_flag"); $licensingMethod = $this->_coreHelper->getDefaultConfig($ext . "/license/get_online_license"); $licenseCode = $this->_coreHelper->getDefaultConfigUncrypted($ext . "/license/activation_code"); $domain = $this->_coreHelper->getDefaultConfig("web/secure/base_url"); $registeredVersion = $this->_coreHelper->getDefaultConfig($ext . "/license/version"); $currentVersion = $extension["version"]; $wsParam = "&rv=" . $registeredVersion . "&cv=" . $currentVersion . "&namespace=" . $ext . "&activation_key=" . $activationKey . "&domain=" . $domain . "&magento=" . $this->_magentoVersion; $soapParams = ["method" => "get", "rv" => $registeredVersion, "cv" => $currentVersion, "namespace" => $ext, "activation_key" => $activationKey, "domain" => $domain, "magento" => $this->_magentoVersion, "licensemanager" => $this->_version]; // licence supprimée car mauvais ak ou ac if ($activationFlag == "1") { $this->addWarning($extension["label"], "flag", [$this->_urlBuilder->getUrl("adminhtml/system_config/edit/section/" . $ext . "/"), $extension["label"]]); } elseif ($registeredVersion != "" && $registeredVersion != $currentVersion && $licenseCode) { // Extension upgrade $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); $this->addWarning($extension["label"], "upgrade", [$registeredVersion, $currentVersion]); $this->_session->setData("update_" . $extension["value"], "true"); $this->_refreshCache = true; } elseif (!$activationKey) { // no activation key not yet registered $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); $this->addWarning($extension["label"], "activation_key_warning", [$this->_urlBuilder->getUrl("adminhtml/system_config/edit/section/" . $ext . "/"), $extension["label"]]); $this->_refreshCache = true; } elseif ($activationKey && (!$licenseCode || empty($licenseCode)) && !$licensingMethod) { // not yet activated --> manual activation $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); if ($this->_session->getData("update_" . $extension["value"]) != "true") { $this->addWarning($extension["label"], "license_code_warning", [$wsUrl . "method=post" . $wsParam]); } else { $this->addWarning($extension["label"], "license_code_updated_warning", [$wsUrl . "method=post" . $wsParam]); } $this->_refreshCache = true; } elseif ($activationKey && (!$licenseCode || empty($licenseCode)) && $licensingMethod) { // not yet activated --> automatic activation try { $options = ['location' => self::SOAP_URL, 'uri' => self::SOAP_URI]; if (!class_exists("\\SoapClient")) { throw new \Exception(); } $api = new \SoapClient(null, $options); $ws = $api->checkActivation($soapParams); $wsResult = json_decode($ws); switch ($wsResult->status) { case "success": $this->addWarning($extension["label"], "ws_success", [$wsResult->message], true); $this->_coreHelper->setDefaultConfig($ext . "/license/version", $wsResult->version); $this->_coreHelper->setDefaultConfigCrypted($ext . "/license/activation_code", $wsResult->activation); $this->_refreshCache = true; break; case "error": $this->addWarning($extension["label"], "ws_failure", [$wsResult->message]); $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); $this->_refreshCache = true; break; default: $this->addWarning($extension["label"], "ws_error", [$wsUrl . "method=post" . $wsParam]); $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); $this->_coreHelper->setDefaultConfig($ext . "/license/get_online_license", "0"); $this->_refreshCache = true; break; } } catch (\Exception $e) { $this->addWarning($extension["label"], "ws_no_allowed", [$wsUrl . "method=post" . $wsParam]); $this->_coreHelper->setDefaultConfig($ext . "/license/activation_code", ""); $this->_coreHelper->setDefaultConfig($ext . "/license/get_online_license", "0"); $this->_refreshCache = true; } } }