Skip to content

Commit a55bb16

Browse files
committed
refactor(updatenotification): migrate to Vue 3
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent b888c42 commit a55bb16

26 files changed

Lines changed: 191 additions & 285 deletions

apps/updatenotification/lib/AppInfo/Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
use Psr\Log\LoggerInterface;
3232

3333
class Application extends App implements IBootstrap {
34-
public const APP_NAME = 'updatenotification';
34+
public const APP_ID = 'updatenotification';
3535

3636
public function __construct() {
37-
parent::__construct(self::APP_NAME, []);
37+
parent::__construct(self::APP_ID, []);
3838
}
3939

4040
#[\Override]
@@ -76,7 +76,7 @@ public function boot(IBootContext $context): void {
7676
}
7777

7878
if ($updateChecker->getUpdateState() !== []) {
79-
Util::addScript(self::APP_NAME, 'update-notification-legacy');
79+
Util::addScript(self::APP_ID, 'update-notification-legacy');
8080
$updateChecker->setInitialState();
8181
}
8282
}

apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function run(mixed $argument): void {
4848
$this->logger->debug(
4949
'Running background job to create app update notifications for "' . $appId . '"',
5050
[
51-
'app' => Application::APP_NAME,
51+
'app' => Application::APP_ID,
5252
],
5353
);
5454

@@ -61,7 +61,7 @@ protected function run(mixed $argument): void {
6161

6262
// Create new notifications
6363
$notification = $this->notificationManager->createNotification();
64-
$notification->setApp(Application::APP_NAME)
64+
$notification->setApp(Application::APP_ID)
6565
->setDateTime($dateTime)
6666
->setSubject('app_updated', [$appId])
6767
->setObject('app_updated', $appId);
@@ -75,7 +75,7 @@ protected function run(mixed $argument): void {
7575
*/
7676
private function stopPreviousNotifications(string $appId): void {
7777
$notification = $this->notificationManager->createNotification();
78-
$notification->setApp(Application::APP_NAME)
78+
$notification->setApp(Application::APP_ID)
7979
->setObject('app_updated', $appId);
8080
$this->notificationManager->markProcessed($notification);
8181
}

apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ protected function sendErrorNotifications($numDays): void {
112112

113113
$notification = $this->notificationManager->createNotification();
114114
try {
115-
$notification->setApp(Application::APP_NAME)
115+
$notification->setApp(Application::APP_ID)
116116
->setDateTime(new \DateTime())
117-
->setObject(Application::APP_NAME, 'error')
117+
->setObject(Application::APP_ID, 'error')
118118
->setSubject('connection_error', ['days' => $numDays]);
119119

120120
foreach ($this->getUsersToNotify() as $uid) {
@@ -132,9 +132,9 @@ protected function sendErrorNotifications($numDays): void {
132132
protected function clearErrorNotifications(): void {
133133
$notification = $this->notificationManager->createNotification();
134134
try {
135-
$notification->setApp(Application::APP_NAME)
135+
$notification->setApp(Application::APP_ID)
136136
->setSubject('connection_error')
137-
->setObject(Application::APP_NAME, 'error');
137+
->setObject(Application::APP_ID, 'error');
138138
} catch (\InvalidArgumentException $e) {
139139
return;
140140
}
@@ -175,7 +175,7 @@ protected function createNotifications($app, $version, $visibleVersion = ''): vo
175175

176176
$notification = $this->notificationManager->createNotification();
177177
try {
178-
$notification->setApp(Application::APP_NAME)
178+
$notification->setApp(Application::APP_ID)
179179
->setDateTime(new \DateTime())
180180
->setObject($app, $version);
181181

@@ -228,7 +228,7 @@ protected function getUsersToNotify(): array {
228228
protected function deleteOutdatedNotifications($app, $version): void {
229229
$notification = $this->notificationManager->createNotification();
230230
try {
231-
$notification->setApp(Application::APP_NAME)
231+
$notification->setApp(Application::APP_ID)
232232
->setObject($app, $version);
233233
} catch (\InvalidArgumentException) {
234234
return;

apps/updatenotification/lib/Controller/ChangelogController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function showChangelog(string $app, ?string $version = null): TemplateRes
4949
// Remove version headline
5050
/** @var string[] */
5151
$changes = explode("\n", $changes, 2);
52-
$changes = trim(end($changes));
52+
$changes = trim(array_last($changes) ?? '');
5353

5454
$this->initialState->provideInitialState('changelog', [
5555
'appName' => $appName,

apps/updatenotification/lib/Listener/AppUpdateEventListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function handle(Event $event): void {
3636
return;
3737
}
3838

39-
if (!$this->appConfig->getValueBool(Application::APP_NAME, 'app_updated.enabled', true)) {
39+
if (!$this->appConfig->getValueBool(Application::APP_ID, 'app_updated.enabled', true)) {
4040
return;
4141
}
4242

@@ -55,7 +55,7 @@ public function handle(Event $event): void {
5555
$this->logger->debug(
5656
'Scheduled app update notification for "' . $event->getAppId() . '"',
5757
[
58-
'app' => Application::APP_NAME,
58+
'app' => Application::APP_ID,
5959
],
6060
);
6161
}

apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function handle(Event $event): void {
3636
return;
3737
}
3838

39-
if (!$this->appConfig->getValueBool(Application::APP_NAME, 'app_updated.enabled', true)) {
39+
if (!$this->appConfig->getValueBool(Application::APP_ID, 'app_updated.enabled', true)) {
4040
return;
4141
}
4242

@@ -50,6 +50,6 @@ public function handle(Event $event): void {
5050
return;
5151
}
5252

53-
Util::addInitScript(Application::APP_NAME, 'init');
53+
Util::addInitScript(Application::APP_ID, 'init');
5454
}
5555
}

apps/updatenotification/lib/Notification/AppUpdateNotifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getID(): string {
4343
*/
4444
#[\Override]
4545
public function getName(): string {
46-
return $this->l10nFactory->get(Application::APP_NAME)->t('App updated');
46+
return $this->l10nFactory->get(Application::APP_ID)->t('App updated');
4747
}
4848

4949
/**
@@ -55,7 +55,7 @@ public function getName(): string {
5555
*/
5656
#[\Override]
5757
public function prepare(INotification $notification, string $languageCode): INotification {
58-
if ($notification->getApp() !== Application::APP_NAME) {
58+
if ($notification->getApp() !== Application::APP_ID) {
5959
throw new UnknownNotificationException('Unknown app');
6060
}
6161

@@ -70,7 +70,7 @@ public function prepare(INotification $notification, string $languageCode): INot
7070
}
7171

7272
// Prepare translation factory for requested language
73-
$l = $this->l10nFactory->get(Application::APP_NAME, $languageCode);
73+
$l = $this->l10nFactory->get(Application::APP_ID, $languageCode);
7474

7575
$icon = $this->appManager->getAppIcon($appId, true);
7676
if ($icon === null) {

apps/updatenotification/lib/Notification/Notifier.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
*/
5353
#[\Override]
5454
public function getID(): string {
55-
return Application::APP_NAME;
55+
return Application::APP_ID;
5656
}
5757

5858
/**
@@ -63,7 +63,7 @@ public function getID(): string {
6363
*/
6464
#[\Override]
6565
public function getName(): string {
66-
return $this->l10NFactory->get(Application::APP_NAME)->t('Update notifications');
66+
return $this->l10NFactory->get(Application::APP_ID)->t('Update notifications');
6767
}
6868

6969
/**
@@ -76,15 +76,15 @@ public function getName(): string {
7676
*/
7777
#[\Override]
7878
public function prepare(INotification $notification, string $languageCode): INotification {
79-
if ($notification->getApp() !== Application::APP_NAME) {
79+
if ($notification->getApp() !== Application::APP_ID) {
8080
throw new UnknownNotificationException('Unknown app id');
8181
}
8282

8383
if ($notification->getSubject() !== 'update_available' && $notification->getSubject() !== 'connection_error') {
8484
throw new UnknownNotificationException('Unknown subject');
8585
}
8686

87-
$l = $this->l10NFactory->get(Application::APP_NAME, $languageCode);
87+
$l = $this->l10NFactory->get(Application::APP_ID, $languageCode);
8888
if ($notification->getSubject() === 'connection_error') {
8989
$errors = $this->appConfig->getAppValueInt('update_check_errors', 0);
9090
if ($errors === 0) {
@@ -131,7 +131,7 @@ public function prepare(INotification $notification, string $languageCode): INot
131131
}
132132
}
133133

134-
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_NAME, 'notification.svg')));
134+
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'notification.svg')));
135135

136136
return $notification;
137137
}

apps/updatenotification/lib/Settings/Admin.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getForm(): TemplateResponse {
5858

5959
$updateState = $this->updateChecker->getUpdateState();
6060

61-
$notifyGroups = $this->appConfig->getValueArray(Application::APP_NAME, 'notify_groups', ['admin']);
61+
$notifyGroups = $this->appConfig->getValueArray(Application::APP_ID, 'notify_groups', ['admin']);
6262

6363
$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
6464
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
@@ -90,7 +90,9 @@ public function getForm(): TemplateResponse {
9090
];
9191
$this->initialState->provideInitialState('data', $params);
9292

93-
return new TemplateResponse('updatenotification', 'admin', [], '');
93+
\OCP\Util::addStyle(Application::APP_ID, 'settings-admin');
94+
\OCP\Util::addScript(Application::APP_ID, 'settings-admin');
95+
return new TemplateResponse(Application::APP_ID, 'admin', [], '');
9496
}
9597

9698
protected function filterChanges(array $changes): array {

apps/updatenotification/src/components/Markdown.vue

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)