From 391a989a911befd9dba6318b40234f63bbd15db0 Mon Sep 17 00:00:00 2001
From: Bjoern Schiessle <bjoern@schiessle.org>
Date: Mon, 24 Apr 2017 12:20:01 +0200
Subject: [PATCH] make sure that every data set has a 'verified' status

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
---
 lib/private/Accounts/AccountManager.php | 39 +++++++++++++++++++------
 1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index cc65ae8caa1..3f4b1d9d79a 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -134,7 +134,11 @@ class AccountManager {
 			return $userData;
 		}
 
-		return json_decode($result[0]['data'], true);
+		$userDataArray = json_decode($result[0]['data'], true);
+
+		$userDataArray = $this->addMissingDefaultValues($userDataArray);
+
+		return $userDataArray;
 	}
 
 	/**
@@ -159,6 +163,23 @@ class AccountManager {
 		}
 	}
 
+	/**
+	 * make sure that all expected data are set
+	 *
+	 * @param array $userData
+	 * @return array
+	 */
+	protected function addMissingDefaultValues(array $userData) {
+
+		foreach ($userData as $key => $value) {
+			if (!isset($userData[$key]['verified'])) {
+				$userData[$key]['verified'] = self::NOT_VERIFIED;
+			}
+		}
+
+		return $userData;
+	}
+
 	/**
 	 * reset verification status if personal data changed
 	 *
@@ -190,19 +211,19 @@ class AccountManager {
 		if($twitterVerified &&
 			$oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
 		) {
-			$newData[self::PROPERTY_TWITTER]['value']['verified'] = self::NOT_VERIFIED;
+			$newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED;
 		}
 
 		if($websiteVerified &&
 			$oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
 		) {
-			$newData[self::PROPERTY_WEBSITE]['value']['verified'] = self::NOT_VERIFIED;
+			$newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED;
 		}
 
 		if($emailVerified &&
 			$oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
 		) {
-			$newData[self::PROPERTY_EMAIL]['value']['verified'] = self::NOT_VERIFIED;
+			$newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED;
 		}
 
 		return $newData;
@@ -263,19 +284,19 @@ class AccountManager {
 				[
 					'value' => '',
 					'scope' => self::VISIBILITY_PRIVATE,
-					'verified' => '0',
+					'verified' => self::NOT_VERIFIED,
 				],
 			self::PROPERTY_WEBSITE =>
 				[
 					'value' => '',
 					'scope' => self::VISIBILITY_PRIVATE,
-					'verified' => '0',
+					'verified' => self::NOT_VERIFIED,
 				],
 			self::PROPERTY_EMAIL =>
 				[
 					'value' => $user->getEMailAddress(),
 					'scope' => self::VISIBILITY_CONTACTS_ONLY,
-					'verified' => '0',
+					'verified' => self::NOT_VERIFIED,
 				],
 			self::PROPERTY_AVATAR =>
 				[
@@ -285,13 +306,13 @@ class AccountManager {
 				[
 					'value' => '',
 					'scope' => self::VISIBILITY_PRIVATE,
-					'verified' => '0',
+					'verified' => self::NOT_VERIFIED,
 				],
 			self::PROPERTY_TWITTER =>
 				[
 					'value' => '',
 					'scope' => self::VISIBILITY_PRIVATE,
-					'verified' => '0',
+					'verified' => self::NOT_VERIFIED,
 				],
 		];
 	}
-- 
GitLab