diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php index 0c21b22a1f..d91d16d199 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 c0929aa36b..9bd6e6d3a3 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 1058773fff..ad3f6af232 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; } - }