From 70bd31cf91e2f98e42608f0bb9866007f4ffd05e Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 27 Feb 2021 15:09:23 +0100 Subject: [PATCH] Version 20.36.11: Feb 27, 2021 Query moved to module swad_timeline_database. --- swad_changelog.h | 3 +- swad_timeline_database.c | 60 ++++++++++++++++++++++++++-------------- swad_timeline_database.h | 3 ++ swad_timeline_note.c | 19 +------------ 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 74d3d6eb..b9717075 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.36.10 (2021-02-07)" +#define Log_PLATFORM_VERSION "SWAD 20.36.11 (2021-02-07)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts + Version 20.36.11: Feb 27, 2021 Query moved to module swad_timeline_database. (305246 lines) Version 20.36.10: Feb 27, 2021 Query moved to module swad_timeline_database. (305243 lines) Version 20.36.9: Feb 27, 2021 Query moved to module swad_timeline_database. (305233 lines) Version 20.36.8: Feb 27, 2021 Function moved to module swad_timeline_database. (305215 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index e29bdc7e..529f01ba 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -50,6 +50,8 @@ /***************************** Private prototypes ****************************/ /*****************************************************************************/ +static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable); + /*****************************************************************************/ /***************************** Create a new note *****************************/ /*****************************************************************************/ @@ -128,6 +130,15 @@ void TL_DB_InsertNoteInVisibleTimeline (long NotCod) NotCod); } +/*****************************************************************************/ +/***************** Get code of media associated to post **********************/ +/*****************************************************************************/ + +long TL_DB_GetMedCodFromPost (long PubCod) + { + return TL_DB_GetMedCodFromPub (PubCod,"tl_posts"); + } + /*****************************************************************************/ /********************* Get number of comments in a note **********************/ /*****************************************************************************/ @@ -265,26 +276,7 @@ void TL_DB_InsertCommentContent (long PubCod, long TL_DB_GetMedCodFromComment (long PubCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - long MedCod = -1L; // Default value - - /***** Get code of media associated to comment *****/ - if (DB_QuerySELECT (&mysql_res,"can not get media code", - "SELECT MedCod" // row[0] - " FROM tl_comments" - " WHERE PubCod=%ld", - PubCod) == 1) // Result should have a unique row - { - /* Get media code */ - row = mysql_fetch_row (mysql_res); - MedCod = Str_ConvertStrCodToLongCod (row[0]); - } - - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_res); - - return MedCod; + return TL_DB_GetMedCodFromPub (PubCod,"tl_comments"); } /*****************************************************************************/ @@ -329,3 +321,31 @@ void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod) PublisherCod, (unsigned) TL_Pub_COMMENT_TO_NOTE); } + +/*****************************************************************************/ +/*************** Get code of media associated to post/comment ****************/ +/*****************************************************************************/ + +static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + long MedCod = -1L; // Default value + + /***** Get code of media associated to comment *****/ + if (DB_QuerySELECT (&mysql_res,"can not get media code", + "SELECT MedCod" // row[0] + " FROM %s" + " WHERE PubCod=%ld", + DBTable,PubCod) == 1) // Result should have a unique row + { + /* Get media code */ + row = mysql_fetch_row (mysql_res); + MedCod = Str_ConvertStrCodToLongCod (row[0]); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_res); + + return MedCod; + } diff --git a/swad_timeline_database.h b/swad_timeline_database.h index bc2b2c9b..330e79c8 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -55,6 +55,9 @@ void TL_DB_MarkNotesChildrenOfFolderAsUnavailable (TL_Not_NoteType_t NoteType, void TL_DB_InsertNoteInJustRetrievedNotes (long NotCod); void TL_DB_InsertNoteInVisibleTimeline (long NotCod); +/* Posts */ +long TL_DB_GetMedCodFromPost (long PubCod); + /* Comments */ unsigned TL_DB_GetNumCommentsInNote (long NotCod); unsigned TL_DB_GetComments (long NotCod,MYSQL_RES **mysql_res); diff --git a/swad_timeline_note.c b/swad_timeline_note.c index ed38d6a3..8a2f5caa 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1228,25 +1228,8 @@ static void TL_Not_RemoveNoteMediaAndDBEntries (struct TL_Not_Note *Not) /***** Remove media associated to post *****/ if (Not->NoteType == TL_NOTE_POST) - { - /* Remove media associated to a post from database */ - if (DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT MedCod" // row[0] - " FROM tl_posts" - " WHERE PstCod=%ld", - Not->Cod) == 1) // Result should have a unique row - { - /* Get media code */ - row = mysql_fetch_row (mysql_res); - MedCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Remove media */ + if ((MedCod = TL_DB_GetMedCodFromPost (Not->Cod)) > 0) Med_RemoveMedia (MedCod); - } - - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_res); - } /***** Mark possible notifications on the publications of this note as removed *****/