diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-23 11:51:32 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-24 20:31:01 +0100 |
commit | 6f5316e443556ab8aca7a378d4d64fa9044fc80c (patch) | |
tree | 0c70e92811a926d6f44b63753587b9793abe20c9 /apps/dav/lib/Migration | |
parent | dd1ab21887fd75f7d43a4df929519449b07606cd (diff) | |
download | nextcloud-server-6f5316e443556ab8aca7a378d4d64fa9044fc80c.tar.gz nextcloud-server-6f5316e443556ab8aca7a378d4d64fa9044fc80c.zip |
Add DAV repair step to fix calendar data
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib/Migration')
-rw-r--r-- | apps/dav/lib/Migration/ValueFix.php | 71 | ||||
-rw-r--r-- | apps/dav/lib/Migration/ValueFixInsert.php | 63 |
2 files changed, 134 insertions, 0 deletions
diff --git a/apps/dav/lib/Migration/ValueFix.php b/apps/dav/lib/Migration/ValueFix.php new file mode 100644 index 00000000000..2ad043b409d --- /dev/null +++ b/apps/dav/lib/Migration/ValueFix.php @@ -0,0 +1,71 @@ +<?php +/** + * @copyright 2016, 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\DAV\Migration; + +use OC\BackgroundJob\QueuedJob; +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\ILogger; +use Sabre\VObject\InvalidDataException; + +class ValueFix extends QueuedJob { + + /** @var CalDavBackend */ + private $calDavBackend; + + /** @var ILogger */ + private $logger; + + public function __construct(CalDavBackend $calDavBackend, ILogger $logger) { + $this->calDavBackend = $calDavBackend; + $this->logger = $logger; + } + + public function run($argument) { + $user = $argument['user']; + + $pattern = '/;VALUE=:/'; + $principal = 'principals/users/' . $user; + $calendars = $this->calDavBackend->getCalendarsForUser($principal); + foreach ($calendars as $calendar) { + $objects = $this->calDavBackend->getCalendarObjects($calendar['id']); + foreach ($objects as $object) { + $calObject = $this->calDavBackend->getCalendarObject($calendar['id'], $object['uri']); + $data = preg_replace($pattern, ':', $calObject['calendardata']); + if ($data !== $calObject['calendardata']) { + try { + $this->calDavBackend->getDenormalizedData($data); + } catch (InvalidDataException $e) { + $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ + 'app'=> 'dav', + 'cal' => $calendar['id'], + 'uri' => $object['uri'], + ]); + continue; + } + $this->calDavBackend->updateCalendarObject($calendar['id'], $object['uri'], $data); + } + } + } + } + +} diff --git a/apps/dav/lib/Migration/ValueFixInsert.php b/apps/dav/lib/Migration/ValueFixInsert.php new file mode 100644 index 00000000000..25917691b20 --- /dev/null +++ b/apps/dav/lib/Migration/ValueFixInsert.php @@ -0,0 +1,63 @@ +<?php +/** + * @copyright 2016, 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\DAV\Migration; + +use OCP\BackgroundJob\IJobList; +use OCP\IConfig; +use OCP\IUser; +use OCP\IUserManager; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class ValueFixInsert implements IRepairStep { + + /** @var IUserManager */ + private $userManager; + + /** @var IJobList */ + private $jobList; + + /** @var IConfig */ + private $config; + + public function __construct(IUserManager $userManager, + IJobList $jobList, + IConfig $config) { + $this->userManager = $userManager; + $this->jobList = $jobList; + $this->config = $config; + } + + public function getName() { + return 'Insert ValueFix background job for each user'; + } + + public function run(IOutput $output) { + if ($this->config->getAppValue('dav', self::class . '_ran', 'false') !== 'true') { + $this->userManager->callForSeenUsers(function (IUser $user) { + $this->jobList->add(ValueFix::class, ['user' => $user->getUID()]); + }); + $this->config->setAppValue('dav', self::class . '_ran', 'true'); + } + } +} |