aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2023-07-27 12:04:52 +0200
committerGitHub <noreply@github.com>2023-07-27 12:04:52 +0200
commit5fbb3bb7f0ad070bf541a1401d1bc98f8b516722 (patch)
tree724fb4c2db10db8d4977eef331866b2758b594ef /apps
parentd0ac2b4494c0135b400ff8c19f7865edc6f87530 (diff)
parent46b462285d9f377348b33d44924827fb11a14e32 (diff)
downloadnextcloud-server-5fbb3bb7f0ad070bf541a1401d1bc98f8b516722.tar.gz
nextcloud-server-5fbb3bb7f0ad070bf541a1401d1bc98f8b516722.zip
Merge pull request #39522 from nextcloud/backport/39264/stable27
[stable27] Add instance category while checking new updates
Diffstat (limited to 'apps')
-rw-r--r--apps/updatenotification/lib/Notification/BackgroundJob.php58
-rw-r--r--apps/updatenotification/tests/Notification/BackgroundJobTest.php31
2 files changed, 23 insertions, 66 deletions
diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php
index f8f1f41e589..4889c931238 100644
--- a/apps/updatenotification/lib/Notification/BackgroundJob.php
+++ b/apps/updatenotification/lib/Notification/BackgroundJob.php
@@ -31,7 +31,6 @@ use OC\Updater\VersionCheck;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
-use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -40,44 +39,21 @@ use OCP\Notification\IManager;
class BackgroundJob extends TimedJob {
protected $connectionNotifications = [3, 7, 14, 30];
- /** @var IConfig */
- protected $config;
-
- /** @var IManager */
- protected $notificationManager;
-
- /** @var IGroupManager */
- protected $groupManager;
-
- /** @var IAppManager */
- protected $appManager;
-
- /** @var IClientService */
- protected $client;
-
- /** @var Installer */
- protected $installer;
-
/** @var string[] */
protected $users;
- public function __construct(ITimeFactory $timeFactory,
- IConfig $config,
- IManager $notificationManager,
- IGroupManager $groupManager,
- IAppManager $appManager,
- IClientService $client,
- Installer $installer) {
+ public function __construct(
+ ITimeFactory $timeFactory,
+ protected IConfig $config,
+ protected IManager $notificationManager,
+ protected IGroupManager $groupManager,
+ protected IAppManager $appManager,
+ protected Installer $installer,
+ protected VersionCheck $versionCheck,
+ ) {
parent::__construct($timeFactory);
// Run once a day
$this->setInterval(60 * 60 * 24);
-
- $this->config = $config;
- $this->notificationManager = $notificationManager;
- $this->groupManager = $groupManager;
- $this->appManager = $appManager;
- $this->client = $client;
- $this->installer = $installer;
}
protected function run($argument) {
@@ -104,12 +80,10 @@ class BackgroundJob extends TimedJob {
return;
}
- $updater = $this->createVersionCheck();
-
- $status = $updater->check();
+ $status = $this->versionCheck->check();
if ($status === false) {
$errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0');
- $this->config->setAppValue('updatenotification', 'update_check_errors', (string)$errors);
+ $this->config->setAppValue('updatenotification', 'update_check_errors', (string) $errors);
if (\in_array($errors, $this->connectionNotifications, true)) {
$this->sendErrorNotifications($errors);
@@ -259,16 +233,6 @@ class BackgroundJob extends TimedJob {
}
/**
- * @return VersionCheck
- */
- protected function createVersionCheck(): VersionCheck {
- return new VersionCheck(
- $this->client,
- $this->config
- );
- }
-
- /**
* @return string
*/
protected function getChannel(): string {
diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
index 70d1a918a01..df8b104e9ca 100644
--- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php
+++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
@@ -32,7 +32,6 @@ use OC\Updater\VersionCheck;
use OCA\UpdateNotification\Notification\BackgroundJob;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -51,12 +50,12 @@ class BackgroundJobTest extends TestCase {
protected $groupManager;
/** @var IAppManager|MockObject */
protected $appManager;
- /** @var IClientService|MockObject */
- protected $client;
- /** @var Installer|MockObject */
- protected $installer;
/** @var ITimeFactory|MockObject */
protected $timeFactory;
+ /** @var Installer|MockObject */
+ protected $installer;
+ /** @var VersionCheck|MockObject */
+ protected $versionCheck;
protected function setUp(): void {
parent::setUp();
@@ -65,9 +64,9 @@ class BackgroundJobTest extends TestCase {
$this->notificationManager = $this->createMock(IManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->appManager = $this->createMock(IAppManager::class);
- $this->client = $this->createMock(IClientService::class);
- $this->installer = $this->createMock(Installer::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->installer = $this->createMock(Installer::class);
+ $this->versionCheck = $this->createMock(VersionCheck::class);
}
/**
@@ -82,8 +81,8 @@ class BackgroundJobTest extends TestCase {
$this->notificationManager,
$this->groupManager,
$this->appManager,
- $this->client,
- $this->installer
+ $this->installer,
+ $this->versionCheck,
);
}
{
@@ -94,8 +93,8 @@ class BackgroundJobTest extends TestCase {
$this->notificationManager,
$this->groupManager,
$this->appManager,
- $this->client,
$this->installer,
+ $this->versionCheck,
])
->setMethods($methods)
->getMock();
@@ -160,7 +159,6 @@ class BackgroundJobTest extends TestCase {
public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays) {
$job = $this->getJob([
'getChannel',
- 'createVersionCheck',
'createNotifications',
'clearErrorNotifications',
'sendErrorNotifications',
@@ -171,17 +169,12 @@ class BackgroundJobTest extends TestCase {
->willReturn($channel);
if ($versionCheck === null) {
- $job->expects($this->never())
- ->method('createVersionCheck');
+ $this->versionCheck->expects($this->never())
+ ->method('check');
} else {
- $check = $this->createMock(VersionCheck::class);
- $check->expects($this->once())
+ $this->versionCheck->expects($this->once())
->method('check')
->willReturn($versionCheck);
-
- $job->expects($this->once())
- ->method('createVersionCheck')
- ->willReturn($check);
}
if ($version === null) {