diff options
author | call-me-matt <nextcloud@matthiasheinisch.de> | 2020-03-30 23:32:37 +0200 |
---|---|---|
committer | call-me-matt <nextcloud@matthiasheinisch.de> | 2020-08-05 00:23:06 +0200 |
commit | 973c28825b42c10a153785982c782368b9b79702 (patch) | |
tree | 63981d8805d2212b219d25d97761e25d27909206 /lib/Cron | |
parent | b78f4d65cc1438477e6c307f9d5d732e84833a98 (diff) |
allowing for background updates of social avatars
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
Diffstat (limited to 'lib/Cron')
-rw-r--r-- | lib/Cron/SocialUpdate.php | 42 | ||||
-rw-r--r-- | lib/Cron/SocialUpdateRegistration.php | 93 |
2 files changed, 135 insertions, 0 deletions
diff --git a/lib/Cron/SocialUpdate.php b/lib/Cron/SocialUpdate.php new file mode 100644 index 00000000..fe245cdc --- /dev/null +++ b/lib/Cron/SocialUpdate.php @@ -0,0 +1,42 @@ +<?php +/** + * @copyright 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de> + * + * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Contacts\Cron; + +use OCA\Contacts\Service\SocialApiService; + +class SocialUpdate extends \OC\BackgroundJob\QueuedJob { + /** @var SocialUpdateService */ + private $social; + + public function __construct(SocialApiService $social) { + $this->social = $social; + } + + protected function run($arguments) { + $userId = $arguments['userId']; + + // update contacts with first available social media profile + $this->social->updateAddressbooks('any', $userId); + } +} diff --git a/lib/Cron/SocialUpdateRegistration.php b/lib/Cron/SocialUpdateRegistration.php new file mode 100644 index 00000000..58c7a51a --- /dev/null +++ b/lib/Cron/SocialUpdateRegistration.php @@ -0,0 +1,93 @@ +<?php +/** + * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Contacts\Cron; + +use OCA\Contacts\AppInfo\Application; + +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\IJobList; +use OCP\IUser; +use OCP\IConfig; +use OCP\IUserManager; + +class SocialUpdateRegistration extends \OC\BackgroundJob\TimedJob { + private $appName; + + /** @var IUserManager */ + private $userManager; + + /** @var IJobList */ + private $jobList; + + /** @var IConfig */ + private $config; + + /** + * RegisterSocialUpdate constructor. + * + * @param ITimeFactory $time + * @param IUserManager $userManager + * @param IJobList $jobList + */ + public function __construct( + // ITimeFactory $time, + IUserManager $userManager, + IConfig $config, + IJobList $jobList) { + //parent::__construct($time); + + $this->appName = Application::APP_ID; + $this->userManager = $userManager; + $this->config = $config; + $this->jobList = $jobList; + + // Run once a week + parent::setInterval(7 * 24 * 60 * 60); + } + + /** + * @inheritDoc + */ + protected function run($arguments) { + + // check if admin allows for social updates: + $syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); + if (!($syncAllowedByAdmin === 'yes')) { + return; + } + + $this->userManager->callForSeenUsers(function (IUser $user) { + + // check that user opted-in: + $bgSyncEnabledByUser = $this->config->getUserValue($user->getUID(), $this->appName, 'enableSocialSync', 'no'); + if ($bgSyncEnabledByUser === 'yes') { + $this->jobList->add(SocialUpdate::class, [ + 'userId' => $user->getUID() + ]); + } + }); + } +} |