You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SyncJob.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Federation;
  27. use OC\BackgroundJob\TimedJob;
  28. use OCP\ILogger;
  29. class SyncJob extends TimedJob {
  30. /** @var SyncFederationAddressBooks */
  31. protected $syncService;
  32. /** @var ILogger */
  33. protected $logger;
  34. /**
  35. * @param SyncFederationAddressBooks $syncService
  36. * @param ILogger $logger
  37. */
  38. public function __construct(SyncFederationAddressBooks $syncService, ILogger $logger) {
  39. // Run once a day
  40. $this->setInterval(24 * 60 * 60);
  41. $this->syncService = $syncService;
  42. $this->logger = $logger;
  43. }
  44. protected function run($argument) {
  45. $this->syncService->syncThemAll(function ($url, $ex) {
  46. if ($ex instanceof \Exception) {
  47. $this->logger->logException($ex, [
  48. 'message' => "Error while syncing $url.",
  49. 'level' => ILogger::INFO,
  50. 'app' => 'fed-sync',
  51. ]);
  52. }
  53. });
  54. }
  55. }