Handle addressbook migration issue by writing the faulty event to the log and continue
This commit is contained in:
parent
6413fffdcb
commit
79811b5806
|
@ -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
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue