From 6af858c41b777e7324f0832bededdb4b99a8187c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Fri, 4 Dec 2015 11:50:11 +0100
Subject: [PATCH] Delete no longer existing users from system addressbook

---
 apps/dav/command/syncsystemaddressbook.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php
index bb2896abc60..162ab362892 100644
--- a/apps/dav/command/syncsystemaddressbook.php
+++ b/apps/dav/command/syncsystemaddressbook.php
@@ -88,6 +88,18 @@ class SyncSystemAddressBook extends Command {
 			}
 			$progress->advance();
 		});
+
+		// remove no longer existing
+		$allCards = $this->backend->getCards($systemAddressBook['id']);
+		foreach($allCards as $card) {
+			$vCard = Reader::read($card['carddata']);
+			$uid = $vCard->UID->getValue();
+			// load backend and see if user exists
+			if (!$this->userManager->userExists($uid)) {
+				$this->backend->deleteCard($systemAddressBook['id'], $card['uri']);
+			}
+		}
+
 		$progress->finish();
 		$output->writeln('');
 	}
-- 
GitLab