diff --git a/handler/AdminHandler.php b/handler/AdminHandler.php index e663a90..f90739f 100644 --- a/handler/AdminHandler.php +++ b/handler/AdminHandler.php @@ -323,6 +323,13 @@ class AdminHandler extends request_handler { csrf_check('editupl'.$id); $upload->setNote($lang, $note); + $texts = posts::getWithUpload($upload); + if (!empty($texts)) { + foreach ($texts as $text) { + $text->updateHtml(); + $text->updateText(); + } + } admin_log(new \AdminActions\UploadsEditNote($id, $note, $lang->value)); redirect('/admin/uploads/'); diff --git a/lib/posts.php b/lib/posts.php index 9ff1a33..02a08c6 100644 --- a/lib/posts.php +++ b/lib/posts.php @@ -327,4 +327,43 @@ class posts { return $posts; } + static function getPostTextsById(array $ids, bool $flat = false): array { + if (empty($ids)) { + return []; + } + + $db = DB(); + $posts = array_fill_keys($ids, null); + + $q = $db->query("SELECT * FROM posts_texts WHERE id IN(".implode(',', $ids).")"); + + while ($row = $db->fetch($q)) { + $posts[(int)$row['id']] = new PostText($row); + } + + if ($flat) { + $list = []; + foreach ($ids as $id) { + $list[] = $posts[$id]; + } + unset($posts); + return $list; + } + + return $posts; + } + + /** + * @param Upload $upload + * @return PostText[] Array of PostTexts that includes specified upload + */ + static function getWithUpload(Upload $upload): array { + $db = DB(); + $q = $db->query("SELECT id FROM posts_texts WHERE md LIKE '%{image,{$upload->randomId}%'"); + $ids = []; + while ($row = $db->fetch($q)) + $ids[] = (int)$row['id']; + return self::getPostTextsById($ids, true); + } + } \ No newline at end of file