From e3aaefd2e93c900c3058f790e32ab6508bce412b Mon Sep 17 00:00:00 2001 From: onli Date: Sun, 18 Nov 2018 22:57:24 +0100 Subject: [PATCH] ML: Add mediaproperties on rename (#509) --- include/functions_images.inc.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 8e09fb45..ba107453 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -335,6 +335,25 @@ function serendipity_updateImageInDatabase($updates, $id) { ); serendipity_plugin_api::hook_event('backend_media_rename', $eventData); } + + // If the user manually saved the image properties, some values might need updating now + // Name and realname are saved there as well, and the title is set to the name by default + if (isset($updates['realname'])) { + $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties + SET value = '" . serendipity_db_escape_string($updates['realname']) . "' + WHERE mediaid = " . (int)$imageBeforeChange['id'] . ' AND property = "realname" AND value = "' . $imageBeforeChange['realname'] . '"'; + serendipity_db_query($q); + $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties + SET value = '" . serendipity_db_escape_string($updates['realname']) . "' + WHERE mediaid = " . (int)$imageBeforeChange['id'] . ' AND property = "TITLE" AND value = "' . $imageBeforeChange['realname'] .'"'; + serendipity_db_query($q); + } + if (isset($updates['name'])) { + $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties + SET value = '" . $updates['name'] . "' + WHERE mediaid = " . (int)$imageBeforeChange['id'] . ' AND property = "name" AND value = "' . $imageBeforeChange['name'] .'"'; + serendipity_db_query($q); + } } return $i; }