From 175fcb9415201d8065015497af83e303b4c58f8e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 27 Feb 2017 12:53:24 +0200 Subject: [PATCH] Fixed exception when trying to find user account and there is no `user://accounts` folder --- CHANGELOG.md | 3 ++- system/src/Grav/Common/User/User.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d65406c..620be3db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ 1. [](#improved) * Genericized `direct-install` so it can be called via Admin plugin 1. [](#bugfix) - * Fix a minor bug in Number validation [#1329](https://github.com/getgrav/grav/issues/1329) + * Fixed a minor bug in Number validation [#1329](https://github.com/getgrav/grav/issues/1329) + * Fixed exception when trying to find user account and there is no `user://accounts` folder # v1.1.17 ## 02/17/2017 diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index fcc8f6c43..d5c108ff8 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -57,14 +57,14 @@ class User extends Data /** * Find a user by username, email, etc * - * @param $query the query to search for + * @param string $query the query to search for * @param array $fields the fields to search * @return User */ public static function find($query, $fields = ['username', 'email']) { $account_dir = Grav::instance()['locator']->findResource('account://'); - $files = array_diff(scandir($account_dir), ['.', '..']); + $files = $account_dir ? array_diff(scandir($account_dir), ['.', '..']) : []; // Try with username first, you never know! if (in_array('username', $fields)) { @@ -100,7 +100,7 @@ class User extends Data public static function remove($username) { $file_path = Grav::instance()['locator']->findResource('account://' . $username . YAML_EXT); - if (file_exists($file_path) && unlink($file_path)) { + if ($file_path && unlink($file_path)) { return true; }