Some minor snapshot updates
This commit is contained in:
@@ -155,10 +155,10 @@ void DatabaseHelper::deleteClient(const std::shared_ptr<VirtualServer>& server,
|
||||
state = sql::command(this->sql, "DELETE FROM `assignedGroups` WHERE `serverId` = :sid AND `cldbid` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute();
|
||||
|
||||
if(serverId == 0) {
|
||||
state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `server_id` = :sid AND `client_database_id` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute();
|
||||
} else {
|
||||
state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `client_database_id` = :id", variable{":id", cldbid}).execute();
|
||||
state = sql::command(this->sql, "DELETE FROM `clients` WHERE `client_database_id` = :id", variable{":id", cldbid}).execute();
|
||||
} else {
|
||||
state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `server_id` = :sid AND `client_database_id` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute();
|
||||
}
|
||||
|
||||
//TODO delete letters
|
||||
|
||||
@@ -111,7 +111,7 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId
|
||||
|
||||
|
||||
sql::model insert_command{this->handle->getSql(),
|
||||
"INSERT INTO `clients_server` (`server_id`, `client_unique_id`, `client_database_id`, `client_created`, `original_client_id`) SELECT :serverId, :uniqueId, `client_database_id`, :timestamp, :org_id FROM `clients` WHERE `client_unique_id` = :uniqueId;"};
|
||||
"INSERT INTO `clients_server` (`server_id`, `client_unique_id`, `client_database_id`, `client_nickname`, `client_created`, `original_client_id`) SELECT :serverId, :uniqueId, `client_database_id`, :nickname, :timestamp, :org_id FROM `clients` WHERE `client_unique_id` = :uniqueId;"};
|
||||
|
||||
insert_command.value(":serverId", target_server_id);
|
||||
|
||||
@@ -119,7 +119,8 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId
|
||||
auto sqlResult = insert_command.command().values(
|
||||
variable{":uniqueId", client.unique_id},
|
||||
variable{":timestamp", std::chrono::floor<std::chrono::seconds>(client.timestamp_created.time_since_epoch()).count()},
|
||||
variable{":org_id", client.database_id}
|
||||
variable{":org_id", client.database_id},
|
||||
variable{":nickname", client.nickname}
|
||||
).execute();
|
||||
|
||||
if(!sqlResult)
|
||||
@@ -154,6 +155,43 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId
|
||||
error = "failed to query client database id mappings (" + map_query_result.fmtStr() + ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
/* the descriptions */
|
||||
{
|
||||
sql::InsertQuery insert_properties_query{"properties",
|
||||
sql::Column<ServerId>("serverId"),
|
||||
sql::Column<property::PropertyType>("type"),
|
||||
sql::Column<ClientDbId>("id"),
|
||||
sql::Column<std::string>("key"),
|
||||
sql::Column<std::string>("value")
|
||||
};
|
||||
|
||||
|
||||
std::string description_property{property::describe(property::CLIENT_DESCRIPTION).name};
|
||||
for(const auto& client : snapshot_data.parsed_clients) {
|
||||
if(client.description.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto new_id = mappings.client_id.find(client.database_id);
|
||||
if(new_id == mappings.client_id.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
insert_properties_query.add_entry(
|
||||
target_server_id,
|
||||
property::PROP_TYPE_CLIENT,
|
||||
new_id->second,
|
||||
description_property,
|
||||
client.description
|
||||
);
|
||||
}
|
||||
|
||||
auto presult = insert_properties_query.execute(this->handle->getSql(), true);
|
||||
if(!presult.has_succeeded()) {
|
||||
logWarning(logging_server_id, "Failed to insert some client properties into the database ({} failed)", presult.failed_entries.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* channels */
|
||||
|
||||
Reference in New Issue
Block a user