summaryrefslogtreecommitdiffstats
path: root/lib/private/Repair/NC15/SetVcardDatabaseUID.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Repair/NC15/SetVcardDatabaseUID.php')
-rw-r--r--lib/private/Repair/NC15/SetVcardDatabaseUID.php28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php
index 4d2805247bf..ccf6c47cbc8 100644
--- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php
+++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php
@@ -27,6 +27,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
+use Sabre\VObject\Reader;
class SetVcardDatabaseUID implements IRepairStep {
const MAX_ROWS = 1000;
@@ -70,20 +71,27 @@ class SetVcardDatabaseUID implements IRepairStep {
} while (count($rows) > 0);
}
- private function getUid($carddata) {
- preg_match('/UID:(.*)$/m', $carddata, $matches);
- if (count($matches) > 1) {
- return $matches[1];
+ /**
+ * Extract UID from vcard
+ *
+ * @param string $cardData the vcard raw data
+ * @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;
}
- return false;
+ return '';
}
/**
* @param int $id
* @param string $uid
*/
- private function update($id, $uid) {
+ private function update(int $id, string $uid) {
if (!$this->updateQuery) {
$builder = $this->connection->getQueryBuilder();
@@ -98,16 +106,14 @@ class SetVcardDatabaseUID implements IRepairStep {
$this->updateQuery->execute();
}
- private function repair() {
+ private function repair(): int {
$this->connection->beginTransaction();
$entries = $this->getInvalidEntries();
$count = 0;
foreach ($entries as $entry) {
$count++;
- $uid = $this->getUid($entry['carddata']);
- if ($uid !== false) {
- $this->update($entry['id'], $uid);
- }
+ $uid = $this->getUID($entry['carddata']);
+ $this->update($entry['id'], $uid);
}
$this->connection->commit();