summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-26 13:05:11 +0200
committerJoas Schilling <coding@schilljs.com>2017-03-26 13:09:53 +0200
commit3bd501aad2451d360da8359d6bbb73efe2eab2ad (patch)
tree129ecb04ffa1cea2e761f14b2a59076f2a74c4da /apps/dav/lib
parentf3917cfea148d09832a727953c74ece952a47f84 (diff)
downloadnextcloud-server-3bd501aad2451d360da8359d6bbb73efe2eab2ad.tar.gz
nextcloud-server-3bd501aad2451d360da8359d6bbb73efe2eab2ad.zip
Directly fix the values
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php119
-rw-r--r--apps/dav/lib/Migration/ValueFix.php71
-rw-r--r--apps/dav/lib/Migration/ValueFixInsert.php63
3 files changed, 119 insertions, 134 deletions
diff --git a/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php b/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php
new file mode 100644
index 00000000000..ae921ce4743
--- /dev/null
+++ b/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * @copyright 2017 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @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 OCA\DAV\CalDAV\CalDavBackend;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\ILogger;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+use Sabre\VObject\InvalidDataException;
+
+class CalDAVRemoveEmptyValue implements IRepairStep {
+
+ /** @var IDBConnection */
+ private $db;
+
+ /** @var CalDavBackend */
+ private $calDavBackend;
+
+ /** @var ILogger */
+ private $logger;
+
+ /**
+ * @param IDBConnection $db
+ * @param CalDavBackend $calDavBackend
+ * @param ILogger $logger
+ */
+ public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) {
+ $this->db = $db;
+ $this->calDavBackend = $calDavBackend;
+ $this->logger = $logger;
+ }
+
+ public function getName() {
+ return 'Fix broken values of calendar objects';
+ }
+
+ public function run(IOutput $output) {
+ $pattern = ';VALUE=:';
+ $count = $warnings = 0;
+
+ $objects = $this->getInvalidObjects($pattern);
+
+ $output->startProgress(count($objects));
+ foreach ($objects as $row) {
+ $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']);
+ $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']);
+
+ if ($data !== $calObject['calendardata']) {
+ $output->advance();
+
+ try {
+ $this->calDavBackend->getDenormalizedData($data);
+ } catch (InvalidDataException $e) {
+ $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [
+ 'app' => 'dav',
+ 'cal' => (int)$row['calendarid'],
+ 'uri' => $row['uri'],
+ ]);
+ $warnings++;
+ continue;
+ }
+
+ $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data);
+ $count++;
+ }
+ }
+ $output->finishProgress();
+
+ if ($warnings > 0) {
+ $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings));
+ }
+ if ($count > 0) {
+ $output->info(sprintf('Updated %d events', $count));
+ }
+ }
+
+ protected function getInvalidObjects($pattern) {
+ $query = $this->db->getQueryBuilder();
+ $query->select(['calendarid', 'uri'])
+ ->from('calendarobjects')
+ ->where($query->expr()->like(
+ 'calendardata',
+ $query->createNamedParameter(
+ '%' . $this->db->escapeLikeParameter($pattern) . '%',
+ IQueryBuilder::PARAM_STR
+ ),
+ IQueryBuilder::PARAM_STR
+ ));
+
+ $result = $query->execute();
+ $rows = $result->fetchAll();
+ $result->closeCursor();
+
+ return $rows;
+ }
+}
diff --git a/apps/dav/lib/Migration/ValueFix.php b/apps/dav/lib/Migration/ValueFix.php
deleted file mode 100644
index 2ad043b409d..00000000000
--- a/apps/dav/lib/Migration/ValueFix.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?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
deleted file mode 100644
index 25917691b20..00000000000
--- a/apps/dav/lib/Migration/ValueFixInsert.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?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');
- }
- }
-}