From db0921ab18a90f2d2ce29e2d1c70fa85fa7c313b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 19 Mar 2019 11:32:22 +0100 Subject: [PATCH] Version18.81.5 --- swad_changelog.h | 3 ++- swad_test.c | 3 +-- swad_timeline.c | 42 +++++++++++++++++++++++++----------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 2a320d137..810d3c924 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -459,10 +459,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.81.4 (2019-03-19)" +#define Log_PLATFORM_VERSION "SWAD 18.81.5 (2019-03-19)" #define CSS_FILE "swad18.80.css" #define JS_FILE "swad18.80.js" /* + Version 18.81.5: Mar 19, 2019 Code refactoring related to media. (240594 lines) Version 18.81.4: Mar 19, 2019 Code refactoring related to media. (240586 lines) Version 18.81.3: Mar 19, 2019 Remove unused fields MediaName,MediaType,MediaTitle,MediaURL,Media from tables. (240657 lines) 8 changes necessary in database: diff --git a/swad_test.c b/swad_test.c index 6a415e908..ffa2291f8 100644 --- a/swad_test.c +++ b/swad_test.c @@ -8498,8 +8498,7 @@ void Tst_RemoveCrsTests (long CrsCod) " AND tst_questions.QstCod=tst_answers.QstCod", CrsCod); - /***** Remove files with images associated - to test questions in the course *****/ + /***** Remove media associated to test questions in the course *****/ Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (CrsCod); Tst_RemoveAllMedFilesFromStemOfAllQstsInCrs (CrsCod); diff --git a/swad_timeline.c b/swad_timeline.c index e7a99192d..2bbd5752f 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -3858,7 +3858,7 @@ static void TL_RemoveNoteMediaAndDBEntries (struct TL_Note *SocNot) long PubCod; unsigned long NumComments; unsigned long NumCom; - unsigned NumMedia; + long MedCod; /***** Remove comments associated to this note *****/ /* Get comments of this note */ @@ -3889,16 +3889,20 @@ static void TL_RemoveNoteMediaAndDBEntries (struct TL_Note *SocNot) /***** Remove media associated to post *****/ if (SocNot->NoteType == TL_NOTE_POST) { - /* Get name of media associated to a post from database */ - NumMedia = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get media", + /* Remove media associated to a post from database */ + if (DB_QuerySELECT (&mysql_res,"can not get media", "SELECT MedCod" // row[0] " FROM social_posts" " WHERE PstCod=%ld", - SocNot->Cod); + SocNot->Cod) == 1) // Result should have a unique row + { + /* Get media code */ + row = mysql_fetch_row (mysql_res); + MedCod = Str_ConvertStrCodToLongCod (row[0]); - /* Remove media */ - Med_RemoveMediaFromAllRows (NumMedia,mysql_res); + /* Remove media */ + Med_RemoveMedia (MedCod); + } /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -4170,19 +4174,23 @@ static void TL_RemoveComment (void) static void TL_RemoveCommentMediaAndDBEntries (long PubCod) { MYSQL_RES *mysql_res; - unsigned NumMedia; + MYSQL_ROW row; + long MedCod;; /***** Remove media associated to comment *****/ - /* Get name of media associated to a comment from database */ - NumMedia = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT MedCod" // row[0] - " FROM social_comments" - " WHERE PubCod=%ld", - PubCod); + if (DB_QuerySELECT (&mysql_res,"can not get media", + "SELECT MedCod" // row[0] + " FROM social_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]); - /* Remove media */ - Med_RemoveMediaFromAllRows (NumMedia,mysql_res); + /* Remove media */ + Med_RemoveMedia (MedCod); + } /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res);