Skip to content

Commit 0e44f5f

Browse files
feat: notify admins only once per LibreSign version after upgrade
Signed-off-by: Samuelson Brito <[email protected]>
1 parent ac7ba8f commit 0e44f5f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/Migration/NotifyAdminsAfterUpgrade.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace OCA\Libresign\Migration;
66

77
use OCA\Libresign\AppInfo\Application as AppInfoApplication;
8+
use OCP\App\IAppManager;
9+
use OCP\IConfig;
10+
use OCP\IL10N;
811
use OCP\IUserManager;
912
use OCP\Migration\IOutput;
1013
use OCP\Migration\IRepairStep;
@@ -14,6 +17,8 @@ class NotifyAdminsAfterUpgrade implements IRepairStep {
1417
public function __construct(
1518
private IUserManager $userManager,
1619
private NotificationManager $notificationManager,
20+
private IConfig $config,
21+
private IAppManager $appManager,
1722
) {
1823
}
1924

@@ -22,6 +27,14 @@ public function getName(): string {
2227
}
2328

2429
public function run(IOutput $output): void {
30+
31+
$currentVersion = $currentVersion = $this->appManager->getAppVersion(AppInfoApplication::APP_ID);
32+
$lastNotifiedVersion = $this->config->getAppValue(AppInfoApplication::APP_ID, 'last_notified_version', '');
33+
34+
if ($currentVersion === $lastNotifiedVersion) {
35+
return;
36+
}
37+
2538
$admins = $this->userManager->search('', 1, 0, ['admin']);
2639
foreach ($admins as $admin) {
2740
$notification = $this->notificationManager->createNotification();
@@ -31,9 +44,12 @@ public function run(IOutput $output): void {
3144
->setDateTime(new \DateTime())
3245
->setObject('upgrade', '1')
3346
->setSubject('libresign_upgrade', [
34-
'message' => 'LibreSign has been updated! Consider supporting the project: https://libresign.coop'
47+
'message' => 'LibreSign has been updated to version ' . $currentVersion . '! Consider supporting the project: https://libresign.coop'
3548
]);
3649
$this->notificationManager->notify($notification);
3750
}
51+
52+
$this->config->setAppValue(AppInfoApplication::APP_ID, 'last_notified_version', $currentVersion);
3853
}
54+
3955
}

0 commit comments

Comments
 (0)