Fix catalog notice on the first module install

This commit is contained in:
max-baranikov 2021-10-19 18:27:25 +03:00 committed by GitHub
parent 0c072aea29
commit bf52b020da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 21 deletions

View File

@ -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()

View File

@ -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;
}