Version 18.9

This commit is contained in:
Antonio Cañas Vargas 2018-10-28 22:21:21 +01:00
parent 69f57ed8fb
commit b2037c42ac
6 changed files with 100 additions and 133 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.8.18 (2018-10-28)"
#define Log_PLATFORM_VERSION "SWAD 18.9 (2018-10-28)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.9: Oct 28, 2018 Some sprintf for database queries changed by internal function. (236082 lines)
Version 18.8.18: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236105 lines)
Version 18.8.17: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236116 lines)
Version 18.8.16: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236263 lines)

View File

@ -3359,13 +3359,6 @@ void DB_Query_new (const char *MsgError)
DB_ExitOnMySQLError (MsgError);
}
void DB_Query (const char *Query,const char *MsgError)
{
/***** Query database *****/
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError (MsgError);
}
/*****************************************************************************/
/********** Free structure that stores the result of a SELECT query **********/
/*****************************************************************************/

View File

@ -61,7 +61,6 @@ void DB_QueryDELETE_new (const char *MsgError);
void DB_QueryDELETE (const char *Query,const char *MsgError);
void DB_Query_new (const char *MsgError);
void DB_Query (const char *Query,const char *MsgError);
void DB_FreeMySQLResult (MYSQL_RES **mysql_res);
void DB_ExitOnMySQLError (const char *Message);

View File

