diff options
author | matt <34400929+call-me-matt@users.noreply.github.com> | 2020-08-11 18:24:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-11 18:24:56 +0200 |
commit | 752bb14cd88acb200582724aa430887a76b5b864 (patch) | |
tree | a6a0ca28b6107e4f1b583f118e15cf1c5963e018 /lib/Cron | |
parent | 16c07999bbc389d970b1667df3ca5853c1311832 (diff) | |
parent | 973c28825b42c10a153785982c782368b9b79702 (diff) |
Merge pull request #1722 from call-me-matt/enh/social-updater
allow for regular background updates of avatars from social networks
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() + ]); + } + }); + } +} |