summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2019-12-13 15:43:36 +0100
committerGitHub <noreply@github.com>2019-12-13 15:43:36 +0100
commitf7674c592ca0677645fa9ec01c7b865b9a6c5a8e (patch)
tree5b4b4972f62a31f4e02e9c5cb74cb0cbddadd501 /lib
parent9cafc508d501e021463adb1eef9f5388ea0ee459 (diff)
parentb97d90e0c3a9064127cf203e92c5c18bde129703 (diff)
downloadnextcloud-server-f7674c592ca0677645fa9ec01c7b865b9a6c5a8e.tar.gz
nextcloud-server-f7674c592ca0677645fa9ec01c7b865b9a6c5a8e.zip
Merge pull request #17494 from nextcloud/fix/16340/ignore-invalid-json
Return a default user record if json is broken
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Accounts/AccountManager.php16
-rw-r--r--lib/private/Accounts/Hooks.php8
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index f1607b1a1ef..225d076ca37 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -1,4 +1,5 @@
<?php
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Björn Schießle
@@ -33,9 +34,12 @@ use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection;
+use OCP\ILogger;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
+use function json_decode;
+use function json_last_error;
/**
* Class AccountManager
@@ -59,6 +63,9 @@ class AccountManager implements IAccountManager {
/** @var IJobList */
private $jobList;
+ /** @var ILogger */
+ private $logger;
+
/**
* AccountManager constructor.
*
@@ -68,10 +75,12 @@ class AccountManager implements IAccountManager {
*/
public function __construct(IDBConnection $connection,
EventDispatcherInterface $eventDispatcher,
- IJobList $jobList) {
+ IJobList $jobList,
+ ILogger $logger) {
$this->connection = $connection;
$this->eventDispatcher = $eventDispatcher;
$this->jobList = $jobList;
+ $this->logger = $logger;
}
/**
@@ -137,6 +146,11 @@ class AccountManager implements IAccountManager {
}
$userDataArray = json_decode($result[0]['data'], true);
+ $jsonError = json_last_error();
+ if ($userDataArray === null || $jsonError !== JSON_ERROR_NONE) {
+ $this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record");
+ return $this->buildDefaultUserRecord($user);
+ }
$userDataArray = $this->addMissingDefaultValues($userDataArray);
diff --git a/lib/private/Accounts/Hooks.php b/lib/private/Accounts/Hooks.php
index 5c6826a6f9e..268f9d82753 100644
--- a/lib/private/Accounts/Hooks.php
+++ b/lib/private/Accounts/Hooks.php
@@ -87,12 +87,8 @@ class Hooks {
* @return AccountManager
*/
protected function getAccountManager() {
- if (is_null($this->accountManager)) {
- $this->accountManager = new AccountManager(
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getEventDispatcher(),
- \OC::$server->getJobList()
- );
+ if ($this->accountManager === null) {
+ $this->accountManager = \OC::$server->query(AccountManager::class);
}
return $this->accountManager;
}