@ -1437,9 +1437,7 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod)
static void Rep_RemoveUsrReportsFromDB (long UsrCod)
{
char Query[128];
/***** Insert a new user's usage report into database *****/
sprintf (Query,"DELETE FROM usr_report WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE (Query,"can not remove user's usage reports");
DB_BuildQuery ("DELETE FROM usr_report WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove user's usage reports");
}

View File

@ -230,12 +230,9 @@ void Ses_UpdateSessionLastRefreshInDB (void)
static void Ses_RemoveSessionFromDB (void)
{
char Query[128 + Cns_BYTES_SESSION_ID];
/***** Remove current session *****/
sprintf (Query,"DELETE FROM sessions WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE (Query,"can not remove a session");
DB_BuildQuery ("DELETE FROM sessions WHERE SessionId='%s'",Gbl.Session.Id);
DB_QueryDELETE_new ("can not remove a session");
/***** Clear old unused social timelines in database *****/
// This is necessary to prevent the table growing and growing
@ -248,22 +245,20 @@ static void Ses_RemoveSessionFromDB (void)
void Ses_RemoveExpiredSessions (void)
{
char Query[1024];
/***** Remove expired sessions *****/
/* A session expire
when last click (LastTime) is too old,
or (when there was at least one refresh (navigator supports AJAX)
and last refresh is too old (browser probably was closed)) */
sprintf (Query,"DELETE LOW_PRIORITY FROM sessions WHERE"
DB_BuildQuery ("DELETE LOW_PRIORITY FROM sessions WHERE"
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
" OR "
"(LastRefresh>LastTime+INTERVAL 1 SECOND"
" AND"
" LastRefresh<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu'))",
Cfg_TIME_TO_CLOSE_SESSION_FROM_LAST_CLICK,
Cfg_TIME_TO_CLOSE_SESSION_FROM_LAST_REFRESH);
DB_QueryDELETE (Query,"can not remove expired sessions");
Cfg_TIME_TO_CLOSE_SESSION_FROM_LAST_CLICK,
Cfg_TIME_TO_CLOSE_SESSION_FROM_LAST_REFRESH);
DB_QueryDELETE_new ("can not remove expired sessions");
}
/*****************************************************************************/
@ -398,15 +393,13 @@ void Ses_InsertHiddenParInDB (Act_Action_t NextAction,
void Ses_RemoveHiddenParFromThisSession (void)
{
char Query[128 + Cns_BYTES_SESSION_ID];
if (Gbl.Session.IsOpen && // There is an open session
!Gbl.HiddenParamsInsertedIntoDB) // No params just inserted
{
/***** Remove hidden parameters of this session *****/
sprintf (Query,"DELETE FROM hidden_params WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE (Query,"can not remove hidden parameters of current session");
DB_BuildQuery ("DELETE FROM hidden_params WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE_new ("can not remove hidden parameters of current session");
}
}
@ -416,12 +409,10 @@ void Ses_RemoveHiddenParFromThisSession (void)
void Ses_RemoveHiddenParFromExpiredSessions (void)
{
char Query[256];
/***** Remove hidden parameters from expired sessions *****/
sprintf (Query,"DELETE FROM hidden_params"
DB_BuildQuery ("DELETE FROM hidden_params"
" WHERE SessionId NOT IN (SELECT SessionId FROM sessions)");
DB_QueryDELETE (Query,"can not remove hidden parameters of expired sessions");
DB_QueryDELETE_new ("can not remove hidden parameters of expired sessions");
}
/*****************************************************************************/

View File

@ -3398,7 +3398,6 @@ void Soc_UnshareSocialNoteUsr (void)
static long Soc_UnshareSocialNote (void)
{
extern const char *Txt_The_original_post_no_longer_exists;
char Query[256];
struct SocialNote SocNot;
long OriginalPubCod;
bool ItsMe;
@ -3416,14 +3415,14 @@ static long Soc_UnshareSocialNote (void)
Gbl.Usrs.Me.UsrDat.UsrCod)) // I am a sharer
{
/***** Delete social publishing from database *****/
sprintf (Query,"DELETE FROM social_pubs"
DB_BuildQuery ("DELETE FROM social_pubs"
" WHERE NotCod=%ld"
" AND PublisherCod=%ld"
" AND PubType=%u",
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE);
DB_QueryDELETE (Query,"can not remove a social publishing");
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE);
DB_QueryDELETE_new ("can not remove a social publishing");
/***** Update number of times this social note is shared *****/
SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot);
@ -3488,7 +3487,6 @@ static long Soc_UnfavSocialNote (void)
{
extern const char *Txt_The_original_post_no_longer_exists;
struct SocialNote SocNot;
char Query[256];
long OriginalPubCod;
bool ItsMe;
@ -3505,11 +3503,11 @@ static long Soc_UnfavSocialNote (void)
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note
{
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_notes_fav"
DB_BuildQuery ("DELETE FROM social_notes_fav"
" WHERE NotCod=%ld AND UsrCod=%ld",
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social note");
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE_new ("can not unfavourite social note");
/***** Update number of times this social note is favourited *****/
SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
@ -3574,7 +3572,6 @@ static long Soc_UnfavSocialComment (void)
extern const char *Txt_The_comment_no_longer_exists;
struct SocialComment SocCom;
bool ItsMe;
char Query[256];
/***** Initialize image *****/
Img_ImageConstructor (&SocCom.Image);
@ -3592,11 +3589,11 @@ static long Soc_UnfavSocialComment (void)
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the comment
{
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_comments_fav"
DB_BuildQuery ("DELETE FROM social_comments_fav"
" WHERE PubCod=%ld AND UsrCod=%ld",
SocCom.PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social comment");
SocCom.PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE_new ("can not unfavourite social comment");
/***** Update number of times this social comment is favourited *****/
SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom);
@ -3805,7 +3802,6 @@ static void Soc_RemoveImgFileFromSocialPost (long PstCod)
static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot)
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long PubCod;
@ -3825,10 +3821,10 @@ static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot)
}
/* Get comments of this social note */
sprintf (Query,"SELECT PubCod FROM social_pubs"
DB_BuildQuery ("SELECT PubCod FROM social_pubs"
" WHERE NotCod=%ld AND PubType=%u",
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
NumComments = DB_QuerySELECT (Query,&mysql_res,"can not get social comments");
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
NumComments = DB_QuerySELECT_new (&mysql_res,"can not get social comments");
/* For each comment... */
for (NumCom = 0;
@ -3853,48 +3849,46 @@ static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot)
/***** Remove favs *****/
/* Remove favs for all comments in this note */
sprintf (Query,"DELETE FROM social_comments_fav"
DB_BuildQuery ("DELETE FROM social_comments_fav"
" USING social_pubs,social_comments_fav"
" WHERE social_pubs.NotCod=%ld"
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments_fav.PubCod",
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove favs for social note");
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove favs for social note");
/* Remove favs for this note */
sprintf (Query,"DELETE FROM social_notes_fav WHERE NotCod=%ld",
SocNot->NotCod);
DB_QueryDELETE (Query,"can not remove favs for social note");
DB_BuildQuery ("DELETE FROM social_notes_fav WHERE NotCod=%ld",
SocNot->NotCod);
DB_QueryDELETE_new ("can not remove favs for social note");
/***** Remove content of the comments of this social note *****/
sprintf (Query,"DELETE FROM social_comments"
DB_BuildQuery ("DELETE FROM social_comments"
" USING social_pubs,social_comments"
" WHERE social_pubs.NotCod=%ld"
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments.PubCod",
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove social comments");
/***** Remove all the social publishings of this note *****/
sprintf (Query,"DELETE FROM social_pubs WHERE NotCod=%ld",
SocNot->NotCod);
DB_QueryDELETE (Query,"can not remove a social publishing");
DB_BuildQuery ("DELETE FROM social_pubs WHERE NotCod=%ld",
SocNot->NotCod);
DB_QueryDELETE_new ("can not remove a social publishing");
/***** Remove social note *****/
sprintf (Query,"DELETE FROM social_notes"
DB_BuildQuery ("DELETE FROM social_notes"
" WHERE NotCod=%ld"
" AND UsrCod=%ld", // Extra check: I am the author
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not remove a social note");
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE_new ("can not remove a social note");
if (SocNot->NoteType == Soc_NOTE_SOCIAL_POST)
{
/***** Remove social post *****/
sprintf (Query,"DELETE FROM social_posts"
" WHERE PstCod=%ld",
SocNot->Cod);
DB_QueryDELETE (Query,"can not remove a social post");
DB_BuildQuery ("DELETE FROM social_posts WHERE PstCod=%ld",SocNot->Cod);
DB_QueryDELETE_new ("can not remove a social post");
}
/***** Reset social note *****/
@ -4153,32 +4147,30 @@ static void Soc_RemoveImgFileFromSocialComment (long PubCod)
static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom)
{
char Query[128];
/***** Mark possible notifications on this comment as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_COMMENT,SocCom->PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,SocCom->PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,SocCom->PubCod);
/***** Remove favs for this comment *****/
sprintf (Query,"DELETE FROM social_comments_fav WHERE PubCod=%ld",
SocCom->PubCod);
DB_QueryDELETE (Query,"can not remove favs for social comment");
DB_BuildQuery ("DELETE FROM social_comments_fav WHERE PubCod=%ld",
SocCom->PubCod);
DB_QueryDELETE_new ("can not remove favs for social comment");
/***** Remove content of this social comment *****/
sprintf (Query,"DELETE FROM social_comments WHERE PubCod=%ld",
SocCom->PubCod);
DB_QueryDELETE (Query,"can not remove a social comment");
DB_BuildQuery ("DELETE FROM social_comments WHERE PubCod=%ld",
SocCom->PubCod);
DB_QueryDELETE_new ("can not remove a social comment");
/***** Remove this social comment *****/
sprintf (Query,"DELETE FROM social_pubs"
DB_BuildQuery ("DELETE FROM social_pubs"
" WHERE PubCod=%ld"
" AND PublisherCod=%ld" // Extra check: I am the author
" AND PubType=%u", // Extra check: it's a comment
SocCom->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove a social comment");
SocCom->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove a social comment");
/***** Reset social comment *****/
Soc_ResetSocialComment (SocCom);
@ -4190,101 +4182,98 @@ static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom)
void Soc_RemoveUsrSocialContent (long UsrCod)
{
char Query[512];
/***** Remove favs for comments *****/
/* Remove all favs made by this user in any social comment */
sprintf (Query,"DELETE FROM social_comments_fav WHERE UsrCod=%ld",
UsrCod);
DB_QueryDELETE (Query,"can not remove favs");
DB_BuildQuery ("DELETE FROM social_comments_fav WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove favs");
/* Remove all favs for all comments of this user */
sprintf (Query,"DELETE FROM social_comments_fav"
DB_BuildQuery ("DELETE FROM social_comments_fav"
" USING social_pubs,social_comments_fav"
" WHERE social_pubs.PublisherCod=%ld" // Author of the comment
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments_fav.PubCod",
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove favs");
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove favs");
/* Remove all favs for all comments in all the social notes of the user */
sprintf (Query,"DELETE FROM social_comments_fav"
DB_BuildQuery ("DELETE FROM social_comments_fav"
" USING social_notes,social_pubs,social_comments_fav"
" WHERE social_notes.UsrCod=%ld" // Author of the note
" AND social_notes.NotCod=social_pubs.NotCod"
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments_fav.PubCod",
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove social comments");
/***** Remove favs for notes *****/
/* Remove all favs made by this user in any social note */
sprintf (Query,"DELETE FROM social_notes_fav WHERE UsrCod=%ld",
UsrCod);
DB_QueryDELETE (Query,"can not remove favs");
DB_BuildQuery ("DELETE FROM social_notes_fav WHERE UsrCod=%ld",
UsrCod);
DB_QueryDELETE_new ("can not remove favs");
/* Remove all favs for all notes of this user */
sprintf (Query,"DELETE FROM social_notes_fav"
DB_BuildQuery ("DELETE FROM social_notes_fav"
" USING social_notes,social_notes_fav"
" WHERE social_notes.UsrCod=%ld" // Author of the note
" AND social_notes.NotCod=social_notes_fav.NotCod",
UsrCod);
DB_QueryDELETE (Query,"can not remove favs");
UsrCod);
DB_QueryDELETE_new ("can not remove favs");
/***** Remove social comments *****/
/* Remove content of all the comments in all the social notes of the user */
sprintf (Query,"DELETE FROM social_comments"
DB_BuildQuery ("DELETE FROM social_comments"
" USING social_notes,social_pubs,social_comments"
" WHERE social_notes.UsrCod=%ld"
" AND social_notes.NotCod=social_pubs.NotCod"
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments.PubCod",
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove social comments");
/* Remove all the comments from any user in any social note of the user */
sprintf (Query,"DELETE FROM social_pubs"
DB_BuildQuery ("DELETE FROM social_pubs"
" USING social_notes,social_pubs"
" WHERE social_notes.UsrCod=%ld"
" AND social_notes.NotCod=social_pubs.NotCod"
" AND social_pubs.PubType=%u",
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove social comments");
/* Remove content of all the comments of the user in any social note */
sprintf (Query,"DELETE FROM social_comments"
DB_BuildQuery ("DELETE FROM social_comments"
" USING social_pubs,social_comments"
" WHERE social_pubs.PublisherCod=%ld"
" AND social_pubs.PubType=%u"
" AND social_pubs.PubCod=social_comments.PubCod",
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE_new ("can not remove social comments");
/***** Remove all the social posts of the user *****/
sprintf (Query,"DELETE FROM social_posts"
DB_BuildQuery ("DELETE FROM social_posts"
" WHERE PstCod IN"
" (SELECT Cod FROM social_notes"
" WHERE UsrCod=%ld AND NoteType=%u)",
UsrCod,(unsigned) Soc_NOTE_SOCIAL_POST);
DB_QueryDELETE (Query,"can not remove social posts");
UsrCod,(unsigned) Soc_NOTE_SOCIAL_POST);
DB_QueryDELETE_new ("can not remove social posts");
/***** Remove all the social publishings of any user authored by the user *****/
sprintf (Query,"DELETE FROM social_pubs"
DB_BuildQuery ("DELETE FROM social_pubs"
" USING social_notes,social_pubs"
" WHERE social_notes.UsrCod=%ld"
" AND social_notes.NotCod=social_pubs.NotCod",
UsrCod);
DB_QueryDELETE (Query,"can not remove social publishings");
UsrCod);
DB_QueryDELETE_new ("can not remove social publishings");
/***** Remove all the social publishings of the user *****/
sprintf (Query,"DELETE FROM social_pubs WHERE PublisherCod=%ld",
UsrCod);
DB_QueryDELETE (Query,"can not remove social publishings");
DB_BuildQuery ("DELETE FROM social_pubs WHERE PublisherCod=%ld",
UsrCod);
DB_QueryDELETE_new ("can not remove social publishings");
/***** Remove all the social notes of the user *****/
sprintf (Query,"DELETE FROM social_notes WHERE UsrCod=%ld",
UsrCod);
DB_QueryDELETE (Query,"can not remove social notes");
DB_BuildQuery ("DELETE FROM social_notes WHERE UsrCod=%ld",
UsrCod);
DB_QueryDELETE_new ("can not remove social notes");
}
/*****************************************************************************/
@ -4761,12 +4750,10 @@ static void Soc_ResetSocialComment (struct SocialComment *SocCom)
void Soc_ClearOldTimelinesDB (void)
{
char Query[256];
/***** Remove social timelines for expired sessions *****/
sprintf (Query,"DELETE LOW_PRIORITY FROM social_timelines"
DB_BuildQuery ("DELETE LOW_PRIORITY FROM social_timelines"
" WHERE SessionId NOT IN (SELECT SessionId FROM sessions)");
DB_QueryDELETE (Query,"can not remove old social timelines");
DB_QueryDELETE_new ("can not remove old social timelines");
}
/*****************************************************************************/
@ -4775,12 +4762,10 @@ void Soc_ClearOldTimelinesDB (void)
static void Soc_ClearTimelineThisSession (void)
{
char Query[128 + Cns_BYTES_SESSION_ID];
/***** Remove social timeline for this session *****/
sprintf (Query,"DELETE FROM social_timelines WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE (Query,"can not remove social timeline");
DB_BuildQuery ("DELETE FROM social_timelines WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE_new ("can not remove social timeline");
}
/*****************************************************************************/