aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-07 14:34:28 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-07 15:04:19 +0100
commit3b25ccef657fe43d4adba639c443f5d42178a2dd (patch)
tree2b1ab44dc96a6828f3b766062721c56b4d185e41 /apps/dav
parentd32b35fc7f89dd941267d5d7b907b05070f5f81c (diff)
downloadnextcloud-server-3b25ccef657fe43d4adba639c443f5d42178a2dd.tar.gz
nextcloud-server-3b25ccef657fe43d4adba639c443f5d42178a2dd.zip
Handle addressbook migration issue by writing the faulty event to the log and continue
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/appinfo/application.php5
-rw-r--r--apps/dav/lib/migration/migrateaddressbooks.php29
-rw-r--r--apps/dav/tests/unit/migration/migrateaddressbooktest.php5
3 files changed, 32 insertions, 7 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php
index d91d16d199d..1dae3d4efbf 100644
--- a/apps/dav/appinfo/application.php
+++ b/apps/dav/appinfo/application.php
@@ -99,9 +99,12 @@ class Application extends App {
$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')
+ $c->query('CardDavBackend'),
+ $logger,
+ null
);
});
diff --git a/apps/dav/lib/migration/migrateaddressbooks.php b/apps/dav/lib/migration/migrateaddressbooks.php
index d26ca4c1810..c0223b30e2c 100644
--- a/apps/dav/lib/migration/migrateaddressbooks.php
+++ b/apps/dav/lib/migration/migrateaddressbooks.php
@@ -23,10 +23,8 @@ 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\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MigrateAddressbooks {
@@ -37,15 +35,26 @@ class MigrateAddressbooks {
/** @var CardDavBackend */
private $backend;
+ /** @var ILogger */
+ private $logger;
+
+ /** @var OutputInterface */
+ private $consoleOutput;
+
+
/**
* @param AddressBookAdapter $adapter
* @param CardDavBackend $backend
*/
function __construct(AddressBookAdapter $adapter,
- CardDavBackend $backend
+ CardDavBackend $backend,
+ ILogger $logger,
+ OutputInterface $consoleOutput = null
) {
$this->adapter = $adapter;
$this->backend = $backend;
+ $this->logger = $logger;
+ $this->consoleOutput = $consoleOutput;
}
/**
@@ -80,7 +89,17 @@ class MigrateAddressbooks {
*/
private function migrateBook($addressBookId, $newAddressBookId) {
$this->adapter->foreachCard($addressBookId, function($card) use ($newAddressBookId) {
- $this->backend->createCard($newAddressBookId, $card['uri'], $card['carddata']);
+ 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);
+ }
+ }
});
}
diff --git a/apps/dav/tests/unit/migration/migrateaddressbooktest.php b/apps/dav/tests/unit/migration/migrateaddressbooktest.php
index 1b27536ce3b..0679e687a04 100644
--- a/apps/dav/tests/unit/migration/migrateaddressbooktest.php
+++ b/apps/dav/tests/unit/migration/migrateaddressbooktest.php
@@ -22,6 +22,7 @@ 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 {
@@ -35,8 +36,10 @@ class MigrateAddressbookTest extends TestCase {
$cardDav->method('createAddressBook')->willReturn(666);
$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');
+ /** @var ILogger $logger */
+ $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock();
- $m = new \OCA\Dav\Migration\MigrateAddressbooks($adapter, $cardDav);
+ $m = new \OCA\Dav\Migration\MigrateAddressbooks($adapter, $cardDav, $logger, null);
$m->migrateForUser('test01');
}