Skip to content

Commit

Permalink
Fix error when check for module updates failed (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackcoder87 authored Dec 15, 2024
1 parent 6abb594 commit 98d2f6c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
53 changes: 30 additions & 23 deletions application/modules/admin/controllers/admin/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,45 @@ public function indexAction()
$versions = $update->getVersions();

if (!$versions) {
// Check for ilch update failed.
$this->getView()->set('curlErrorOccurred', true);
$this->addMessage($this->getTranslator()->trans('versionQueryFailedWith', curl_error($update->getTransferUrl())), 'danger');
} else {
// If a check for an ilch update was successfull then check for module updates and the latest news as well.
$countOfUpdatesAvailable = 0;
$modulesList = url_get_contents($this->getConfig()->get('updateserver') . 'modules.json');
$modulesOnUpdateServer = json_decode($modulesList);
$versionsOfModules = $moduleMapper->getVersionsOfModules();
foreach ($modulesOnUpdateServer as $moduleOnUpdateServer) {
if (in_array($moduleOnUpdateServer->key, $modules) && version_compare($versionsOfModules[$moduleOnUpdateServer->key]['version'], $moduleOnUpdateServer->version, '<')) {
++$countOfUpdatesAvailable;

if ($modulesList === false) {
// Check for module updates failed.
$this->addMessage($this->getTranslator()->trans('checkForModuleUpdatesFailed'), 'danger');
} else {
$modulesOnUpdateServer = json_decode($modulesList);
$versionsOfModules = $moduleMapper->getVersionsOfModules();
foreach ($modulesOnUpdateServer as $moduleOnUpdateServer) {
if (in_array($moduleOnUpdateServer->key, $modules) && version_compare($versionsOfModules[$moduleOnUpdateServer->key]['version'], $moduleOnUpdateServer->version, '<')) {
++$countOfUpdatesAvailable;
}
}
}

$notificationsMapper = new NotificationsMapper();
if ($countOfUpdatesAvailable) {
$notifications = $notificationsMapper->getNotificationsByType('adminModuleUpdatesAvailable');
$currentTime = new Date();
$notificationModel = new NotificationModel();
$notificationModel->setModule('admin');
$notificationModel->setMessage($this->getTranslator()->trans('moduleUpdatesAvailable', $countOfUpdatesAvailable));
$notificationModel->setURL($this->getLayout()->getUrl(['controller' => 'modules', 'action' => 'updates']));
$notificationModel->setType('adminModuleUpdatesAvailable');
if (!$notifications) {
$notificationsMapper->addNotification($notificationModel);
} elseif ((strtotime($currentTime->toDb(true)) - strtotime($notifications[count($notifications) - 1]->getTimestamp()) > 86400)) {
$notificationModel->setId($notifications[count($notifications) - 1]->getId());
$notificationsMapper->updateNotificationById($notificationModel);
$notificationsMapper = new NotificationsMapper();
if ($countOfUpdatesAvailable) {
$notifications = $notificationsMapper->getNotificationsByType('adminModuleUpdatesAvailable');
$currentTime = new Date();
$notificationModel = new NotificationModel();
$notificationModel->setModule('admin');
$notificationModel->setMessage($this->getTranslator()->trans('moduleUpdatesAvailable', $countOfUpdatesAvailable));
$notificationModel->setURL($this->getLayout()->getUrl(['controller' => 'modules', 'action' => 'updates']));
$notificationModel->setType('adminModuleUpdatesAvailable');
if (!$notifications) {
$notificationsMapper->addNotification($notificationModel);
} elseif ((strtotime($currentTime->toDb(true)) - strtotime($notifications[count($notifications) - 1]->getTimestamp()) > 86400)) {
$notificationModel->setId($notifications[count($notifications) - 1]->getId());
$notificationsMapper->updateNotificationById($notificationModel);
}
} else {
// There are no module updates available. Delete notifications.
$notificationsMapper->deleteNotificationsByType('adminModuleUpdatesAvailable');
}
} else {
// There are no module updates available. Delete notifications.
$notificationsMapper->deleteNotificationsByType('adminModuleUpdatesAvailable');
}

// Load the latest news.
Expand Down
1 change: 1 addition & 0 deletions application/modules/admin/translations/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
'lastUpdateUnknown' => 'unbekannt',
'lastUpdateError' => 'Abfrage des Updateservers fehlgeschlagen.',
'layoutModuleNotInstalled' => 'Das dazugehörige Modul ist nicht installiert.',
'checkForModuleUpdatesFailed' => 'Abfrage des Updateservers auf Modul-Updates fehlgeschlagen.',

'menuInfos' => 'Informationen',
'menuPHPInfo' => 'PHP Info',
Expand Down
1 change: 1 addition & 0 deletions application/modules/admin/translations/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
'lastUpdateUnknown' => 'unknown',
'lastUpdateError' => 'Querying the updateserver failed.',
'layoutModuleNotInstalled' => 'The associated module is not installed.',
'checkForModuleUpdatesFailed' => 'Querying the updateserver for modules updates failed.',

'menuInfos' => 'Information',
'menuPHPInfo' => 'PHP Info',
Expand Down

0 comments on commit 98d2f6c

Please sign in to comment.