aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-07 14:11:14 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-07 15:04:19 +0100
commitd32b35fc7f89dd941267d5d7b907b05070f5f81c (patch)
treeb57c748cb0d1609737e6481aa8cd37f2d891cd1e
parenta61fa5b52675d0f1742c0dbe605df7a816ce1570 (diff)
downloadnextcloud-server-d32b35fc7f89dd941267d5d7b907b05070f5f81c.tar.gz
nextcloud-server-d32b35fc7f89dd941267d5d7b907b05070f5f81c.zip
Handle calendar migration issue by writing the faulty event to the log and continue
-rw-r--r--apps/dav/appinfo/application.php5
-rw-r--r--apps/dav/lib/migration/migratecalendars.php28
-rw-r--r--apps/dav/tests/unit/migration/migratecalendartest.php12
3 files changed, 34 insertions, 11 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php
index 0c21b22a1fe..d91d16d199d 100644
--- a/apps/dav/appinfo/application.php
+++ b/apps/dav/appinfo/application.php
@@ -108,9 +108,12 @@ class Application extends App {
$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')
+ $c->query('CalDavBackend'),
+ $logger,
+ null
);
});
diff --git a/apps/dav/lib/migration/migratecalendars.php b/apps/dav/lib/migration/migratecalendars.php
index c0929aa36be..9bd6e6d3a3f 100644
--- a/apps/dav/lib/migration/migratecalendars.php
+++ b/apps/dav/lib/migration/migratecalendars.php
@@ -23,9 +23,7 @@ namespace OCA\Dav\Migration;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Calendar;
-use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputInterface;
+use OCP\ILogger;
use Symfony\Component\Console\Output\OutputInterface;
class MigrateCalendars {
@@ -36,15 +34,25 @@ class MigrateCalendars {
/** @var CalDavBackend */
private $backend;
+ /** @var ILogger */
+ private $logger;
+
+ /** @var OutputInterface */
+ private $consoleOutput;
+
/**
* @param CalendarAdapter $adapter
* @param CalDavBackend $backend
*/
function __construct(CalendarAdapter $adapter,
- CalDavBackend $backend
+ CalDavBackend $backend,
+ ILogger $logger,
+ OutputInterface $consoleOutput = null
) {
$this->adapter = $adapter;
$this->backend = $backend;
+ $this->logger = $logger;
+ $this->consoleOutput = $consoleOutput;
}
/**
@@ -82,7 +90,17 @@ class MigrateCalendars {
*/
private function migrateCalendar($calendarId, $newCalendarId) {
$this->adapter->foreachCalendarObject($calendarId, function($calObject) use ($newCalendarId) {
- $this->backend->createCalendarObject($newCalendarId, $calObject['uri'], $calObject['calendardata']);
+ 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);
+ }
+ }
});
}
diff --git a/apps/dav/tests/unit/migration/migratecalendartest.php b/apps/dav/tests/unit/migration/migratecalendartest.php
index 1058773ffff..ad3f6af2322 100644
--- a/apps/dav/tests/unit/migration/migratecalendartest.php
+++ b/apps/dav/tests/unit/migration/migratecalendartest.php
@@ -22,6 +22,7 @@ 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 {
@@ -35,15 +36,17 @@ class MigrateCalendarTest extends TestCase {
$cardDav->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');
+ /** @var ILogger $logger */
+ $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock();
- $m = new \OCA\Dav\Migration\MigrateCalendars($adapter, $cardDav);
+ $m = new \OCA\Dav\Migration\MigrateCalendars($adapter, $cardDav, $logger, null);
$m->migrateForUser('test01');
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
- private function mockAdapter($shares = []) {
+ private function mockAdapter($shares = [], $calData = 'BEGIN:VCARD') {
$adapter = $this->getMockBuilder('\OCA\Dav\Migration\CalendarAdapter')
->disableOriginalConstructor()
->getMock();
@@ -62,15 +65,14 @@ class MigrateCalendarTest extends TestCase {
'components' => 'VEVENT,VTODO,VJOURNAL'
]);
});
- $adapter->method('foreachCalendarObject')->willReturnCallback(function ($addressBookId, \Closure $callBack) {
+ $adapter->method('foreachCalendarObject')->willReturnCallback(function ($addressBookId, \Closure $callBack) use ($calData) {
$callBack([
'userid' => $addressBookId,
'uri' => '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.ics',
- 'calendardata' => 'BEGIN:VCARD'
+ 'calendardata' => $calData
]);
});
$adapter->method('getShares')->willReturn($shares);
return $adapter;
}
-
}