[Pkg-owncloud-commits] [owncloud] 60/104: Introduce user count action to user management
David Prévot
taffit at moszumanska.debian.org
Sat Jan 18 13:33:40 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 4b4901519d144f93cd3b738d919e04a75d3cbb43
Author: Arthur Schiwon <blizzz at owncloud.com>
Date: Tue Jan 7 23:05:37 2014 +0100
Introduce user count action to user management
---
lib/private/user/backend.php | 16 +++++++++-------
lib/private/user/database.php | 15 +++++++++++++++
lib/private/user/manager.php | 18 ++++++++++++++++++
3 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php
index 02c93d1..6969ce4 100644
--- a/lib/private/user/backend.php
+++ b/lib/private/user/backend.php
@@ -31,13 +31,14 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
/**
* actions that user backends can define
*/
-define('OC_USER_BACKEND_CREATE_USER', 0x0000001);
-define('OC_USER_BACKEND_SET_PASSWORD', 0x0000010);
-define('OC_USER_BACKEND_CHECK_PASSWORD', 0x0000100);
-define('OC_USER_BACKEND_GET_HOME', 0x0001000);
-define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x0010000);
-define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x0100000);
-define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x1000000);
+define('OC_USER_BACKEND_CREATE_USER', 0x00000001);
+define('OC_USER_BACKEND_SET_PASSWORD', 0x00000010);
+define('OC_USER_BACKEND_CHECK_PASSWORD', 0x00000100);
+define('OC_USER_BACKEND_GET_HOME', 0x00001000);
+define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x00010000);
+define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x00100000);
+define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x01000000);
+define('OC_USER_BACKEND_COUNT_USERS', 0x10000000);
/**
* Abstract base class for user management. Provides methods for querying backend
@@ -55,6 +56,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar',
+ OC_USER_BACKEND_COUNT_USERS => 'countUsers',
);
/**
diff --git a/lib/private/user/database.php b/lib/private/user/database.php
index 3db770f..7b958db 100644
--- a/lib/private/user/database.php
+++ b/lib/private/user/database.php
@@ -255,4 +255,19 @@ class OC_User_Database extends OC_User_Backend {
return true;
}
+ /**
+ * counts the users in the database
+ *
+ * @return int | bool
+ */
+ public function countUsers() {
+ $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
+ $result = $query->execute();
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
+ return $result->fetchOne();
+ }
+
}
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 703c8cd..a13f4aa 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -261,4 +261,22 @@ class Manager extends PublicEmitter {
}
return false;
}
+
+ /**
+ * returns how many users per backend exist (if supported by backend)
+ *
+ * @return array with backend class as key and count number as value
+ */
+ public function countUsers() {
+ $userCountStatistics = array();
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) {
+ $backendusers = $backend->countUsers();
+ if($backendusers !== false) {
+ $userCountStatistics[get_class($backend)] = $backendusers;
+ }
+ }
+ }
+ return $userCountStatistics;
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list