Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-10-02 12:47:00 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-01-31 18:43:51 +0300
commitc287787f8df599b567f399f6022ffc88db3a0582 (patch)
tree6d1863eff65f5c43db73c1e36df6938c505ef58e /lib/BackgroundJob
parent31f89d71f860c8c2f75234537a8d64f38da696ab (diff)
Add a cache for IMAP message in the database
Co-authored-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/BackgroundJob')
-rw-r--r--lib/BackgroundJob/SyncJob.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/BackgroundJob/SyncJob.php b/lib/BackgroundJob/SyncJob.php
new file mode 100644
index 000000000..6dfab3d2e
--- /dev/null
+++ b/lib/BackgroundJob/SyncJob.php
@@ -0,0 +1,78 @@
+<?php declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Mail\BackgroundJob;
+
+use OCA\Mail\Service\AccountService;
+use OCA\Mail\Service\SyncService;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\IJobList;
+use OCP\BackgroundJob\TimedJob;
+use OCP\ILogger;
+
+class SyncJob extends TimedJob {
+
+ /** @var AccountService */
+ private $accountService;
+ /** @var SyncService */
+ private $syncService;
+ /** @var ILogger */
+ private $logger;
+ /** @var IJobList */
+ private $jobList;
+
+ public function __construct(ITimeFactory $time,
+ AccountService $accountService,
+ SyncService $syncService,
+ ILogger $logger,
+ IJobList $jobList) {
+ parent::__construct($time);
+
+ $this->accountService = $accountService;
+ $this->syncService = $syncService;
+ $this->logger = $logger;
+
+ $this->setInterval(3600);
+ $this->jobList = $jobList;
+ }
+
+ protected function run($argument) {
+ $accountId = (int)$argument['accountId'];
+
+ try {
+ $account = $this->accountService->findById($accountId);
+ } catch (DoesNotExistException $e) {
+ $this->logger->debug('Could not find account <' . $accountId . '> removing from jobs');
+ $this->jobList->remove(self::class, $argument);
+ return;
+ }
+
+ try {
+ $this->syncService->syncAccount($account);
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ }
+ }
+
+}