diff --git a/application/Espo/Core/Utils/AdminNotificationManager.php b/application/Espo/Core/Utils/AdminNotificationManager.php index 084b258ed8..bf97bf3441 100644 --- a/application/Espo/Core/Utils/AdminNotificationManager.php +++ b/application/Espo/Core/Utils/AdminNotificationManager.php @@ -117,7 +117,7 @@ class AdminNotificationManager { $config = $this->getConfig(); - $latestVersion = $config->get('latestAvailableVersion'); + $latestVersion = $config->get('latestVersion'); if (isset($latestVersion)) { $currentVersion = $config->get('version'); if (version_compare($latestVersion, $currentVersion, '>')) { @@ -135,9 +135,9 @@ class AdminNotificationManager $extensions = []; - $latestAvailableExtensionsVersions = $config->get('latestAvailableExtensionsVersions'); - if (!empty($latestAvailableExtensionsVersions) && is_array($latestAvailableExtensionsVersions)) { - foreach ($latestAvailableExtensionsVersions as $extensionName => $extensionLatestVersion) { + $latestExtensionVersions = $config->get('latestExtensionVersions'); + if (!empty($latestExtensionVersions) && is_array($latestExtensionVersions)) { + foreach ($latestExtensionVersions as $extensionName => $extensionLatestVersion) { $currentVersion = $this->getExtensionLatestInstalledVersion($extensionName); if (isset($currentVersion) && version_compare($extensionLatestVersion, $currentVersion, '>')) { $extensions[$extensionName] = array( diff --git a/application/Espo/Jobs/NewVersionChecker.php b/application/Espo/Jobs/NewVersionChecker.php new file mode 100644 index 0000000000..3ec7752de4 --- /dev/null +++ b/application/Espo/Jobs/NewVersionChecker.php @@ -0,0 +1,76 @@ +getConfig(); + + if (!$config->get('adminNotifications') || $config->get('adminNotificationNewVersionCheckerDisabled')) { + return true; + } + + $latestRelease = $this->getLatestRelease(); + if (!empty($latestRelease['version']) && $config->get('latestVersion') != $latestRelease['version']) { + $config->set('latestVersion', $latestRelease['version']); + $config->save(); + } + + return true; + } + + protected function getLatestRelease($url = null, array $requestData = ['action' => 'latestRelease']) + { + if (function_exists('curl_version')) { + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url ? $url : base64_decode('aHR0cHM6Ly9zLmVzcG9jcm0uY29tLw==')); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestData)); + + $result = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($httpCode === 200) { + $data = json_decode($result, true); + if (is_array($data)) { + return $data; + } + } + } + } +} \ No newline at end of file diff --git a/application/Espo/Jobs/SchecduleNewVersionChecker.php b/application/Espo/Jobs/SchecduleNewVersionChecker.php new file mode 100644 index 0000000000..d4165de00c --- /dev/null +++ b/application/Espo/Jobs/SchecduleNewVersionChecker.php @@ -0,0 +1,79 @@ +getConfig()->get('adminNotifications') || $this->getConfig()->get('adminNotificationNewVersionCheckerDisabled')) { + return true; + } + + $scheduledJob = $this->getEntityManager()->getRepository('ScheduledJob')->where(array( + 'job' => 'SchecduleNewVersionChecker', + 'status' => 'Active', + ))->findOne(); + + if ($scheduledJob) { + $job = $this->getEntityManager()->getEntity('Job'); + $job->set(array( + 'name' => 'NewVersionChecker', + 'method' => 'NewVersionChecker', + 'scheduledJobId' => $scheduledJob->get('id'), + 'executeTime' => $this->getRunTime(), + )); + + $this->getEntityManager()->saveEntity($job); + } + + return true; + } + + protected function getRunTime() + { + $hour = rand(0, 4); + $minute = rand(0, 60); + + $nextDay = new \DateTime('+ 1 day'); + $time = $nextDay->format('Y-m-d') . ' ' . $hour . ':' . $minute . ':00'; + + $timeZone = $this->getConfig()->get('timeZone'); + if (empty($timeZone)) { + $timeZone = 'UTC'; + } + + $datetime = new \DateTime($time, new \DateTimeZone($timeZone)); + + return $datetime->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s'); + } +} \ No newline at end of file diff --git a/application/Espo/Resources/i18n/en_US/Settings.json b/application/Espo/Resources/i18n/en_US/Settings.json index e355f9acb6..a33e93a99b 100644 --- a/application/Espo/Resources/i18n/en_US/Settings.json +++ b/application/Espo/Resources/i18n/en_US/Settings.json @@ -90,7 +90,8 @@ "currencyDecimalPlaces": "Currency Decimal Places", "aclStrictMode": "ACL Strict Mode", "aclAllowDeleteCreated": "Allow to remove created records", - "adminNotifications": "System notifications in administration panel" + "adminNotifications": "System notifications in administration panel", + "adminNotificationNewVersionCheckerDisabled": "Disable notification about new EspoCRM version" }, "options": { "weekStart": { diff --git a/application/Espo/Resources/layouts/Settings/notifications.json b/application/Espo/Resources/layouts/Settings/notifications.json index 882fbb6cab..f2ee9ef855 100644 --- a/application/Espo/Resources/layouts/Settings/notifications.json +++ b/application/Espo/Resources/layouts/Settings/notifications.json @@ -18,7 +18,8 @@ { "label": "Admin Notifications", "rows": [ - [{"name": "adminNotifications"}, false] + [{"name": "adminNotifications"}, false], + [{"name": "adminNotificationNewVersionCheckerDisabled"}, false] ] } ] \ No newline at end of file diff --git a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json index 53a38dd26c..4ab288efc0 100644 --- a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json +++ b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json @@ -77,6 +77,10 @@ "Dummy": { "isSystem": true, "scheduling": "1 */12 * * *" + }, + "SchecduleNewVersionChecker": { + "isSystem": true, + "scheduling": "15 5 * * *" } } } diff --git a/application/Espo/Resources/metadata/entityDefs/Settings.json b/application/Espo/Resources/metadata/entityDefs/Settings.json index 550695d307..a2b865e907 100644 --- a/application/Espo/Resources/metadata/entityDefs/Settings.json +++ b/application/Espo/Resources/metadata/entityDefs/Settings.json @@ -436,6 +436,9 @@ }, "adminNotifications": { "type": "bool" + }, + "adminNotificationNewVersionCheckerDisabled": { + "type": "bool" } } } diff --git a/client/src/views/admin/notifications.js b/client/src/views/admin/notifications.js index bfb683d207..5fea88681d 100644 --- a/client/src/views/admin/notifications.js +++ b/client/src/views/admin/notifications.js @@ -48,6 +48,22 @@ Espo.define('views/admin/notifications', 'views/settings/record/edit', function fields: ['assignmentEmailNotificationsEntityList'] } ] + }, + 'adminNotifications': { + map: { + true: [ + { + action: 'show', + fields: ['adminNotificationNewVersionCheckerDisabled'] + } + ] + }, + default: [ + { + action: 'hide', + fields: ['adminNotificationNewVersionCheckerDisabled'] + } + ] } },