Added method to get number of accounts

This commit is contained in:
Sylvain Berfini 2019-08-21 15:07:31 +02:00
parent 03d3037398
commit 19a7ca05f5
3 changed files with 26 additions and 0 deletions

View file

@ -210,6 +210,18 @@ class Account {
return false;
}
function getCount() {
$query = "SELECT count(*) FROM " . ACCOUNTS_DB_TABLE;
$stmt = $this->conn->prepare($query);
Logger::getInstance()->debug("GetCount " . (string)$this);
if ($stmt->execute()) {
$number_of_rows = $stmt->fetchColumn();
return $number_of_rows;
}
Logger::getInstance()->error($stmt->errorInfo());
return -1;
}
function getAll() {
$query = "SELECT ac.id, ac.username, ac.domain, ac.activated, ac.confirmation_key, ac.email, al.alias FROM " . ACCOUNTS_DB_TABLE .
" ac LEFT JOIN " . ALIAS_DB_TABLE . " al ON ac.id = al.account_id";

View file

@ -965,6 +965,16 @@ function xmlrpc_delete_email_account($method, $args) {
return NOK;
}
// args = []
function xmlrpc_get_accounts_count($method, $args) {
Logger::getInstance()->message("[XMLRPC] xmlrpc_get_accounts_count()");
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
return $account->getCount();
}
function xmlrpc_accounts_register_methods($server) {
if (ALLOW_TEST_ACCOUNTS) {
// /!\ This methods must be used for tests purposes only /!\
@ -992,6 +1002,8 @@ function xmlrpc_accounts_register_methods($server) {
xmlrpc_server_register_method($server, 'update_password', 'xmlrpc_update_password');// args = [username, old password, new password, [domain], [algo]], return OK
xmlrpc_server_register_method($server, 'update_hash', 'xmlrpc_update_hash');// args = [username, old hash, new hash, [domain], [algo]], return OK
xmlrpc_server_register_method($server, 'update_email', 'xmlrpc_update_email');// args = [username, password, new email, [domain], [algo]], return OK
xmlrpc_server_register_method($server, 'get_accounts_count', 'xmlrpc_get_accounts_count');//args = []
}
?>

View file

@ -65,6 +65,8 @@ if (USE_DIGEST_AUTH) {
// compatibility
13 => 'create_account',
14 => 'create_account_with_useragent',
15 => 'get_accounts_count',
);
// Get authentication header if there is one