From 02f5eeb7c0447c362e8f4176218ec1a3dac88e8d Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 22 Sep 2021 14:41:49 +0200 Subject: [PATCH] Version 21.13: Sep 22, 2021 New module swad_log_database for database queries related to access logs. --- Makefile | 2 +- swad_changelog.h | 3 +- swad_layout.c | 3 +- swad_log.c | 122 ++++++----------------------------------------- swad_log.h | 3 +- 5 files changed, 22 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index d1d6cf97..4ad05010 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_institution.o swad_institution_config.o \ swad_institution_database.o \ swad_language.o swad_layout.o swad_link.o swad_link_database.o \ - swad_log.o swad_logo.o \ + swad_log.o swad_log_database.o swad_logo.o \ swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \ swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \ swad_media.o swad_media_database.o swad_menu.o swad_message.o \ diff --git a/swad_changelog.h b/swad_changelog.h index d3613070..096b0c1a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.12 (2021-09-22)" +#define Log_PLATFORM_VERSION "SWAD 21.13 (2021-09-22)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.13: Sep 22, 2021 New module swad_log_database for database queries related to access logs. (316510 lines) Version 21.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links. (316361 lines) Version 21.11.1: Sep 22, 2021 Queries moved to module swad_info_database. (316237 lines) Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information. (316228 lines) diff --git a/swad_layout.c b/swad_layout.c index 839cfe0f..0c210cb1 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -53,6 +53,7 @@ #include "swad_language.h" #include "swad_link.h" #include "swad_log.h" +#include "swad_log_database.h" #include "swad_logo.h" #include "swad_match.h" #include "swad_MFU.h" @@ -1449,7 +1450,7 @@ void Lay_RefreshNotifsAndConnected (void) else if (!(Gbl.PID % 103)) Set_RemoveOldSettingsFromIP (); // Remove old settings from IP else if (!(Gbl.PID % 107)) - Log_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query + Log_DB_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query else if (!(Gbl.PID % 109)) Fil_RemoveOldTmpFiles (Cfg_PATH_OUT_PRIVATE ,Cfg_TIME_TO_DELETE_HTML_OUTPUT ,false); else if (!(Gbl.PID % 113)) diff --git a/swad_log.c b/swad_log.c index 82331224..54ae9afa 100644 --- a/swad_log.c +++ b/swad_log.c @@ -40,6 +40,7 @@ #include "swad_HTML.h" #include "swad_institution_database.h" #include "swad_log.h" +#include "swad_log_database.h" #include "swad_profile.h" #include "swad_role.h" #include "swad_statistic.h" @@ -52,8 +53,6 @@ /***************************** Private constants *****************************/ /*****************************************************************************/ -#define Log_SECONDS_IN_RECENT_LOG ((time_t) (Cfg_DAYS_IN_RECENT_LOG * 24UL * 60UL * 60UL)) // Remove entries in recent log oldest than this time - /*****************************************************************************/ /****************************** Private types ********************************/ /*****************************************************************************/ @@ -88,50 +87,10 @@ void Log_LogAccess (const char *Comments) /***** Insert access into database *****/ /* Log access in historical log */ - LogCod = - DB_QueryINSERTandReturnCode ("can not log access", - "INSERT INTO log" - " (ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod," - "UsrCod,Role,ClickTime," - "TimeToGenerate,TimeToSend,IP)" - " VALUES" - " (%ld,%ld,%ld,%ld,%ld,%ld," - "%ld,%u,NOW()," - "%ld,%ld,'%s')", - ActCod, - Gbl.Hierarchy.Cty.CtyCod, - Gbl.Hierarchy.Ins.InsCod, - Gbl.Hierarchy.Ctr.CtrCod, - Gbl.Hierarchy.Deg.DegCod, - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) RoleToStore, - Gbl.TimeGenerationInMicroseconds, - Gbl.TimeSendInMicroseconds, - Gbl.IP); + LogCod = Log_DB_LogAccessInHistoricalLog (ActCod,RoleToStore); /* Log access in recent log (log_recent) */ - DB_QueryINSERT ("can not log access (recent)", - "INSERT INTO log_recent" - " (LogCod,ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod," - "UsrCod,Role,ClickTime," - "TimeToGenerate,TimeToSend,IP)" - " VALUES" - " (%ld,%ld,%ld,%ld,%ld,%ld,%ld," - "%ld,%u,NOW()," - "%ld,%ld,'%s')", - LogCod, - ActCod, - Gbl.Hierarchy.Cty.CtyCod, - Gbl.Hierarchy.Ins.InsCod, - Gbl.Hierarchy.Ctr.CtrCod, - Gbl.Hierarchy.Deg.DegCod, - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) RoleToStore, - Gbl.TimeGenerationInMicroseconds, - Gbl.TimeSendInMicroseconds, - Gbl.IP); + Log_DB_LogAccessInRecentLog (LogCod,ActCod,RoleToStore); /* Log access while answering exam prints */ ExaLog_LogAccess (LogCod); @@ -145,49 +104,24 @@ void Log_LogAccess (const char *Comments) Str_Copy (CommentsDB,Comments,MaxLength); Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT, CommentsDB,MaxLength,true); // Avoid SQL injection - DB_QueryINSERT ("can not log access (comments)", - "INSERT INTO log_comments" - " (LogCod,Comments)" - " VALUES" - " (%ld,'%s')", - LogCod, - CommentsDB); + Log_DB_LogComments (LogCod,CommentsDB); free (CommentsDB); } } /* Log search string */ if (Gbl.Search.LogSearch && Gbl.Search.Str[0]) - DB_QueryINSERT ("can not log access (search)", - "INSERT INTO log_search" - " (LogCod,SearchStr)" - " VALUES" - " (%ld,'%s')", - LogCod, - Gbl.Search.Str); + Log_DB_LogSearchString (LogCod); if (Gbl.WebService.IsWebService) - /* Log web service plugin and function */ - DB_QueryINSERT ("can not log access (comments)", - "INSERT INTO log_api" - " (LogCod,PlgCod,FunCod)" - " VALUES" - " (%ld,%ld,%u)", - LogCod, - Gbl.WebService.PlgCod, - (unsigned) Gbl.WebService.Function); + /* Log web service plugin and API function */ + Log_DB_LogAPI (LogCod); else { BanCodClicked = Ban_GetBanCodClicked (); if (BanCodClicked > 0) /* Log banner clicked */ - DB_QueryINSERT ("can not log banner clicked", - "INSERT INTO log_banners" - " (LogCod,BanCod)" - " VALUES" - " (%ld,%ld)", - LogCod, - BanCodClicked); + Log_DB_LogBanner (LogCod,BanCodClicked); } /***** Increment my number of clicks *****/ @@ -195,19 +129,6 @@ void Log_LogAccess (const char *Comments) Prf_DB_IncrementNumClicksUsr (Gbl.Usrs.Me.UsrDat.UsrCod); } -/*****************************************************************************/ -/************ Sometimes, we delete old entries in recent log table ***********/ -/*****************************************************************************/ - -void Log_RemoveOldEntriesRecentLog (void) - { - /***** Remove all expired clipboards *****/ - DB_QueryDELETE ("can not remove old entries from recent log", - "DELETE LOW_PRIORITY FROM log_recent" - " WHERE ClickTime