Skip to content

Commit 30c2689

Browse files
committed
Add instance category while checking new updates
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent 0d78334 commit 30c2689

3 files changed

Lines changed: 43 additions & 47 deletions

File tree

apps/updatenotification/lib/Notification/BackgroundJob.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,22 @@
4040
class BackgroundJob extends TimedJob {
4141
protected $connectionNotifications = [3, 7, 14, 30];
4242

43-
/** @var IConfig */
44-
protected $config;
45-
46-
/** @var IManager */
47-
protected $notificationManager;
48-
49-
/** @var IGroupManager */
50-
protected $groupManager;
51-
52-
/** @var IAppManager */
53-
protected $appManager;
54-
55-
/** @var IClientService */
56-
protected $client;
57-
58-
/** @var Installer */
59-
protected $installer;
60-
6143
/** @var string[] */
6244
protected $users;
6345

64-
public function __construct(ITimeFactory $timeFactory,
65-
IConfig $config,
66-
IManager $notificationManager,
67-
IGroupManager $groupManager,
68-
IAppManager $appManager,
69-
IClientService $client,
70-
Installer $installer) {
46+
public function __construct(
47+
ITimeFactory $timeFactory,
48+
protected IConfig $config,
49+
protected IManager $notificationManager,
50+
protected IUserManager $userManager,
51+
protected IGroupManager $groupManager,
52+
protected IAppManager $appManager,
53+
protected IClientService $client,
54+
protected Installer $installer
55+
) {
7156
parent::__construct($timeFactory);
7257
// Run once a day
7358
$this->setInterval(60 * 60 * 24);
74-
75-
$this->config = $config;
76-
$this->notificationManager = $notificationManager;
77-
$this->groupManager = $groupManager;
78-
$this->appManager = $appManager;
79-
$this->client = $client;
80-
$this->installer = $installer;
8159
}
8260

8361
protected function run($argument) {
@@ -264,7 +242,8 @@ protected function deleteOutdatedNotifications($app, $version) {
264242
protected function createVersionCheck(): VersionCheck {
265243
return new VersionCheck(
266244
$this->client,
267-
$this->config
245+
$this->config,
246+
$this->userManager,
268247
);
269248
}
270249

apps/updatenotification/tests/Notification/BackgroundJobTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function setUp(): void {
6363

6464
$this->config = $this->createMock(IConfig::class);
6565
$this->notificationManager = $this->createMock(IManager::class);
66+
$this->userManager = $this->createMock(IUserManager::class);
6667
$this->groupManager = $this->createMock(IGroupManager::class);
6768
$this->appManager = $this->createMock(IAppManager::class);
6869
$this->client = $this->createMock(IClientService::class);
@@ -80,6 +81,7 @@ protected function getJob(array $methods = []) {
8081
$this->timeFactory,
8182
$this->config,
8283
$this->notificationManager,
84+
$this->userManager,
8385
$this->groupManager,
8486
$this->appManager,
8587
$this->client,

lib/private/Updater/VersionCheck.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,15 @@
2828

2929
use OCP\Http\Client\IClientService;
3030
use OCP\IConfig;
31+
use OCP\IUserManager;
3132
use OCP\Util;
3233

3334
class VersionCheck {
34-
/** @var IClientService */
35-
private $clientService;
36-
37-
/** @var IConfig */
38-
private $config;
39-
40-
/**
41-
* @param IClientService $clientService
42-
* @param IConfig $config
43-
*/
44-
public function __construct(IClientService $clientService,
45-
IConfig $config) {
46-
$this->clientService = $clientService;
47-
$this->config = $config;
35+
public function __construct(
36+
private IClientService $clientService,
37+
private IConfig $config,
38+
private IUserManager $userManager,
39+
) {
4840
}
4941

5042

@@ -81,6 +73,8 @@ public function check() {
8173
$version['php_major'] = PHP_MAJOR_VERSION;
8274
$version['php_minor'] = PHP_MINOR_VERSION;
8375
$version['php_release'] = PHP_RELEASE_VERSION;
76+
$version['category'] = $this->computeCategory();
77+
$version['isSubscriber'] = (int) $this->config->getAppValue('support', 'subscription_key', '0');
8478
$versionString = implode('x', $version);
8579

8680
//fetch xml data from updater
@@ -130,4 +124,25 @@ protected function getUrlContent($url) {
130124
$response = $client->get($url);
131125
return $response->getBody();
132126
}
127+
128+
private function computeCategory() {
129+
$categoryBoundaries = [
130+
100,
131+
500,
132+
1000,
133+
5000,
134+
10000,
135+
100000,
136+
1000000,
137+
];
138+
139+
$nbUsers = array_sum($this->userManager->countUsers());
140+
foreach ($categoryBoundaries as $categoryId => $boundary) {
141+
if ($nbUsers <= $boundary) {
142+
return $categoryId;
143+
}
144+
}
145+
146+
return $categoryId + 1;
147+
}
133148
}

0 commit comments

Comments
 (0)