diff options
author | Thomas Citharel <tcit@tcit.fr> | 2022-06-14 11:46:13 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2022-06-14 11:46:13 +0200 |
commit | f79c8f14c2ca94bb2c742117e2d048734a89a268 (patch) | |
tree | 9192febbd7bc30e4f0d0c78a97dea023384f0001 /lib | |
parent | 9c746480546fb42123d3337d809600bcaf3a9430 (diff) |
Avoid running social update background job on deleted/disabled users
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Cron/SocialUpdate.php | 17 | ||||
-rw-r--r-- | lib/Cron/SocialUpdateRegistration.php | 2 |
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, |