Added checking for a new version of the module

This commit is contained in:
gleemand 2022-07-05 18:08:23 +03:00 committed by GitHub
parent f383ca4f30
commit fa43cfecd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 3 deletions

View file

@ -1,3 +1,6 @@
## v3.4.6
* Добавлена проверка наличия новой версии модуля
## v3.4.5
* Исправлена работа воркеров публичной части сайта

View file

@ -1 +1 @@
3.4.5
3.4.6

View file

@ -152,6 +152,8 @@ class RetailcrmSettingsHelper
$settings = new RetailcrmSettingsItems();
$result = $settings->getValueStoredAll();
$result['latestVersion'] = self::getLatestVersion();
$consultantScript = new RetailcrmSettingsItemHtml('consultantScript', RetailCRM::CONSULTANT_SCRIPT);
$result['consultantScript'] = $consultantScript->getValueStored();
@ -175,4 +177,49 @@ class RetailcrmSettingsHelper
'linkOrders' => RetailcrmTools::getAdminControllerUrl(AdminOrdersController::class),
];
}
private static function getLatestVersion()
{
$latestInfo = self::getLatestInfo();
if (
$latestInfo
&& isset(
$latestInfo['tag_name'],
$latestInfo['body'],
$latestInfo['assets'],
current($latestInfo['assets'])['browser_download_url']
)
) {
return [
'isSuccess' => true,
'isLatest' => (bool) mb_stristr($latestInfo['tag_name'], RetailCRM::VERSION),
'url' => current($latestInfo['assets'])['browser_download_url'],
'critical' => (bool) mb_stristr($latestInfo['body'], '[important]'),
];
}
return [
'isSuccess' => false,
];
}
private static function getLatestInfo()
{
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, 'https://api.github.com/repos/retailcrm/prestashop-module/releases/latest');
curl_setopt($curlHandler, CURLOPT_USERAGENT, 'Simla integration module for PrestaShop');
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 10);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 10);
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
curl_close($curlHandler);
return 200 === $statusCode ? json_decode($responseBody, true) : null;
}
}

View file

@ -48,6 +48,8 @@ require_once dirname(__FILE__) . '/bootstrap.php';
class RetailCRM extends Module
{
const VERSION = '3.4.6';
const API_URL = 'RETAILCRM_ADDRESS';
const API_KEY = 'RETAILCRM_API_TOKEN';
const DELIVERY = 'RETAILCRM_API_DELIVERY';
@ -150,7 +152,7 @@ class RetailCRM extends Module
{
$this->name = 'retailcrm';
$this->tab = 'export';
$this->version = '3.4.5';
$this->version = self::VERSION;
$this->author = 'DIGITAL RETAIL TECHNOLOGIES SL';
$this->displayName = $this->l('Simla.com');
$this->description = $this->l('Integration module for Simla.com');

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

File diff suppressed because one or more lines are too long