New version checker

This commit is contained in:
Taras Machyshyn
2017-12-06 16:23:11 +02:00
parent 4f98f39f2a
commit 4ceae087fa
8 changed files with 186 additions and 6 deletions
@@ -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(
@@ -0,0 +1,76 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2017 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Jobs;
use Espo\Core\Exceptions;
class NewVersionChecker extends \Espo\Core\Jobs\Base
{
public function run()
{
$config = $this->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;
}
}
}
}
}
@@ -0,0 +1,79 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2017 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Jobs;
use Espo\Core\Exceptions;
class SchecduleNewVersionChecker extends \Espo\Core\Jobs\Base
{
public function run()
{
if (!$this->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');
}
}
@@ -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": {
@@ -18,7 +18,8 @@
{
"label": "Admin Notifications",
"rows": [
[{"name": "adminNotifications"}, false]
[{"name": "adminNotifications"}, false],
[{"name": "adminNotificationNewVersionCheckerDisabled"}, false]
]
}
]
@@ -77,6 +77,10 @@
"Dummy": {
"isSystem": true,
"scheduling": "1 */12 * * *"
},
"SchecduleNewVersionChecker": {
"isSystem": true,
"scheduling": "15 5 * * *"
}
}
}
@@ -436,6 +436,9 @@
},
"adminNotifications": {
"type": "bool"
},
"adminNotificationNewVersionCheckerDisabled": {
"type": "bool"
}
}
}
+16
View File
@@ -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']
}
]
}
},