4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 13:16:37 +00:00
AzuraCast/src/Notification/Check/UpdateCheck.php

97 lines
3.2 KiB
PHP
Raw Normal View History

<?php
2021-07-19 05:53:45 +00:00
declare(strict_types=1);
namespace App\Notification\Check;
use App\Entity;
use App\Enums\GlobalPermissions;
2022-01-17 04:45:07 +00:00
use App\Enums\ReleaseChannel;
use App\Event\GetNotifications;
2021-01-11 02:41:58 +00:00
use App\Session\Flash;
use App\Version;
2022-07-01 06:06:29 +00:00
final class UpdateCheck
{
2021-04-23 05:24:12 +00:00
public function __construct(
2022-07-01 06:06:29 +00:00
private readonly Version $version,
private readonly Entity\Repository\SettingsRepository $settingsRepo
2021-04-23 05:24:12 +00:00
) {
}
public function __invoke(GetNotifications $event): void
{
// This notification is for full administrators only.
2021-06-08 06:40:49 +00:00
$acl = $event->getRequest()->getAcl();
if (!$acl->isAllowed(GlobalPermissions::All)) {
return;
}
$settings = $this->settingsRepo->readSettings();
if (!$settings->getCheckForUpdates()) {
return;
}
$updateData = $settings->getUpdateResults();
if (empty($updateData)) {
return;
}
2023-01-05 19:21:23 +00:00
$router = $event->getRequest()->getRouter();
$actionLabel = __('Update AzuraCast');
$actionUrl = $router->named('admin:updates:index');
2022-01-17 04:45:07 +00:00
$releaseChannel = $this->version->getReleaseChannelEnum();
2022-01-17 04:45:07 +00:00
if (ReleaseChannel::Stable === $releaseChannel && $updateData['needs_release_update']) {
2021-01-11 02:41:58 +00:00
$notificationParts = [
2022-05-07 16:44:14 +00:00
'<b>' . sprintf(
__('AzuraCast <a href="%s" target="_blank">version %s</a> is now available.'),
2021-01-11 02:41:58 +00:00
Version::CHANGELOG_URL,
$updateData['latest_release']
) . '</b>',
2022-05-07 16:44:14 +00:00
sprintf(
__('You are currently running version %s. Updating is highly recommended.'),
$updateData['current_release']
),
];
2021-01-11 02:41:58 +00:00
$notification = new Entity\Api\Notification();
$notification->title = __('New AzuraCast Release Version Available');
$notification->body = implode(' ', $notificationParts);
$notification->type = Flash::INFO;
$notification->actionLabel = $actionLabel;
$notification->actionUrl = $actionUrl;
$event->addNotification($notification);
return;
}
2022-01-17 04:45:07 +00:00
if (ReleaseChannel::RollingRelease === $releaseChannel && $updateData['needs_rolling_update']) {
2021-01-11 02:41:58 +00:00
$notificationParts = [];
2022-05-07 16:44:14 +00:00
$notificationParts[] = '<b>' . sprintf(
__('Your installation is currently %d update(s) behind the latest version.'),
2021-01-11 02:41:58 +00:00
$updateData['rolling_updates_available']
) . '</b>';
$notificationParts[] = sprintf(
'<a href="%s" target="_blank">' . __('View the changelog for full details.') . '</a>',
Version::CHANGELOG_URL
);
2021-01-11 02:41:58 +00:00
$notificationParts[] = __('You should update to take advantage of bug and security fixes.');
$notification = new Entity\Api\Notification();
$notification->title = __('New AzuraCast Updates Available');
$notification->body = implode(' ', $notificationParts);
$notification->type = Flash::INFO;
$notification->actionLabel = $actionLabel;
$notification->actionUrl = $actionUrl;
$event->addNotification($notification);
}
}
}