summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2022-06-14 13:11:39 +0200
committerGitHub <noreply@github.com>2022-06-14 13:11:39 +0200
commit75e3b331ceba82efe777969d6a9ec83ce0a11200 (patch)
tree957563d4849e77bf1ba0109846387270550e1eed
parent7ff460a46ec1efad6c1f270f4f6d2064a8193af6 (diff)
parentba7913dff39229edc1e670b25e24f8a487286163 (diff)
Merge pull request #2786 from nextcloud/backport/2785/stable4.1
[stable4.1] Avoid running social update background job on deleted/disabled users
-rw-r--r--lib/Cron/SocialUpdate.php17
-rw-r--r--lib/Cron/SocialUpdateRegistration.php2
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/Cron/SocialUpdate.php b/lib/Cron/SocialUpdate.php
index cfb5a92d..dfd2989e 100644
--- a/lib/Cron/SocialUpdate.php
+++ b/lib/Cron/SocialUpdate.php
@@ -32,19 +32,24 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob;
+use OCP\IUserManager;
class SocialUpdate extends QueuedJob {
/** @var SocialApiService */
private $social;
/** @var IJobList */
private $jobList;
+ /** @var IUserManager */
+ private $userManager;
public function __construct(ITimeFactory $time,
SocialApiService $social,
- IJobList $jobList) {
+ IJobList $jobList,
+ IUserManager $userManager) {
parent::__construct($time);
$this->social = $social;
$this->jobList = $jobList;
+ $this->userManager = $userManager;
}
protected function run($arguments) {
@@ -52,6 +57,11 @@ class SocialUpdate extends QueuedJob {
$offsetBook = $arguments['offsetBook'] ?? null;
$offsetContact = $arguments['offsetContact'] ?? null;
+ // No need to do anything if the user is gone anyway
+ if (!$this->userManager->userExists($userId)) {
+ return;
+ }
+
// update contacts with first available social media profile
$result = $this->social->updateAddressbooks($userId, $offsetBook, $offsetContact);
@@ -62,13 +72,12 @@ class SocialUpdate extends QueuedJob {
$stoppedAtContact = $report[0]['stoppedAt']['contact'];
// make sure the offset contact/address book are still existing
- if ($this->social->existsAddressBook($stoppedAtBook, $userId) == false) {
+ if (!$this->social->existsAddressBook($stoppedAtBook, $userId)) {
$stoppedAtBook = null;
}
- if ($this->social->existsContact($stoppedAtContact, $stoppedAtBook, $userId) == false) {
+ if (!$this->social->existsContact($stoppedAtContact, $stoppedAtBook, $userId)) {
$stoppedAtContact = null;
}
- // TODO: can we check the userId still exists?
$this->jobList->add(self::class, [
'userId' => $userId,
diff --git a/lib/Cron/SocialUpdateRegistration.php b/lib/Cron/SocialUpdateRegistration.php
index ddb2e4b7..da8f24c0 100644
--- a/lib/Cron/SocialUpdateRegistration.php
+++ b/lib/Cron/SocialUpdateRegistration.php
@@ -94,7 +94,7 @@ class SocialUpdateRegistration extends TimedJob {
// check that user opted-in:
$bgSyncEnabledByUser = $this->config->getUserValue($user->getUID(), $this->appName, 'enableSocialSync', 'no');
- if ($bgSyncEnabledByUser === 'yes') {
+ if ($bgSyncEnabledByUser === 'yes' && $user->isEnabled()) {
$this->jobList->add(SocialUpdate::class, [
'userId' => $user->getUID(),
'offsetBook' => null,