admin: uploads/edit_note: re-render posts' htmls when note is changed
This commit is contained in:
parent
c9c5f26e2a
commit
a8889a293e
@ -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/');
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user