summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorblizzz <blizzz@owncloud.com>2014-01-08 10:41:39 -0800
committerblizzz <blizzz@owncloud.com>2014-01-08 10:41:39 -0800
commitd8b8abb429d3d66598a16d25cf55f7dc19e3f996 (patch)
tree085c9d1173d570f02fbf1bc88fb6ec27a674c42a /lib/private
parent0e7283ef39d7fe2e80585c190d8e1dc2cb511c96 (diff)
parent4585b4ea3f1fd21aabc167102e74a382dfa0cbd8 (diff)
downloadnextcloud-server-d8b8abb429d3d66598a16d25cf55f7dc19e3f996.tar.gz
nextcloud-server-d8b8abb429d3d66598a16d25cf55f7dc19e3f996.zip
Merge pull request #6681 from owncloud/userreport
add command line option to get user number statistics
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/user/backend.php17
-rw-r--r--lib/private/user/database.php15
-rw-r--r--lib/private/user/dummy.php9
-rw-r--r--lib/private/user/manager.php22
4 files changed, 56 insertions, 7 deletions
diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php
index 02c93d13bdf..f4e5618e04a 100644
--- a/lib/private/user/backend.php
+++ b/lib/private/user/backend.php
@@ -31,13 +31,15 @@ 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);
+//more actions cannot be defined without breaking 32bit platforms!
/**
* Abstract base class for user management. Provides methods for querying backend
@@ -55,6 +57,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 c99db3b27ca..1a63755b980 100644
--- a/lib/private/user/database.php
+++ b/lib/private/user/database.php
@@ -253,4 +253,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/dummy.php b/lib/private/user/dummy.php
index 52be7edfa75..fc15a630cf3 100644
--- a/lib/private/user/dummy.php
+++ b/lib/private/user/dummy.php
@@ -123,4 +123,13 @@ class OC_User_Dummy extends OC_User_Backend {
public function hasUserListings() {
return true;
}
+
+ /**
+ * counts the users in the database
+ *
+ * @return int | bool
+ */
+ public function countUsers() {
+ return 0;
+ }
}
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index cf83a75ba25..90970ef9963 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -270,4 +270,26 @@ 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) {
+ if(isset($userCountStatistics[get_class($backend)])) {
+ $userCountStatistics[get_class($backend)] += $backendusers;
+ } else {
+ $userCountStatistics[get_class($backend)] = $backendusers;
+ }
+ }
+ }
+ }
+ return $userCountStatistics;
+ }
}