Fixed exception when trying to find user account and there is no user://accounts folder

This commit is contained in:
Matias Griese
2017-02-27 12:53:24 +02:00
parent da2a0f507b
commit 175fcb9415
2 changed files with 5 additions and 4 deletions

View File

@@ -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

View File

@@ -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;
}