mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -07:00
Added user analytics table to database
This commit is contained in:
parent
dd4900b038
commit
d7d50def51
8 changed files with 70 additions and 14 deletions
|
|
@ -881,13 +881,45 @@ void Servatrice_DatabaseInterface::updateUsersClientID(const QString &userName,
|
|||
|
||||
}
|
||||
|
||||
void Servatrice_DatabaseInterface::updateUsersLastLoginTime(const QString &userName)
|
||||
{
|
||||
void Servatrice_DatabaseInterface::updateUsersLastLoginData(const QString &userName, const QString &clientVersion) {
|
||||
|
||||
if (!checkSql())
|
||||
return;
|
||||
|
||||
QSqlQuery *query = prepareQuery("update {prefix}_users set last_login = NOW() where name = :user_name");
|
||||
query->bindValue(":user_name", userName);
|
||||
execSqlQuery(query);
|
||||
int usersID;
|
||||
|
||||
QSqlQuery *query = prepareQuery("select id from {prefix}_users where name = :user_name");
|
||||
query->bindValue(":user_name", userName);
|
||||
if (!execSqlQuery(query)) {
|
||||
qDebug("Failed to locate user id when updating users last login data: SQL Error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (query->next()) {
|
||||
usersID = query->value(0).toInt();
|
||||
}
|
||||
|
||||
if (usersID) {
|
||||
int userCount;
|
||||
query = prepareQuery("select count(id) from {prefix}_user_analytics where id = :user_id");
|
||||
query->bindValue(":user_id", usersID);
|
||||
if (!execSqlQuery(query))
|
||||
return;
|
||||
|
||||
if (query->next()) {
|
||||
userCount = query->value(0).toInt();
|
||||
}
|
||||
|
||||
if (!userCount) {
|
||||
query = prepareQuery("insert into {prefix}_user_analytics (id,client_ver,last_login) values (:user_id,:client_ver,NOW())");
|
||||
query->bindValue(":user_id", usersID);
|
||||
query->bindValue(":client_ver", clientVersion);
|
||||
execSqlQuery(query);
|
||||
} else {
|
||||
query = prepareQuery("update {prefix}_user_analytics set last_login = NOW(), client_ver = :client_ver where id = :user_id");
|
||||
query->bindValue(":client_ver", clientVersion);
|
||||
query->bindValue(":user_id", usersID);
|
||||
execSqlQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include "server.h"
|
||||
#include "server_database_interface.h"
|
||||
|
||||
#define DATABASE_SCHEMA_VERSION 7
|
||||
#define DATABASE_SCHEMA_VERSION 8
|
||||
|
||||
class Servatrice;
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ public:
|
|||
const QString &password, const QString &emailAddress, const QString &country, QString &token, bool active = false);
|
||||
bool activateUser(const QString &userName, const QString &token);
|
||||
void updateUsersClientID(const QString &userName, const QString &userClientID);
|
||||
void updateUsersLastLoginTime(const QString &userName);
|
||||
void updateUsersLastLoginData(const QString &userName, const QString &clientVersion);
|
||||
void logMessage(const int senderId, const QString &senderName, const QString &senderIp, const QString &logMessage,
|
||||
LogMessage_TargetType targetType, const int targetId, const QString &targetName);
|
||||
bool changeUserPassword(const QString &user, const QString &oldPassword, const QString &newPassword);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue