summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/migration
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/migration')
-rw-r--r--apps/dav/lib/migration/addressbookadapter.php106
-rw-r--r--apps/dav/lib/migration/calendaradapter.php102
-rw-r--r--apps/dav/lib/migration/migrateaddressbooks.php131
-rw-r--r--apps/dav/lib/migration/migratecalendars.php132
4 files changed, 0 insertions, 471 deletions
diff --git a/apps/dav/lib/migration/addressbookadapter.php b/apps/dav/lib/migration/addressbookadapter.php
deleted file mode 100644
index 5264747a004..00000000000
--- a/apps/dav/lib/migration/addressbookadapter.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OCA\Dav\Migration;
-
-use OCP\IDBConnection;
-use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-
-class AddressBookAdapter {
-
- /** @var \OCP\IDBConnection */
- protected $dbConnection;
-
- /** @var string */
- private $sourceBookTable;
-
- /** @var string */
- private $sourceCardsTable;
-
- /**
- * @param IDBConnection $dbConnection
- * @param string $sourceBookTable
- * @param string $sourceCardsTable
- */
- function __construct(IDBConnection $dbConnection,
- $sourceBookTable = 'contacts_addressbooks',
- $sourceCardsTable = 'contacts_cards') {
- $this->dbConnection = $dbConnection;
- $this->sourceBookTable = $sourceBookTable;
- $this->sourceCardsTable = $sourceCardsTable;
- }
-
- /**
- * @param string $user
- * @param \Closure $callBack
- */
- public function foreachBook($user, \Closure $callBack) {
- // get all addressbooks of that user
- $query = $this->dbConnection->getQueryBuilder();
- $stmt = $query->select('*')->from($this->sourceBookTable)
- ->where($query->expr()->eq('userid', $query->createNamedParameter($user)))
- ->execute();
-
- while($row = $stmt->fetch()) {
- $callBack($row);
- }
- }
-
- public function setup() {
- if (!$this->dbConnection->tableExists($this->sourceBookTable)) {
- throw new \DomainException('Contacts tables are missing. Nothing to do.');
- }
- }
-
- /**
- * @param int $addressBookId
- * @param \Closure $callBack
- */
- public function foreachCard($addressBookId, \Closure $callBack) {
- $query = $this->dbConnection->getQueryBuilder();
- $stmt = $query->select('*')->from($this->sourceCardsTable)
- ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
- ->execute();
-
- while($row = $stmt->fetch()) {
- $callBack($row);
- }
- }
-
- /**
- * @param int $addressBookId
- * @return array
- */
- public function getShares($addressBookId) {
- $query = $this->dbConnection->getQueryBuilder();
- $shares = $query->select('*')->from('share')
- ->where($query->expr()->eq('item_source', $query->createNamedParameter($addressBookId)))
- ->andWhere($query->expr()->eq('item_type', $query->expr()->literal('addressbook')))
- ->andWhere($query->expr()->in('share_type', [ $query->expr()->literal(0), $query->expr()->literal(1)]))
- ->execute()
- ->fetchAll();
-
- return $shares;
- }
-}
diff --git a/apps/dav/lib/migration/calendaradapter.php b/apps/dav/lib/migration/calendaradapter.php
deleted file mode 100644
index d02f2256c34..00000000000
--- a/apps/dav/lib/migration/calendaradapter.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OCA\Dav\Migration;
-
-use OCP\IDBConnection;
-
-class CalendarAdapter {
-
- /** @var \OCP\IDBConnection */
- protected $dbConnection;
-
- /** @var string */
- private $sourceCalendarTable;
-
- /** @var string */
- private $sourceCalObjTable;
-
- /**
- * @param IDBConnection $dbConnection
- * @param string $sourceCalendarTable
- * @param string $sourceCalObjTable
- */
- function __construct(IDBConnection $dbConnection,
- $sourceCalendarTable = 'clndr_calendars',
- $sourceCalObjTable = 'clndr_objects') {
- $this->dbConnection = $dbConnection;
- $this->sourceCalendarTable = $sourceCalendarTable;
- $this->sourceCalObjTable = $sourceCalObjTable;
- }
-
- /**
- * @param string $user
- * @param \Closure $callBack
- */
- public function foreachCalendar($user, \Closure $callBack) {
- // get all calendars of that user
- $query = $this->dbConnection->getQueryBuilder();
- $stmt = $query->select('*')->from($this->sourceCalendarTable)
- ->where($query->expr()->eq('userid', $query->createNamedParameter($user)))
- ->execute();
-
- while($row = $stmt->fetch()) {
- $callBack($row);
- }
- }
-
- public function setup() {
- if (!$this->dbConnection->tableExists($this->sourceCalendarTable)) {
- throw new \DomainException('Calendar tables are missing. Nothing to do.');
- }
- }
-
- /**
- * @param int $calendarId
- * @param \Closure $callBack
- */
- public function foreachCalendarObject($calendarId, \Closure $callBack) {
- $query = $this->dbConnection->getQueryBuilder();
- $stmt = $query->select('*')->from($this->sourceCalObjTable)
- ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
- ->execute();
-
- while($row = $stmt->fetch()) {
- $callBack($row);
- }
- }
-
- /**
- * @param int $addressBookId
- * @return array
- */
- public function getShares($addressBookId) {
- $query = $this->dbConnection->getQueryBuilder();
- $shares = $query->select('*')->from('share')
- ->where($query->expr()->eq('item_source', $query->createNamedParameter($addressBookId)))
- ->andWhere($query->expr()->eq('item_type', $query->expr()->literal('calendar')))
- ->andWhere($query->expr()->in('share_type', [ $query->expr()->literal(0), $query->expr()->literal(1)]))
- ->execute()
- ->fetchAll();
-
- return $shares;
- }
-}
diff --git a/apps/dav/lib/migration/migrateaddressbooks.php b/apps/dav/lib/migration/migrateaddressbooks.php
deleted file mode 100644
index 7e1f47ea75e..00000000000
--- a/apps/dav/lib/migration/migrateaddressbooks.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OCA\Dav\Migration;
-
-use OCA\DAV\CardDAV\AddressBook;
-use OCA\DAV\CardDAV\CardDavBackend;
-use OCP\ILogger;
-use Sabre\CardDAV\Plugin;
-use Symfony\Component\Console\Output\OutputInterface;
-
-class MigrateAddressbooks {
-
- /** @var AddressBookAdapter */
- protected $adapter;
-
- /** @var CardDavBackend */
- private $backend;
-
- /** @var ILogger */
- private $logger;
-
- /** @var OutputInterface */
- private $consoleOutput;
-
-
- /**
- * @param AddressBookAdapter $adapter
- * @param CardDavBackend $backend
- */
- function __construct(AddressBookAdapter $adapter,
- CardDavBackend $backend,
- ILogger $logger,
- OutputInterface $consoleOutput = null
- ) {
- $this->adapter = $adapter;
- $this->backend = $backend;
- $this->logger = $logger;
- $this->consoleOutput = $consoleOutput;
- }
-
- /**
- * @param string $user
- */
- public function migrateForUser($user) {
-
- $this->adapter->foreachBook($user, function($book) use ($user) {
- $principal = "principals/users/$user";
- $knownBooks = $this->backend->getAddressBooksByUri($principal, $book['uri']);
- if (!is_null($knownBooks)) {
- return;
- }
-
- $newId = $this->backend->createAddressBook($principal, $book['uri'], [
- '{DAV:}displayname' => $book['displayname'],
- '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $book['description']
- ]);
-
- $this->migrateBook($book['id'], $newId);
- $this->migrateShares($book['id'], $newId);
- });
- }
-
- public function setup() {
- $this->adapter->setup();
- }
-
- /**
- * @param int $addressBookId
- * @param int $newAddressBookId
- */
- private function migrateBook($addressBookId, $newAddressBookId) {
- $this->adapter->foreachCard($addressBookId, function($card) use ($newAddressBookId) {
- try {
- $this->backend->createCard($newAddressBookId, $card['uri'], $card['carddata']);
- } catch (\Exception $ex) {
- $eventId = $card['id'];
- $addressBookId = $card['addressbookid'];
- $msg = "One event could not be migrated. (id: $eventId, addressbookid: $addressBookId)";
- $this->logger->logException($ex, ['app' => 'dav', 'message' => $msg]);
- if (!is_null($this->consoleOutput)) {
- $this->consoleOutput->writeln($msg);
- }
- }
- });
- }
-
- /**
- * @param int $addressBookId
- * @param int $newAddressBookId
- */
- private function migrateShares($addressBookId, $newAddressBookId) {
- $shares =$this->adapter->getShares($addressBookId);
- if (empty($shares)) {
- return;
- }
-
- $add = array_map(function($s) {
- $prefix = 'principal:principals/users/';
- if ((int)$s['share_type'] === 1) {
- $prefix = 'principal:principals/groups/';
- }
- return [
- 'href' => $prefix . $s['share_with'],
- 'readOnly' => !((int)$s['permissions'] === 31)
- ];
- }, $shares);
-
- $newAddressBook = $this->backend->getAddressBookById($newAddressBookId);
- $book = new AddressBook($this->backend, $newAddressBook);
- $this->backend->updateShares($book, $add, []);
- }
-}
diff --git a/apps/dav/lib/migration/migratecalendars.php b/apps/dav/lib/migration/migratecalendars.php
deleted file mode 100644
index 3c1487761c2..00000000000
--- a/apps/dav/lib/migration/migratecalendars.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OCA\Dav\Migration;
-
-use OCA\DAV\CalDAV\CalDavBackend;
-use OCA\DAV\CalDAV\Calendar;
-use OCP\ILogger;
-use Symfony\Component\Console\Output\OutputInterface;
-
-class MigrateCalendars {
-
- /** @var CalendarAdapter */
- protected $adapter;
-
- /** @var CalDavBackend */
- private $backend;
-
- /** @var ILogger */
- private $logger;
-
- /** @var OutputInterface */
- private $consoleOutput;
-
- /**
- * @param CalendarAdapter $adapter
- * @param CalDavBackend $backend
- */
- function __construct(CalendarAdapter $adapter,
- CalDavBackend $backend,
- ILogger $logger,
- OutputInterface $consoleOutput = null
- ) {
- $this->adapter = $adapter;
- $this->backend = $backend;
- $this->logger = $logger;
- $this->consoleOutput = $consoleOutput;
- }
-
- /**
- * @param string $user
- */
- public function migrateForUser($user) {
-
- $this->adapter->foreachCalendar($user, function($calendar) use ($user) {
- $principal = "principals/users/$user";
- $calendarByUri = $this->backend->getCalendarByUri($principal, $calendar['uri']);
- if (!is_null($calendarByUri)) {
- return;
- }
-
- $newId = $this->backend->createCalendar($principal, $calendar['uri'], [
- '{DAV:}displayname' => $calendar['displayname'],
- '{urn:ietf:params:xml:ns:caldav}calendar-description' => $calendar['displayname'],
- '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $calendar['timezone'],
- '{http://apple.com/ns/ical/}calendar-order' => $calendar['calendarorder'],
- '{http://apple.com/ns/ical/}calendar-color' => $calendar['calendarcolor'],
- ]);
-
- $this->migrateCalendar($calendar['id'], $newId);
- $this->migrateShares($calendar['id'], $newId);
- });
- }
-
- public function setup() {
- $this->adapter->setup();
- }
-
- /**
- * @param int $calendarId
- * @param int $newCalendarId
- */
- private function migrateCalendar($calendarId, $newCalendarId) {
- $this->adapter->foreachCalendarObject($calendarId, function($calObject) use ($newCalendarId) {
- try {
- $this->backend->createCalendarObject($newCalendarId, $calObject['uri'], $calObject['calendardata']);
- } catch (\Exception $ex) {
- $eventId = $calObject['id'];
- $calendarId = $calObject['calendarId'];
- $msg = "One event could not be migrated. (id: $eventId, calendarid: $calendarId)";
- $this->logger->logException($ex, ['app' => 'dav', 'message' => $msg]);
- if (!is_null($this->consoleOutput)) {
- $this->consoleOutput->writeln($msg);
- }
- }
- });
- }
-
- /**
- * @param int $calendarId
- * @param int $newCalendarId
- */
- private function migrateShares($calendarId, $newCalendarId) {
- $shares =$this->adapter->getShares($calendarId);
- if (empty($shares)) {
- return;
- }
-
- $add = array_map(function($s) {
- $prefix = 'principal:principals/users/';
- if ((int)$s['share_type'] === 1) {
- $prefix = 'principal:principals/groups/';
- }
- return [
- 'href' => $prefix . $s['share_with'],
- 'readOnly' => !((int)$s['permissions'] === 31)
- ];
- }, $shares);
-
- $newCalendar = $this->backend->getCalendarById($newCalendarId);
- $calendar = new Calendar($this->backend, $newCalendar);
- $this->backend->updateShares($calendar, $add, []);
- }
-}