diff --git a/CHANGELOG.md b/CHANGELOG.md index 6441c29d4..a57669a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ 1. [](#new) * Added `Route::withoutParams()` methods * Added `Pages::setCheckMethod()` method to override page configuration in Admin Plugin - * Added `Cache::clearCache('invalidate')` parameter for just invalidating the cache without deleting any cached files + * Added `Cache::clearCache('invalidate')` parameter for just invalidating the cache without deleting any cached files + * Made `UserCollectionInderface` to extend `Countable` to get the count of existing users 1. [](#improved) * Flex admin: added default search options for flex objects 1. [](#bugfix) diff --git a/system/src/Grav/Common/User/DataUser/UserCollection.php b/system/src/Grav/Common/User/DataUser/UserCollection.php index 0970ce7d3..800322a9f 100644 --- a/system/src/Grav/Common/User/DataUser/UserCollection.php +++ b/system/src/Grav/Common/User/DataUser/UserCollection.php @@ -118,4 +118,13 @@ class UserCollection implements UserCollectionInterface return $file_path && unlink($file_path); } + + public function count(): int + { + // check for existence of a user account + $account_dir = $file_path = Grav::instance()['locator']->findResource('account://'); + $accounts = glob($account_dir . '/*.yaml') ?: []; + + return count($accounts); + } } diff --git a/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php b/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php index a8cc7d65c..37b9009a5 100644 --- a/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php +++ b/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php @@ -9,7 +9,7 @@ namespace Grav\Common\User\Interfaces; -interface UserCollectionInterface +interface UserCollectionInterface extends \Countable { /** * Load user account.