diff --git a/sql/swad.sql b/sql/swad.sql index f7a816aa8..969f9946d 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -844,9 +844,9 @@ CREATE TABLE IF NOT EXISTS institutions ( INDEX(CtyCod), INDEX(Status)); -- --- Table links: stores the global institutional links shown on right part of page +-- Table lnk_links: stores the global institutional links shown on right part of page -- -CREATE TABLE IF NOT EXISTS links ( +CREATE TABLE IF NOT EXISTS lnk_links ( LnkCod INT NOT NULL AUTO_INCREMENT, ShortName VARCHAR(511) NOT NULL, FullName VARCHAR(2047) NOT NULL, @@ -1122,9 +1122,9 @@ CREATE TABLE IF NOT EXISTS notices_deleted ( INDEX(UsrCod), INDEX(CreatTime)); -- --- Table notif: stores the notifications of events +-- Table ntf_notifications: stores the notifications of events -- -CREATE TABLE IF NOT EXISTS notif ( +CREATE TABLE IF NOT EXISTS ntf_notifications ( NtfCod INT NOT NULL AUTO_INCREMENT, NotifyEvent TINYINT NOT NULL, ToUsrCod INT NOT NULL, diff --git a/swad_API.c b/swad_API.c index 06de8ed5e..0d7d0490a 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3342,8 +3342,9 @@ int swad__getNotifications (struct soap *soap, "CrsCod," // row[7] "Cod," // row[8] "Status" // row[9] - " FROM notif" - " WHERE ToUsrCod=%ld AND TimeNotif>=FROM_UNIXTIME(%ld)" + " FROM ntf_notifications" + " WHERE ToUsrCod=%ld" + " AND TimeNotif>=FROM_UNIXTIME(%ld)" " ORDER BY TimeNotif DESC", Gbl.Usrs.Me.UsrDat.UsrCod,beginTime); @@ -3612,8 +3613,10 @@ int swad__markNotificationsAsRead (struct soap *soap, { /***** Mark notification as read in the database *****/ DB_QueryUPDATE ("can not mark notification as read", - "UPDATE notif SET Status=(Status | %u)" - " WHERE NtfCod=%ld AND ToUsrCod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE NtfCod=%ld" + " AND ToUsrCod=%ld", (unsigned) Ntf_STATUS_BIT_READ, (long) NtfCod,Gbl.Usrs.Me.UsrDat.UsrCod); @@ -3891,7 +3894,7 @@ static int API_SendMessageToUsr (long OriginalMsgCod, /***** Create notification for this recipient. If this recipient wants to receive notifications by email, activate the sending of a notification *****/ DB_QueryINSERT ("can not create new notification event", - "INSERT INTO notif" + "INSERT INTO ntf_notifications" " (NotifyEvent,ToUsrCod,FromUsrCod,InsCod,DegCod,CrsCod,Cod,TimeNotif,Status)" " VALUES" " (%u,%ld,%ld,-1,-1,-1,%ld,NOW(),%u)", diff --git a/swad_changelog.h b/swad_changelog.h index 729aa59b8..448c1979e 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -600,13 +600,17 @@ TODO: Salvador Romero Cort TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. */ -#define Log_PLATFORM_VERSION "SWAD 20.51.15 (2021-03-19)" +#define Log_PLATFORM_VERSION "SWAD 20.51.16 (2021-03-19)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.6.2.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.51.16: Mar 19, 2021 Notifications database table renamed. (307980 lines) + 1 change necessary in database: +RENAME TABLE notif TO ntf_notifications; + Version 20.51.15: Mar 19, 2021 Holidays database table renamed. (307911 lines) 1 change necessary in database: RENAME TABLE holidays TO hld_holidays; diff --git a/swad_database.c b/swad_database.c index c1eff19a7..16ecbd16d 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1828,9 +1828,9 @@ mysql> DESCRIBE ins_instits; "INDEX(CtyCod)," "INDEX(Status))"); - /***** Table links *****/ + /***** Table lnk_links *****/ /* -mysql> DESCRIBE links; +mysql> DESCRIBE lnk_links; +-----------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------+------+-----+---------+----------------+ @@ -1841,7 +1841,7 @@ mysql> DESCRIBE links; +-----------+---------------+------+-----+---------+----------------+ 4 rows in set (0,00 sec) */ - DB_CreateTable ("CREATE TABLE IF NOT EXISTS links (" + DB_CreateTable ("CREATE TABLE IF NOT EXISTS lnk_links (" "LnkCod INT NOT NULL AUTO_INCREMENT," "ShortName VARCHAR(511) NOT NULL," // Lnk_MAX_BYTES_LINK_SHRT_NAME "FullName VARCHAR(2047) NOT NULL," // Lnk_MAX_BYTES_LINK_FULL_NAME @@ -2338,9 +2338,9 @@ mysql> DESCRIBE notices_deleted; "INDEX(UsrCod)," "INDEX(CreatTime))"); - /***** Table notif *****/ + /***** Table ntf_notifications *****/ /* -mysql> DESCRIBE notif; +mysql> DESCRIBE ntf_notifications; +-------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+----------------+ @@ -2359,7 +2359,7 @@ mysql> DESCRIBE notif; 11 rows in set (0.02 sec) */ // TODO: Change NtfCod and LogCod from INT to BIGINT in database tables. - DB_CreateTable ("CREATE TABLE IF NOT EXISTS notif (" + DB_CreateTable ("CREATE TABLE IF NOT EXISTS ntf_notifications (" "NtfCod INT NOT NULL AUTO_INCREMENT," "NotifyEvent TINYINT NOT NULL," "ToUsrCod INT NOT NULL," diff --git a/swad_enrolment.c b/swad_enrolment.c index 968a16cbe..e6e10b781 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -3074,11 +3074,12 @@ static void Enr_RemoveExpiredEnrolmentRequests (void) /***** Mark possible notifications as removed Important: do this before removing the request *****/ DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif,crs_usr_requests" - " SET notif.Status=(notif.Status | %u)" - " WHERE notif.NotifyEvent=%u" - " AND notif.Cod=crs_usr_requests.ReqCod" - " AND crs_usr_requests.RequestTimeLnkCod); @@ -501,7 +508,8 @@ void Lnk_RemoveLink (void) /***** Remove link *****/ DB_QueryDELETE ("can not remove an institutional link", - "DELETE FROM links WHERE LnkCod=%ld", + "DELETE FROM lnk_links" + " WHERE LnkCod=%ld", Lnk_EditingLnk->LnkCod); /***** Write message to show the change made *****/ @@ -622,8 +630,10 @@ static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,lo /***** Get number of links with a name from database *****/ return (DB_QueryCOUNT ("can not check if the name of an institutional link" " already existed", - "SELECT COUNT(*) FROM links" - " WHERE %s='%s' AND LnkCod<>%ld", + "SELECT COUNT(*)" + " FROM lnk_links" + " WHERE %s='%s'" + " AND LnkCod<>%ld", FieldName,Name,LnkCod) != 0); } @@ -635,7 +645,9 @@ static void Lnk_UpdateLnkNameDB (long LnkCod,const char *FieldName,const char *N { /***** Update institutional link changing old name by new name */ DB_QueryUPDATE ("can not update the name of an institutional link", - "UPDATE links SET %s='%s' WHERE LnkCod=%ld", + "UPDATE lnk_links" + " SET %s='%s'" + " WHERE LnkCod=%ld", FieldName,NewLnkName,LnkCod); } @@ -667,7 +679,9 @@ void Lnk_ChangeLinkWWW (void) { /***** Update the table changing old WWW by new WWW *****/ DB_QueryUPDATE ("can not update the web of an institutional link", - "UPDATE links SET WWW='%s' WHERE LnkCod=%ld", + "UPDATE lnk_links" + " SET WWW='%s'" + " WHERE LnkCod=%ld", NewWWW,Lnk_EditingLnk->LnkCod); /***** Message to show the change made *****/ @@ -838,7 +852,7 @@ static void Lnk_CreateLink (struct Link *Lnk) { /***** Create a new link *****/ DB_QueryINSERT ("can not create institutional link", - "INSERT INTO links" + "INSERT INTO lnk_links" " (ShortName,FullName,WWW)" " VALUES" " ('%s','%s','%s')", diff --git a/swad_notification.c b/swad_notification.c index 0c036c84f..a5866effe 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -347,13 +347,21 @@ void Ntf_ShowMyNotifications (void) sprintf (SubQuery," AND (Status&%u)=0", Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED); - NumNotifications = DB_QuerySELECT (&mysql_res,"can not get your notifications", - "SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod," - "Cod,UNIX_TIMESTAMP(TimeNotif),Status" - " FROM notif" - " WHERE ToUsrCod=%ld%s" - " ORDER BY TimeNotif DESC", - Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery); + NumNotifications = + DB_QuerySELECT (&mysql_res,"can not get your notifications", + "SELECT NotifyEvent," // row[0] + "FromUsrCod," // row[1] + "InsCod," // row[2] + "CtrCod," // row[3] + "DegCod," // row[4] + "CrsCod," // row[5] + "Cod," // row[6] + "UNIX_TIMESTAMP(TimeNotif)," // row[7] + "Status" // row[8] + " FROM ntf_notifications" + " WHERE ToUsrCod=%ld%s" + " ORDER BY TimeNotif DESC", + Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery); /***** Contextual menu *****/ Mnu_ContextMenuBegin (); @@ -913,24 +921,37 @@ void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,lon if (Cod > 0) // Set only one notification // for the user as seen DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE notif SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND Cod=%ld", (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod,(unsigned) NotifyEvent,Cod); + ToUsrCod, + (unsigned) NotifyEvent, + Cod); else if (CrsCod > 0) // Set all notifications of this type // in the current course for the user as seen DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE notif SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND CrsCod=%ld", (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod,(unsigned) NotifyEvent,Gbl.Hierarchy.Crs.CrsCod); + ToUsrCod, + (unsigned) NotifyEvent, + Gbl.Hierarchy.Crs.CrsCod); else // Set all notifications of this type // for the user as seen DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE notif SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld AND NotifyEvent=%u", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u", (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod,(unsigned) NotifyEvent); + ToUsrCod, + (unsigned) NotifyEvent); } } @@ -942,8 +963,10 @@ void Ntf_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod) { /***** Set notification as removed *****/ DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif SET Status=(Status | %u)" - " WHERE NotifyEvent=%u AND Cod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE NotifyEvent=%u" + " AND Cod=%ld", (unsigned) Ntf_STATUS_BIT_REMOVED, (unsigned) NotifyEvent,Cod); } @@ -957,18 +980,26 @@ void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long /***** Set notification as removed *****/ if (Cod > 0) // Set only one notification as removed DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND Cod=%ld", (unsigned) Ntf_STATUS_BIT_REMOVED, - ToUsrCod,(unsigned) NotifyEvent, + ToUsrCod, + (unsigned) NotifyEvent, Cod); else // Set all notifications of this type, // in the current course for the user, as removed DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND CrsCod=%ld", (unsigned) Ntf_STATUS_BIT_REMOVED, - ToUsrCod,(unsigned) NotifyEvent, + ToUsrCod, + (unsigned) NotifyEvent, Gbl.Hierarchy.Crs.CrsCod); } @@ -986,20 +1017,24 @@ void Ntf_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod) except notifications about new messages *****/ if (ToUsrCod > 0) // If the user code is specified DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif SET Status=(Status | %u)" + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" " WHERE ToUsrCod=%ld" - " AND CrsCod=%ld" - " AND NotifyEvent<>%u", // messages will remain available + " AND CrsCod=%ld" + " AND NotifyEvent<>%u", // messages will remain available (unsigned) Ntf_STATUS_BIT_REMOVED, ToUsrCod, - CrsCod,(unsigned) Ntf_EVENT_MESSAGE); + CrsCod, + (unsigned) Ntf_EVENT_MESSAGE); else // User code not specified ==> any user DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif SET Status=(Status | %u)" + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" " WHERE CrsCod=%ld" - " AND NotifyEvent<>%u", // messages will remain available + " AND NotifyEvent<>%u", // messages will remain available (unsigned) Ntf_STATUS_BIT_REMOVED, - CrsCod,(unsigned) Ntf_EVENT_MESSAGE); + CrsCod, + (unsigned) Ntf_EVENT_MESSAGE); } /*****************************************************************************/ @@ -1101,7 +1136,7 @@ void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path) return; } DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif" + "UPDATE ntf_notifications" " SET Status=(Status | %u)" " WHERE NotifyEvent=%u" " AND Cod IN" @@ -1128,7 +1163,7 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod) { /***** Set notifications as removed *****/ DB_QueryUPDATE ("can not set notification(s) as removed", - "UPDATE notif" + "UPDATE ntf_notifications" " SET Status=(Status | %u)" " WHERE NotifyEvent IN (%u,%u,%u,%u)" " AND Cod IN" @@ -1483,7 +1518,7 @@ void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent, { /***** Store notify event *****/ DB_QueryINSERT ("can not create new notification event", - "INSERT INTO notif" + "INSERT INTO ntf_notifications" " (NotifyEvent,ToUsrCod,FromUsrCod," "InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)" " VALUES" @@ -1529,11 +1564,12 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void) // !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) if ((NumRows = DB_QuerySELECT (&mysql_res,"can not get users" " who must be notified", - "SELECT DISTINCT ToUsrCod FROM notif" + "SELECT DISTINCT ToUsrCod" + " FROM ntf_notifications" " WHERE TimeNotif0" - " AND (Status & %u)=0" - " AND (Status & %u)=0", + " AND (Status & %u)<>0" + " AND (Status & %u)=0" + " AND (Status & %u)=0", Cfg_TIME_TO_SEND_PENDING_NOTIF, (unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_SENT, @@ -1572,7 +1608,7 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void) /***** Delete old notifications ******/ DB_QueryDELETE ("can not remove old notifications", - "DELETE LOW_PRIORITY FROM notif" + "DELETE LOW_PRIORITY FROM ntf_notifications" " WHERE TimeNotif0" - " AND (Status & %u)=0" - " AND (Status & %u)=0" - " ORDER BY TimeNotif,NotifyEvent", + " FROM ntf_notifications" + " WHERE ToUsrCod=%ld" + " AND (Status & %u)<>0" + " AND (Status & %u)=0" + " AND (Status & %u)=0" + " ORDER BY TimeNotif," + "NotifyEvent", ToUsrDat->UsrCod, (unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_SENT, @@ -1798,10 +1836,14 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign /***** Mark all the pending notifications of this user as 'sent' *****/ DB_QueryUPDATE ("can not set pending notifications of a user as sent", - "UPDATE notif SET Status=(Status | %u)" + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" " WHERE ToUsrCod=%ld" - " AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0", - (unsigned) Ntf_STATUS_BIT_SENT,ToUsrDat->UsrCod, + " AND (Status & %u)<>0" + " AND (Status & %u)=0" + " AND (Status & %u)=0", + (unsigned) Ntf_STATUS_BIT_SENT, + ToUsrDat->UsrCod, (unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_SENT, (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); @@ -1896,7 +1938,8 @@ void Ntf_MarkAllNotifAsSeen (void) { /***** Set all my notifications as seen *****/ DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE notif SET Status=(Status | %u)" + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" " WHERE ToUsrCod=%ld", (unsigned) Ntf_STATUS_BIT_READ, Gbl.Usrs.Me.UsrDat.UsrCod); @@ -2099,8 +2142,10 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void) { /***** Get number of places with a name from database *****/ return DB_QueryCOUNT ("can not get number of unseen notifications", - "SELECT COUNT(*) FROM notif" - " WHERE ToUsrCod=%ld AND (Status & %u)=0", + "SELECT COUNT(*)" + " FROM ntf_notifications" + " WHERE ToUsrCod=%ld" + " AND (Status & %u)=0", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); } @@ -2113,9 +2158,11 @@ static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void) { /***** Get number of places with a name from database *****/ return DB_QueryCOUNT ("can not get number of unseen notifications", - "SELECT COUNT(*) FROM notif" - " WHERE ToUsrCod=%ld AND (Status & %u)=0" - " AND TimeNotif>FROM_UNIXTIME(%ld)", + "SELECT COUNT(*)" + " FROM ntf_notifications" + " WHERE ToUsrCod=%ld" + " AND (Status & %u)=0" + " AND TimeNotif>FROM_UNIXTIME(%ld)", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED), Gbl.Usrs.Me.UsrLast.LastAccNotif); @@ -2129,6 +2176,7 @@ void Ntf_RemoveUsrNtfs (long ToUsrCod) { /***** Delete notifications of a user ******/ DB_QueryDELETE ("can not remove notifications of a user", - "DELETE LOW_PRIORITY FROM notif WHERE ToUsrCod=%ld", + "DELETE LOW_PRIORITY FROM ntf_notifications" + " WHERE ToUsrCod=%ld", ToUsrCod); }