From bf52b020da4a5c9a79feb98d247ea5e3077191d3 Mon Sep 17 00:00:00 2001 From: max-baranikov Date: Tue, 19 Oct 2021 18:27:25 +0300 Subject: [PATCH] Fix catalog notice on the first module install --- retailcrm/lib/RetailcrmCatalogHelper.php | 43 +++++++++++++----------- retailcrm/retailcrm.php | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/retailcrm/lib/RetailcrmCatalogHelper.php b/retailcrm/lib/RetailcrmCatalogHelper.php index c98a827..050ef10 100644 --- a/retailcrm/lib/RetailcrmCatalogHelper.php +++ b/retailcrm/lib/RetailcrmCatalogHelper.php @@ -45,7 +45,7 @@ class RetailcrmCatalogHelper $date = null; $filePath = self::getIcmlFilePath(); if (!file_exists($filePath) || ($fileHandler = fopen($filePath, 'rb')) === false) { - return null; + return false; } while ($line = fgets($fileHandler)) { @@ -60,7 +60,7 @@ class RetailcrmCatalogHelper fclose($fileHandler); - return $date; + return DateTime::createFromFormat('Y-m-d H:i:s', $date); } public static function getIcmlFileLink() @@ -91,29 +91,32 @@ class RetailcrmCatalogHelper { $icmlInfo = json_decode((string)Configuration::get(self::ICML_INFO_NAME), true); - if (json_last_error() != JSON_ERROR_NONE) { + if ($icmlInfo === null || json_last_error() !== JSON_ERROR_NONE) { $icmlInfo = array(); } - $lastGenerated = DateTime::createFromFormat('Y-m-d H:i:s', self::getIcmlFileDate()); - if ($lastGenerated instanceof DateTime) { - $icmlInfo['lastGenerated'] = $lastGenerated; - $now = new DateTime(); - /** @var DateInterval $diff */ - $diff = $lastGenerated->diff($now); + $lastGenerated = self::getIcmlFileDate(); - $icmlInfo['lastGeneratedDiff'] = array( - 'days' => $diff->days, - 'hours' => $diff->h, - 'minutes' => $diff->i - ); - - $icmlInfo['isOutdated'] = ( - $icmlInfo['lastGeneratedDiff']['days'] > 0 - || $icmlInfo['lastGeneratedDiff']['hours'] > 4 - ); + if ($lastGenerated === false) { + return $icmlInfo; } + $icmlInfo['lastGenerated'] = $lastGenerated; + $now = new DateTime(); + /** @var DateInterval $diff */ + $diff = $lastGenerated->diff($now); + + $icmlInfo['lastGeneratedDiff'] = array( + 'days' => $diff->days, + 'hours' => $diff->h, + 'minutes' => $diff->i + ); + + $icmlInfo['isOutdated'] = ( + $icmlInfo['lastGeneratedDiff']['days'] > 0 + || $icmlInfo['lastGeneratedDiff']['hours'] > 4 + ); + $api = RetailcrmTools::getApiClient(); if ($api !== null) { @@ -126,7 +129,7 @@ class RetailcrmCatalogHelper } } - return (array)$icmlInfo; + return $icmlInfo; } public static function getIcmlFileInfoMultistore() diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 129298b..1f06e0e 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -1274,7 +1274,7 @@ class RetailCRM extends Module return false; } } - } elseif ($icmlInfo['isOutdated'] || !$icmlInfo['isUrlActual']) { + } elseif ($icmlInfo['isOutdated'] || (isset($icmlInfo['isUrlActual']) && $icmlInfo['isUrlActual'] === false)) { return false; }