summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-12-05 19:41:19 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-12-05 21:13:57 +0100
commit2be63bcb6a772dbb5600e116595751fed6ac261e (patch)
tree27d396d7d042af5ed25e493e4943155e01097ea0
parent5e44699139d59e66d65586adc3da8e4ee1c4ebde (diff)
downloadnextcloud-server-2be63bcb6a772dbb5600e116595751fed6ac261e.tar.gz
nextcloud-server-2be63bcb6a772dbb5600e116595751fed6ac261e.zip
Log and continue on Dav reader failure
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--lib/private/Repair.php2
-rw-r--r--lib/private/Repair/NC15/SetVcardDatabaseUID.php31
-rw-r--r--tests/lib/Repair/SetVcardDatabaseUIDTest.php11
3 files changed, 32 insertions, 12 deletions
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index da825c9a7ad..8bb3d3327a6 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -147,7 +147,7 @@ class Repair implements IOutput {
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
- new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig())
+ new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger())
];
}
diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php
index 210fc0a862c..cefb1c18111 100644
--- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php
+++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php
@@ -25,9 +25,11 @@ namespace OC\Repair\NC15;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\ILogger;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Sabre\VObject\Reader;
+use Sabre\VObject\ParseException;
class SetVcardDatabaseUID implements IRepairStep {
const MAX_ROWS = 1000;
@@ -38,11 +40,15 @@ class SetVcardDatabaseUID implements IRepairStep {
/** @var IConfig */
private $config;
+ /** @var ILogger */
+ private $logger;
+
private $updateQuery;
- public function __construct(IDBConnection $connection, IConfig $config) {
+ public function __construct(IDBConnection $connection, IConfig $config, ILogger $logger) {
$this->connection = $connection;
$this->config = $config;
+ $this->logger = $logger;
}
public function getName() {
@@ -75,13 +81,20 @@ class SetVcardDatabaseUID implements IRepairStep {
* Extract UID from vcard
*
* @param string $cardData the vcard raw data
+ * @param IOutput $output the output logger
* @return string the uid or empty if none
*/
- private function getUID(string $cardData): string {
- $vCard = Reader::read($cardData);
- if ($vCard->UID) {
- $uid = $vCard->UID->getValue();
- return $uid;
+ private function getUID(string $cardData, IOutput $output): string {
+ try {
+ $vCard = Reader::read($cardData);
+ if ($vCard->UID) {
+ $uid = $vCard->UID->getValue();
+
+ return $uid;
+ }
+ } catch (ParseException $e) {
+ $output->warning('One vCard is broken. We logged the exception and will continue the repair.');
+ $this->logger->logException($e);
}
return '';
@@ -106,7 +119,7 @@ class SetVcardDatabaseUID implements IRepairStep {
$this->updateQuery->execute();
}
- private function repair(): int {
+ private function repair(IOutput $output): int {
$this->connection->beginTransaction();
$entries = $this->getInvalidEntries();
$count = 0;
@@ -116,7 +129,7 @@ class SetVcardDatabaseUID implements IRepairStep {
if (is_resource($cardData)) {
$cardData = stream_get_contents($cardData);
}
- $uid = $this->getUID($cardData);
+ $uid = $this->getUID($cardData, $output);
$this->update($entry['id'], $uid);
}
$this->connection->commit();
@@ -133,7 +146,7 @@ class SetVcardDatabaseUID implements IRepairStep {
public function run(IOutput $output) {
if ($this->shouldRun()) {
- $count = $this->repair();
+ $count = $this->repair($output);
$output->info('Fixed ' . $count . ' vcards');
}
diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php
index 97da3c6a901..2939528a21a 100644
--- a/tests/lib/Repair/SetVcardDatabaseUIDTest.php
+++ b/tests/lib/Repair/SetVcardDatabaseUIDTest.php
@@ -24,6 +24,8 @@
namespace Test\Repair;
use OCP\IConfig;
+use OCP\ILogger;
+use OCP\Migration\IOutput;
use OC\Repair\NC15\SetVcardDatabaseUID;
use Test\TestCase;
@@ -38,11 +40,15 @@ class SetVcardDatabaseUIDTest extends TestCase {
/** @var IConfig */
private $config;
+ /** @var Ilogger */
+ private $logger;
+
protected function setUp() {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
- $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config);
+ $this->logger = $this->createMock(Ilogger::class);
+ $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config, $this->logger);
}
protected function tearDown() {
@@ -86,7 +92,8 @@ class SetVcardDatabaseUIDTest extends TestCase {
* @param string|boolean $expected
*/
public function testExtractUIDFromVcard($from, $expected) {
- $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from]);
+ $output = $this->createMock(IOutput::class);
+ $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from, 'output' => $output]);
$this->assertEquals($expected, $uid);
}