diff options
28 files changed, 110 insertions, 1499 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php index 593cd770be5..c3811a40845 100644 --- a/apps/dav/appinfo/application.php +++ b/apps/dav/appinfo/application.php @@ -30,10 +30,6 @@ use OCA\DAV\CardDAV\SyncService; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\GroupPrincipalBackend; use OCA\DAV\HookManager; -use OCA\Dav\Migration\AddressBookAdapter; -use OCA\Dav\Migration\CalendarAdapter; -use OCA\Dav\Migration\MigrateAddressbooks; -use OCA\Dav\Migration\MigrateCalendars; use \OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\Contacts\IManager; @@ -98,30 +94,6 @@ class Application extends App { return new CalDavBackend($db, $principal); }); - $container->registerService('MigrateAddressbooks', function($c) { - /** @var IAppContainer $c */ - $db = $c->getServer()->getDatabaseConnection(); - $logger = $c->getServer()->getLogger(); - return new MigrateAddressbooks( - new AddressBookAdapter($db), - $c->query('CardDavBackend'), - $logger, - null - ); - }); - - $container->registerService('MigrateCalendars', function($c) { - /** @var IAppContainer $c */ - $db = $c->getServer()->getDatabaseConnection(); - $logger = $c->getServer()->getLogger(); - return new MigrateCalendars( - new CalendarAdapter($db), - $c->query('CalDavBackend'), - $logger, - null - ); - }); - $container->registerService('BirthdayService', function($c) { /** @var IAppContainer $c */ $g = new GroupPrincipalBackend( @@ -186,38 +158,6 @@ class Application extends App { $jl->add(new SyncJob()); } - public function migrateAddressbooks() { - try { - /** @var MigrateAddressbooks $migration */ - $migration = $this->getContainer()->query('MigrateAddressbooks'); - $migration->setup(); - $userManager = $this->getContainer()->getServer()->getUserManager(); - - $userManager->callForAllUsers(function($user) use($migration) { - /** @var IUser $user */ - $migration->migrateForUser($user->getUID()); - }); - } catch (\Exception $ex) { - $this->getContainer()->getServer()->getLogger()->logException($ex); - } - } - - public function migrateCalendars() { - try { - /** @var MigrateCalendars $migration */ - $migration = $this->getContainer()->query('MigrateCalendars'); - $migration->setup(); - $userManager = $this->getContainer()->getServer()->getUserManager(); - - $userManager->callForAllUsers(function($user) use($migration) { - /** @var IUser $user */ - $migration->migrateForUser($user->getUID()); - }); - } catch (\Exception $ex) { - $this->getContainer()->getServer()->getLogger()->logException($ex); - } - } - public function generateBirthdays() { try { /** @var BirthdayService $migration */ diff --git a/apps/dav/appinfo/install.php b/apps/dav/appinfo/install.php index dc5ae39226e..fbd41d25f49 100644 --- a/apps/dav/appinfo/install.php +++ b/apps/dav/appinfo/install.php @@ -23,6 +23,4 @@ use OCA\Dav\AppInfo\Application; $app = new Application(); $app->setupCron(); -$app->migrateAddressbooks(); -$app->migrateCalendars(); $app->generateBirthdays(); diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php index 570848f0b23..b3ab25a99e3 100644 --- a/apps/dav/appinfo/register_command.php +++ b/apps/dav/appinfo/register_command.php @@ -21,8 +21,6 @@ use OCA\Dav\AppInfo\Application; use OCA\DAV\Command\CreateAddressBook; use OCA\DAV\Command\CreateCalendar; -use OCA\Dav\Command\MigrateAddressbooks; -use OCA\Dav\Command\MigrateCalendars; use OCA\DAV\Command\SyncBirthdayCalendar; use OCA\DAV\Command\SyncSystemAddressBook; @@ -37,5 +35,3 @@ $application->add(new CreateCalendar($userManager, $groupManager, $dbConnection) $application->add(new CreateAddressBook($userManager, $app->getContainer()->query('CardDavBackend'))); $application->add(new SyncSystemAddressBook($app->getSyncService())); $application->add(new SyncBirthdayCalendar($userManager, $app->getContainer()->query('BirthdayService'))); -$application->add(new MigrateAddressbooks($userManager, $app->getContainer()->query('MigrateAddressbooks'))); -$application->add(new MigrateCalendars($userManager, $app->getContainer()->query('MigrateCalendars'))); diff --git a/apps/dav/command/migrateaddressbooks.php b/apps/dav/command/migrateaddressbooks.php deleted file mode 100644 index 562f19a2300..00000000000 --- a/apps/dav/command/migrateaddressbooks.php +++ /dev/null @@ -1,86 +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\Command; - -use OCP\IUser; -use OCP\IUserManager; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -class MigrateAddressbooks extends Command { - - /** @var IUserManager */ - protected $userManager; - - /** @var \OCA\Dav\Migration\MigrateAddressbooks */ - private $service; - - /** - * @param IUserManager $userManager - * @param \OCA\Dav\Migration\MigrateAddressbooks $service - */ - function __construct(IUserManager $userManager, - \OCA\Dav\Migration\MigrateAddressbooks $service - ) { - parent::__construct(); - $this->userManager = $userManager; - $this->service = $service; - } - - protected function configure() { - $this - ->setName('dav:migrate-addressbooks') - ->setDescription('Migrate addressbooks from the contacts app to core') - ->addArgument('user', - InputArgument::OPTIONAL, - 'User for whom all addressbooks will be migrated'); - } - - protected function execute(InputInterface $input, OutputInterface $output) { - $this->service->setup(); - - $user = $input->getArgument('user'); - if (!is_null($user)) { - if (!$this->userManager->userExists($user)) { - throw new \InvalidArgumentException("User <$user> in unknown."); - } - $output->writeln("Start migration for $user"); - $this->service->migrateForUser($user); - return; - } - $output->writeln("Start migration of all known users ..."); - $p = new ProgressBar($output); - $p->start(); - $this->userManager->callForAllUsers(function($user) use ($p) { - $p->advance(); - /** @var IUser $user */ - $this->service->migrateForUser($user->getUID()); - }); - - $p->finish(); - $output->writeln(''); - } -} diff --git a/apps/dav/command/migratecalendars.php b/apps/dav/command/migratecalendars.php deleted file mode 100644 index d887309ac3e..00000000000 --- a/apps/dav/command/migratecalendars.php +++ /dev/null @@ -1,85 +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\Command; - -use OCP\IUser; -use OCP\IUserManager; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -class MigrateCalendars extends Command { - - /** @var IUserManager */ - protected $userManager; - - /** @var \OCA\Dav\Migration\MigrateCalendars */ - private $service; - - /** - * @param IUserManager $userManager - * @param \OCA\Dav\Migration\MigrateCalendars $service - */ - function __construct(IUserManager $userManager, - \OCA\Dav\Migration\MigrateCalendars $service - ) { - parent::__construct(); - $this->userManager = $userManager; - $this->service = $service; - } - - protected function configure() { - $this - ->setName('dav:migrate-calendars') - ->setDescription('Migrate calendars from the calendar app to core') - ->addArgument('user', - InputArgument::OPTIONAL, - 'User for whom all calendars will be migrated'); - } - - protected function execute(InputInterface $input, OutputInterface $output) { - $this->service->setup(); - - $user = $input->getArgument('user'); - if (!is_null($user)) { - if (!$this->userManager->userExists($user)) { - throw new \InvalidArgumentException("User <$user> in unknown."); - } - $output->writeln("Start migration for $user"); - $this->service->migrateForUser($user); - return; - } - $output->writeln("Start migration of all known users ..."); - $p = new ProgressBar($output); - $p->start(); - $this->userManager->callForAllUsers(function($user) use ($p) { - $p->advance(); - /** @var IUser $user */ - $this->service->migrateForUser($user->getUID()); - }); - - $p->finish(); - $output->writeln(''); - } -} diff --git a/apps/dav/lib/hookmanager.php b/apps/dav/lib/hookmanager.php index c3d68a3ee2a..4a4704ff2a2 100644 --- a/apps/dav/lib/hookmanager.php +++ b/apps/dav/lib/hookmanager.php @@ -105,7 +105,8 @@ class HookManager { $calendars = $this->calDav->getCalendarsForUser($principal); if (empty($calendars)) { try { - $this->calDav->createCalendar($principal, 'default', []); + $this->calDav->createCalendar($principal, 'personal', [ + 'displayname' => 'Personal']); } catch (\Exception $ex) { \OC::$server->getLogger()->logException($ex); } @@ -113,7 +114,8 @@ class HookManager { $books = $this->cardDav->getAddressBooksForUser($principal); if (empty($books)) { try { - $this->cardDav->createAddressBook($principal, 'default', []); + $this->cardDav->createAddressBook($principal, 'contacts', [ + 'displayname' => 'Contacts']); } catch (\Exception $ex) { \OC::$server->getLogger()->logException($ex); } 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, []); - } -} diff --git a/apps/dav/tests/unit/migration/addressbookadaptertest.php b/apps/dav/tests/unit/migration/addressbookadaptertest.php deleted file mode 100644 index e6e57049a93..00000000000 --- a/apps/dav/tests/unit/migration/addressbookadaptertest.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php -/** - * @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\Tests\Unit\Migration; - -use DomainException; -use OCA\Dav\Migration\AddressBookAdapter; -use OCP\IDBConnection; -use Test\TestCase; - -/** - * Class AddressbookAdapterTest - * - * @group DB - * - * @package OCA\DAV\Tests\Unit\Migration - */ -class AddressbookAdapterTest extends TestCase { - - /** @var IDBConnection */ - private $db; - /** @var AddressBookAdapter */ - private $adapter; - /** @var array */ - private $books = []; - /** @var array */ - private $cards = []; - - public function setUp() { - parent::setUp(); - $this->db = \OC::$server->getDatabaseConnection(); - - $manager = new \OC\DB\MDB2SchemaManager($this->db); - $manager->createDbFromStructure(__DIR__ . '/contacts_schema.xml'); - - $this->adapter = new AddressBookAdapter($this->db); - } - - public function tearDown() { - $this->db->dropTable('contacts_addressbooks'); - $this->db->dropTable('contacts_cards'); - parent::tearDown(); - } - - /** - * @expectedException DomainException - */ - public function testOldTablesDoNotExist() { - $adapter = new AddressBookAdapter(\OC::$server->getDatabaseConnection(), 'crazy_table_that_does_no_exist'); - $adapter->setup(); - } - - public function test() { - - // insert test data - $builder = $this->db->getQueryBuilder(); - $builder->insert('contacts_addressbooks') - ->values([ - 'userid' => $builder->createNamedParameter('test-user-666'), - 'displayname' => $builder->createNamedParameter('Display Name'), - 'uri' => $builder->createNamedParameter('contacts'), - 'description' => $builder->createNamedParameter('An address book for testing'), - 'ctag' => $builder->createNamedParameter('112233'), - 'active' => $builder->createNamedParameter('1') - ]) - ->execute(); - $builder = $this->db->getQueryBuilder(); - $builder->insert('contacts_cards') - ->values([ - 'addressbookid' => $builder->createNamedParameter(6666), - 'fullname' => $builder->createNamedParameter('Full Name'), - 'carddata' => $builder->createNamedParameter('datadatadata'), - 'uri' => $builder->createNamedParameter('some-card.vcf'), - 'lastmodified' => $builder->createNamedParameter('112233'), - ]) - ->execute(); - $builder = $this->db->getQueryBuilder(); - $builder->insert('share') - ->values([ - 'share_type' => $builder->createNamedParameter(1), - 'share_with' => $builder->createNamedParameter('user01'), - 'uid_owner' => $builder->createNamedParameter('user02'), - 'item_type' => $builder->createNamedParameter('addressbook'), - 'item_source' => $builder->createNamedParameter(6666), - 'item_target' => $builder->createNamedParameter('Contacts (user02)'), - ]) - ->execute(); - - // test the adapter - $this->adapter->foreachBook('test-user-666', function($row) { - $this->books[] = $row; - }); - $this->assertArrayHasKey('id', $this->books[0]); - $this->assertEquals('test-user-666', $this->books[0]['userid']); - $this->assertEquals('Display Name', $this->books[0]['displayname']); - $this->assertEquals('contacts', $this->books[0]['uri']); - $this->assertEquals('An address book for testing', $this->books[0]['description']); - $this->assertEquals('112233', $this->books[0]['ctag']); - - $this->adapter->foreachCard(6666, function($row) { - $this->cards[]= $row; - }); - $this->assertArrayHasKey('id', $this->cards[0]); - $this->assertEquals(6666, $this->cards[0]['addressbookid']); - - // test getShares - $shares = $this->adapter->getShares(6666); - $this->assertEquals(1, count($shares)); - - } - -} diff --git a/apps/dav/tests/unit/migration/calendar_schema.xml b/apps/dav/tests/unit/migration/calendar_schema.xml deleted file mode 100644 index 6c88b596a3f..00000000000 --- a/apps/dav/tests/unit/migration/calendar_schema.xml +++ /dev/null @@ -1,191 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<database> - - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - - <charset>utf8</charset> - - <table> - - <name>*dbprefix*clndr_objects</name> - - <declaration> - - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>calendarid</name> - <type>integer</type> - <default></default> - <notnull>true</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>objecttype</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>40</length> - </field> - - <field> - <name>startdate</name> - <type>timestamp</type> - <default>1970-01-01 00:00:00</default> - <notnull>false</notnull> - </field> - - <field> - <name>enddate</name> - <type>timestamp</type> - <default>1970-01-01 00:00:00</default> - <notnull>false</notnull> - </field> - - <field> - <name>repeating</name> - <type>integer</type> - <default></default> - <notnull>false</notnull> - <length>4</length> - </field> - - <field> - <name>summary</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>calendardata</name> - <type>clob</type> - <notnull>false</notnull> - </field> - - <field> - <name>uri</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>lastmodified</name> - <type>integer</type> - <default></default> - <notnull>false</notnull> - <length>4</length> - </field> - - </declaration> - - </table> - - <table> - - <name>*dbprefix*clndr_calendars</name> - - <declaration> - - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>userid</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>displayname</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>100</length> - </field> - - <field> - <name>uri</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>active</name> - <type>integer</type> - <default>1</default> - <notnull>true</notnull> - <length>4</length> - </field> - - <field> - <name>ctag</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>calendarorder</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>calendarcolor</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>10</length> - </field> - - <field> - <name>timezone</name> - <type>clob</type> - <notnull>false</notnull> - </field> - - <field> - <name>components</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>100</length> - </field> - - </declaration> - - </table> - -</database> diff --git a/apps/dav/tests/unit/migration/calendaradaptertest.php b/apps/dav/tests/unit/migration/calendaradaptertest.php deleted file mode 100644 index f92774ef6ad..00000000000 --- a/apps/dav/tests/unit/migration/calendaradaptertest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php -/** - * @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\Tests\Unit\Migration; - -use DomainException; -use OCA\Dav\Migration\AddressBookAdapter; -use OCA\Dav\Migration\CalendarAdapter; -use OCP\IDBConnection; -use Test\TestCase; - -/** - * Class CalendarAdapterTest - * - * @group DB - * - * @package OCA\DAV\Tests\Unit\Migration - */ -class CalendarAdapterTest extends TestCase { - - /** @var IDBConnection */ - private $db; - /** @var CalendarAdapter */ - private $adapter; - /** @var array */ - private $cals = []; - /** @var array */ - private $calObjs = []; - - public function setUp() { - parent::setUp(); - $this->db = \OC::$server->getDatabaseConnection(); - - $manager = new \OC\DB\MDB2SchemaManager($this->db); - $manager->createDbFromStructure(__DIR__ . '/calendar_schema.xml'); - - $this->adapter = new CalendarAdapter($this->db); - } - - public function tearDown() { - $this->db->dropTable('clndr_calendars'); - $this->db->dropTable('clndr_objects'); - parent::tearDown(); - } - - /** - * @expectedException DomainException - */ - public function testOldTablesDoNotExist() { - $adapter = new AddressBookAdapter(\OC::$server->getDatabaseConnection(), 'crazy_table_that_does_no_exist'); - $adapter->setup(); - } - - public function test() { - - // insert test data - $builder = $this->db->getQueryBuilder(); - $builder->insert('clndr_calendars') - ->values([ - 'userid' => $builder->createNamedParameter('test-user-666'), - 'displayname' => $builder->createNamedParameter('Display Name'), - 'uri' => $builder->createNamedParameter('events'), - 'ctag' => $builder->createNamedParameter('112233'), - 'active' => $builder->createNamedParameter('1') - ]) - ->execute(); - $builder = $this->db->getQueryBuilder(); - $builder->insert('clndr_objects') - ->values([ - 'calendarid' => $builder->createNamedParameter(6666), - 'objecttype' => $builder->createNamedParameter('VEVENT'), - 'startdate' => $builder->createNamedParameter(new \DateTime(), 'datetime'), - 'enddate' => $builder->createNamedParameter(new \DateTime(), 'datetime'), - 'repeating' => $builder->createNamedParameter(0), - 'summary' => $builder->createNamedParameter('Something crazy will happen'), - 'uri' => $builder->createNamedParameter('event.ics'), - 'lastmodified' => $builder->createNamedParameter('112233'), - ]) - ->execute(); - $builder = $this->db->getQueryBuilder(); - $builder->insert('share') - ->values([ - 'share_type' => $builder->createNamedParameter(1), - 'share_with' => $builder->createNamedParameter('user01'), - 'uid_owner' => $builder->createNamedParameter('user02'), - 'item_type' => $builder->createNamedParameter('calendar'), - 'item_source' => $builder->createNamedParameter(6666), - 'item_target' => $builder->createNamedParameter('Contacts (user02)'), - ]) - ->execute(); - - // test the adapter - $this->adapter->foreachCalendar('test-user-666', function($row) { - $this->cals[] = $row; - }); - $this->assertArrayHasKey('id', $this->cals[0]); - $this->assertEquals('test-user-666', $this->cals[0]['userid']); - $this->assertEquals('Display Name', $this->cals[0]['displayname']); - $this->assertEquals('events', $this->cals[0]['uri']); - $this->assertEquals('112233', $this->cals[0]['ctag']); - - $this->adapter->foreachCalendarObject(6666, function($row) { - $this->calObjs[]= $row; - }); - $this->assertArrayHasKey('id', $this->calObjs[0]); - $this->assertEquals(6666, $this->calObjs[0]['calendarid']); - - // test getShares - $shares = $this->adapter->getShares(6666); - $this->assertEquals(1, count($shares)); - - } - -} diff --git a/apps/dav/tests/unit/migration/contacts_schema.xml b/apps/dav/tests/unit/migration/contacts_schema.xml deleted file mode 100644 index 51836a1e0c6..00000000000 --- a/apps/dav/tests/unit/migration/contacts_schema.xml +++ /dev/null @@ -1,151 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<database> - - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - <charset>utf8</charset> - <table> - - <name>*dbprefix*contacts_addressbooks</name> - - <declaration> - - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>userid</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>255</length> - </field> - - <field> - <name>displayname</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>uri</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>200</length> - </field> - - <field> - <name>description</name> - <type>text</type> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>ctag</name> - <type>integer</type> - <default>1</default> - <notnull>true</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>active</name> - <type>integer</type> - <default>1</default> - <notnull>true</notnull> - <length>4</length> - </field> - - <index> - <name>c_addressbook_userid_index</name> - <field> - <name>userid</name> - <sorting>ascending</sorting> - </field> - </index> - </declaration> - - </table> - - <table> - - <name>*dbprefix*contacts_cards</name> - - <declaration> - - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>addressbookid</name> - <type>integer</type> - <default></default> - <notnull>true</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - <field> - <name>fullname</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>255</length> - </field> - - <field> - <name>carddata</name> - <type>clob</type> - <notnull>false</notnull> - </field> - - <field> - <name>uri</name> - <type>text</type> - <default></default> - <notnull>false</notnull> - <length>200</length> - </field> - - <field> - <name>lastmodified</name> - <type>integer</type> - <default></default> - <notnull>false</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - - - <index> - <name>c_addressbookid_index</name> - <field> - <name>addressbookid</name> - <sorting>ascending</sorting> - </field> - </index> - </declaration> - - </table> - -</database> diff --git a/apps/dav/tests/unit/migration/migrateaddressbooktest.php b/apps/dav/tests/unit/migration/migrateaddressbooktest.php deleted file mode 100644 index 31cb16265c0..00000000000 --- a/apps/dav/tests/unit/migration/migrateaddressbooktest.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php -/** - * @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\Tests\Unit\Migration; - -use OCA\DAV\CardDAV\CardDavBackend; -use OCA\Dav\Migration\AddressBookAdapter; -use OCP\ILogger; -use Test\TestCase; - -class MigrateAddressbookTest extends TestCase { - - public function testMigration() { - /** @var AddressBookAdapter | \PHPUnit_Framework_MockObject_MockObject $adapter */ - $adapter = $this->mockAdapter([ - ['share_type' => '1', 'share_with' => 'users', 'permissions' => '31'], - ['share_type' => '2', 'share_with' => 'adam', 'permissions' => '1'], - ]); - - /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $cardDav */ - $cardDav = $this->getMockBuilder('\OCA\Dav\CardDAV\CardDAVBackend')->disableOriginalConstructor()->getMock(); - $cardDav->expects($this->any())->method('createAddressBook')->willReturn(666); - $cardDav->expects($this->any())->method('getAddressBookById')->willReturn([]); - $cardDav->expects($this->once())->method('createAddressBook')->with('principals/users/test01', 'test_contacts'); - $cardDav->expects($this->once())->method('createCard')->with(666, '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.vcf', 'BEGIN:VCARD'); - $cardDav->expects($this->once())->method('updateShares')->with($this->anything(), [ - ['href' => 'principal:principals/groups/users', 'readOnly' => false], - ['href' => 'principal:principals/users/adam', 'readOnly' => true] - ]); - /** @var ILogger $logger */ - $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock(); - - $m = new \OCA\Dav\Migration\MigrateAddressbooks($adapter, $cardDav, $logger, null); - $m->migrateForUser('test01'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function mockAdapter($shares = []) { - $adapter = $this->getMockBuilder('\OCA\Dav\Migration\AddressBookAdapter')->disableOriginalConstructor()->getMock(); - $adapter->expects($this->any())->method('foreachBook')->willReturnCallback(function ($user, \Closure $callBack) { - $callBack([ - 'id' => 0, - 'userid' => $user, - 'displayname' => 'Test Contacts', - 'uri' => 'test_contacts', - 'description' => 'Contacts to test with', - 'ctag' => 1234567890, - 'active' => 1 - ]); - }); - $adapter->expects($this->any())->method('foreachCard')->willReturnCallback(function ($addressBookId, \Closure $callBack) { - $callBack([ - 'userid' => $addressBookId, - 'uri' => '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.vcf', - 'carddata' => 'BEGIN:VCARD' - ]); - }); - $adapter->expects($this->any())->method('getShares')->willReturn($shares); - return $adapter; - } - -} diff --git a/apps/dav/tests/unit/migration/migratecalendartest.php b/apps/dav/tests/unit/migration/migratecalendartest.php deleted file mode 100644 index e62970aef34..00000000000 --- a/apps/dav/tests/unit/migration/migratecalendartest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php -/** - * @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\Tests\Unit\Migration; - -use OCA\DAV\CalDAV\CalDavBackend; -use OCA\Dav\Migration\CalendarAdapter; -use OCP\ILogger; -use Test\TestCase; - -class MigrateCalendarTest extends TestCase { - - public function testMigration() { - /** @var CalendarAdapter | \PHPUnit_Framework_MockObject_MockObject $adapter */ - $adapter = $this->mockAdapter([ - ['share_type' => '1', 'share_with' => 'users', 'permissions' => '31'], - ['share_type' => '2', 'share_with' => 'adam', 'permissions' => '1'], - ]); - - /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cardDav */ - $cardDav = $this->getMockBuilder('\OCA\Dav\CalDAV\CalDAVBackend')->disableOriginalConstructor()->getMock(); - $cardDav->expects($this->any())->method('createCalendar')->willReturn(666); - $cardDav->expects($this->once())->method('createCalendar')->with('principals/users/test01', 'test_contacts'); - $cardDav->expects($this->once())->method('createCalendarObject')->with(666, '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.ics', 'BEGIN:VCARD'); - $cardDav->expects($this->once())->method('updateShares')->with($this->anything(), [ - ['href' => 'principal:principals/groups/users', 'readOnly' => false], - ['href' => 'principal:principals/users/adam', 'readOnly' => true] - ]); - /** @var ILogger $logger */ - $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock(); - - $m = new \OCA\Dav\Migration\MigrateCalendars($adapter, $cardDav, $logger, null); - $m->migrateForUser('test01'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function mockAdapter($shares = [], $calData = 'BEGIN:VCARD') { - $adapter = $this->getMockBuilder('\OCA\Dav\Migration\CalendarAdapter') - ->disableOriginalConstructor() - ->getMock(); - $adapter->expects($this->any())->method('foreachCalendar')->willReturnCallback(function ($user, \Closure $callBack) { - $callBack([ - // calendarorder | calendarcolor | timezone | components - 'id' => 0, - 'userid' => $user, - 'displayname' => 'Test Contacts', - 'uri' => 'test_contacts', - 'ctag' => 1234567890, - 'active' => 1, - 'calendarorder' => '0', - 'calendarcolor' => '#b3dc6c', - 'timezone' => null, - 'components' => 'VEVENT,VTODO,VJOURNAL' - ]); - }); - $adapter->expects($this->any())->method('foreachCalendarObject')->willReturnCallback(function ($addressBookId, \Closure $callBack) use ($calData) { - $callBack([ - 'userid' => $addressBookId, - 'uri' => '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.ics', - 'calendardata' => $calData - ]); - }); - $adapter->expects($this->any())->method('getShares')->willReturn($shares); - return $adapter; - } -} diff --git a/apps/files_sharing/lib/mountprovider.php b/apps/files_sharing/lib/mountprovider.php index 4a60e44bb26..6c8bbb62ee7 100644 --- a/apps/files_sharing/lib/mountprovider.php +++ b/apps/files_sharing/lib/mountprovider.php @@ -55,19 +55,20 @@ class MountProvider implements IMountProvider { $shares = array_filter($shares, function ($share) { return $share['permissions'] > 0; }); - $shares = array_map(function ($share) use ($user, $storageFactory) { - - return new SharedMount( + $mounts = []; + foreach ($shares as $share) { + $mounts[] = new SharedMount( '\OC\Files\Storage\Shared', - '/' . $user->getUID() . '/' . $share['file_target'], - array( + $mounts, + [ 'share' => $share, 'user' => $user->getUID() - ), + ], $storageFactory ); - }, $shares); + } + // array_filter removes the null values from the array - return array_filter($shares); + return array_filter($mounts); } } diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php index 1e554cc5948..311e81269db 100644 --- a/apps/files_sharing/lib/sharedmount.php +++ b/apps/files_sharing/lib/sharedmount.php @@ -25,6 +25,7 @@ namespace OCA\Files_Sharing; +use OC\Files\Filesystem; use OC\Files\Mount\MountPoint; use OC\Files\Mount\MoveableMount; use OC\Files\View; @@ -50,14 +51,14 @@ class SharedMount extends MountPoint implements MoveableMount { /** * @param string $storage - * @param string $mountpoint + * @param SharedMount[] $mountpoints * @param array|null $arguments * @param \OCP\Files\Storage\IStorageFactory $loader */ - public function __construct($storage, $mountpoint, $arguments = null, $loader = null) { + public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { $this->user = $arguments['user']; $this->recipientView = new View('/' . $this->user . '/files'); - $newMountPoint = $this->verifyMountPoint($arguments['share']); + $newMountPoint = $this->verifyMountPoint($arguments['share'], $mountpoints); $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; $arguments['ownerView'] = new View('/' . $arguments['share']['uid_owner'] . '/files'); parent::__construct($storage, $absMountPoint, $arguments, $loader); @@ -67,9 +68,10 @@ class SharedMount extends MountPoint implements MoveableMount { * check if the parent folder exists otherwise move the mount point up * * @param array $share + * @param SharedMount[] $mountpoints * @return string */ - private function verifyMountPoint(&$share) { + private function verifyMountPoint(&$share, array $mountpoints) { $mountPoint = basename($share['file_target']); $parent = dirname($share['file_target']); @@ -78,10 +80,10 @@ class SharedMount extends MountPoint implements MoveableMount { $parent = Helper::getShareFolder(); } - $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget( + $newMountPoint = $this->generateUniqueTarget( \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), - [], - $this->recipientView + $this->recipientView, + $mountpoints ); if ($newMountPoint !== $share['file_target']) { @@ -94,6 +96,37 @@ class SharedMount extends MountPoint implements MoveableMount { } /** + * @param string $path + * @param View $view + * @param SharedMount[] $mountpoints + * @return mixed + */ + private function generateUniqueTarget($path, $view, array $mountpoints) { + $pathinfo = pathinfo($path); + $ext = (isset($pathinfo['extension'])) ? '.'.$pathinfo['extension'] : ''; + $name = $pathinfo['filename']; + $dir = $pathinfo['dirname']; + + // Helper function to find existing mount points + $mountpointExists = function($path) use ($mountpoints) { + foreach ($mountpoints as $mountpoint) { + if ($mountpoint->getShare()['file_target'] === $path) { + return true; + } + } + return false; + }; + + $i = 2; + while ($view->file_exists($path) || $mountpointExists($path)) { + $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext); + $i++; + } + + return $path; + } + + /** * update fileTarget in the database if the mount point changed * * @param string $newPath diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 83b72cc7449..cc591dd51d6 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -670,3 +670,15 @@ Feature: sharing When as "user1" gets properties of folder "/tmp" with |{http://owncloud.org/ns}share-permissions| Then the single response should contain a property "{http://owncloud.org/ns}share-permissions" with value "15" + + Scenario: unique target names for incomming shares + Given user "user0" exists + And user "user1" exists + And user "user2" exists + And user "user0" created a folder "/foo" + And user "user1" created a folder "/foo" + When file "/foo" of user "user0" is shared with user "user2" + And file "/foo" of user "user1" is shared with user "user2" + Then user "user2" should see following elements + | /foo/ | + | /foo%20(2)/ | diff --git a/core/css/header.css b/core/css/header.css index 5a5acb269ab..083f6f350ea 100644 --- a/core/css/header.css +++ b/core/css/header.css @@ -294,6 +294,12 @@ color: #bbb; cursor: pointer; } +#settings .icon-loading-dark { + display: inline-block; + margin-bottom: -3px; + margin-right: 6px; + background-size: 16px 16px; +} #expand { display: block; padding: 7px 30px 6px 10px; diff --git a/core/css/tooltip.css b/core/css/tooltip.css index 34d0ec6c70f..3c3582e30ef 100644 --- a/core/css/tooltip.css +++ b/core/css/tooltip.css @@ -53,6 +53,7 @@ text-align: center; background-color: #000000; border-radius: 4px; + word-break: break-all; } .tooltip-arrow { position: absolute; diff --git a/core/js/js.js b/core/js/js.js index 598e0dcd185..188c15c5db5 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1553,11 +1553,30 @@ function initCore() { } if(!event.ctrlKey) { $app.addClass('app-loading'); + } else { + // Close navigation when opening app in + // a new tab + OC.hideMenus(); + } + }); + } + + function setupUserMenu() { + var $menu = $('#header #settings'); + + $menu.delegate('a', 'click', function(event) { + var $page = $(event.target); + if (!$page.is('a')) { + $page = $page.closest('a'); } + $page.find('img').remove(); + $page.find('div').remove(); // prevent odd double-clicks + $page.prepend($('<div/>').addClass('icon-loading-dark')); }); } setupMainMenu(); + setupUserMenu(); // move triangle of apps dropdown to align with app name triangle // 2 is the additional offset between the triangles diff --git a/lib/private/lock/abstractlockingprovider.php b/lib/private/Lock/AbstractLockingProvider.php index f96358778c1..f96358778c1 100644 --- a/lib/private/lock/abstractlockingprovider.php +++ b/lib/private/Lock/AbstractLockingProvider.php diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/Lock/DBLockingProvider.php index 9e97df44d3f..9e97df44d3f 100644 --- a/lib/private/lock/dblockingprovider.php +++ b/lib/private/Lock/DBLockingProvider.php diff --git a/lib/private/lock/memcachelockingprovider.php b/lib/private/Lock/MemcacheLockingProvider.php index 536b29e2c28..536b29e2c28 100644 --- a/lib/private/lock/memcachelockingprovider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php diff --git a/lib/private/lock/nooplockingprovider.php b/lib/private/Lock/NoopLockingProvider.php index dc58230f77e..dc58230f77e 100644 --- a/lib/private/lock/nooplockingprovider.php +++ b/lib/private/Lock/NoopLockingProvider.php diff --git a/lib/private/share/share.php b/lib/private/share/share.php index c6f7258c536..2125767cabb 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -137,7 +137,7 @@ class Share extends Constants { $publicShare = false; $remoteShare = false; $source = -1; - $cache = false; + $cache = $mountPath = false; $view = new \OC\Files\View('/' . $ownerUser . '/files'); $meta = $view->getFileInfo($path); @@ -151,8 +151,14 @@ class Share extends Constants { if($meta !== false) { $source = $meta['fileid']; $cache = new \OC\Files\Cache\Cache($meta['storage']); + + $mountPath = $meta->getMountPoint()->getMountPoint(); + if ($mountPath !== false) { + $mountPath = substr($mountPath, strlen('/' . $ownerUser . '/files')); + } } + $paths = []; while ($source !== -1) { // Fetch all shares with another user if (!$returnUserPaths) { @@ -257,6 +263,7 @@ class Share extends Constants { // let's get the parent for the next round $meta = $cache->get((int)$source); if ($recursive === true && $meta !== false) { + $paths[$source] = $meta['path']; $source = (int)$meta['parent']; } else { $source = -1; @@ -285,9 +292,15 @@ class Share extends Constants { } else { while ($row = $result->fetchRow()) { foreach ($fileTargets[$row['fileid']] as $uid => $shareData) { - $sharedPath = $shareData['file_target']; - $sharedPath .= substr($path, strlen($row['path']) -5); - $sharePaths[$uid] = $sharedPath; + if ($mountPath !== false) { + $sharedPath = $shareData['file_target']; + $sharedPath .= substr($path, strlen($mountPath) + strlen($paths[$row['fileid']])); + $sharePaths[$uid] = $sharedPath; + } else { + $sharedPath = $shareData['file_target']; + $sharedPath .= substr($path, strlen($row['path']) -5); + $sharePaths[$uid] = $sharedPath; + } } } } diff --git a/lib/private/template/base.php b/lib/private/template/base.php index 2c745b02a1d..cfe629b5fbf 100644 --- a/lib/private/template/base.php +++ b/lib/private/template/base.php @@ -55,7 +55,7 @@ class Base { * @param string|false $app_dir * @param string $theme * @param string $app - * @return array + * @return string[] */ protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { // Check if the app is in the app folder or in the root @@ -74,7 +74,7 @@ class Base { /** * @param string $serverRoot * @param string $theme - * @return array + * @return string[] */ protected function getCoreTemplateDirs($theme, $serverRoot) { return [ |