Багфикс к DLE Forum 2.5 - удаление вложений вместе с темой
В DLE Forum 2.5 обнаружен еще один баг: при удалении темы вложенные аттачи не удаляются, тем самым накапливаются ненужные файлы.
Багфикс, чтобы при удалении темы вместе с ней удалялись приложенные вложения:
1. Открыть engine/forum/action/moderation.php (~ 112-134 строки находим):
// user converting //
if ($forum_config['set_post_num_up'])
{
$query = $db->query("SELECT distinct post_author FROM " . PREFIX . "_forum_posts WHERE topic_id = '$topic_id'");
while ($row = $db->get_row($query))
{
if ($forum_config['set_topic_post'])
{
$topic = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_forum_topics WHERE author_topic = '$row[post_author]'");
$topic_num = $topic['count'];
}
$post = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_forum_posts WHERE post_author = '$row[post_author]'");
$post_num = $post['count'];
$update = ($topic_num + $post_num);
$db->query("UPDATE " . PREFIX . "_users SET forum_post = '$update' WHERE name ='$row[post_author]'");
}
}
if ($forum_config['set_post_num_up'])
{
$query = $db->query("SELECT distinct post_author FROM " . PREFIX . "_forum_posts WHERE topic_id = '$topic_id'");
while ($row = $db->get_row($query))
{
if ($forum_config['set_topic_post'])
{
$topic = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_forum_topics WHERE author_topic = '$row[post_author]'");
$topic_num = $topic['count'];
}
$post = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_forum_posts WHERE post_author = '$row[post_author]'");
$post_num = $post['count'];
$update = ($topic_num + $post_num);
$db->query("UPDATE " . PREFIX . "_users SET forum_post = '$update' WHERE name ='$row[post_author]'");
}
}
Ниже добавляем:
$result = $db->query("SELECT * FROM " . PREFIX . "_forum_files WHERE topic_id = '" . $topic_id . "'");
while ($row = $db->get_row($result)) {
if ($row['file_type'] == "file") {
unlink(UPLOAD_DIR."files/" . $row['onserver']);
} elseif ($row['file_type'] == "thumb") {
unlink(UPLOAD_DIR."thumbs/" . $row['onserver']);
unlink(UPLOAD_DIR."images/" . $row['onserver']);
} else {
unlink(UPLOAD_DIR."images/" . $row['onserver']);
}
}
$db->query("DELETE FROM " . PREFIX . "_forum_files WHERE topic_id = '" . $topic_id . "'");
2. Переходим к файлу engine/forum/action/post.php (~ 283 строка находим):
$db->query("DELETE FROM " . PREFIX . "_forum_posts WHERE pid = '$post_id'");
После вставляем:
$result = $db->query("SELECT * FROM " . PREFIX . "_forum_files WHERE post_id = '" . $post_id . "'");
while ($row = $db->get_row($result)) {
if ($row['file_type'] == "file") {
unlink(UPLOAD_DIR."files/" . $row['onserver']);
} elseif ($row['file_type'] == "thumb") {
unlink(UPLOAD_DIR."thumbs/" . $row['onserver']);
unlink(UPLOAD_DIR."images/" . $row['onserver']);
} else {
unlink(UPLOAD_DIR."images/" . $row['onserver']);
}
}
$db->query("DELETE FROM " . PREFIX . "_forum_files WHERE post_id = '" . $post_id . "'");
3. Открываем файл engine/forum/admin/forum.php (~218-220 строки находим):
$db->query("DELETE FROM " . PREFIX . "_forum_topics WHERE forum_id = '$myrow[id]'");
$db->query("DELETE FROM " . PREFIX . "_forum_forums WHERE id = '$myrow[id]'");
Ниже добавляем:
$result = $db->query("SELECT * FROM " . PREFIX . "_forum_files WHERE forum_id = '" . $myrow['id'] . "'");
while ($row = $db->get_row($result)) {
if ($row['file_type'] == "file") {
unlink(UPLOAD_DIR."files/" . $row['onserver']);
} elseif ($row['file_type'] == "thumb") {
unlink(UPLOAD_DIR."thumbs/" . $row['onserver']);
unlink(UPLOAD_DIR."images/" . $row['onserver']);
} else {
unlink(UPLOAD_DIR."images/" . $row['onserver']);
}
}
$db->query("DELETE FROM " . PREFIX . "_forum_files WHERE forum_id = '" . $myrow['id'] . "'");
~ 526-528 строки находим:
$db->query("DELETE FROM " . PREFIX . "_forum_topics WHERE forum_id = '$id'");
$db->query("DELETE FROM " . PREFIX . "_forum_forums WHERE id = '$id'");
Ниже вставляем:
$result = $db->query("SELECT * FROM " . PREFIX . "_forum_files WHERE forum_id = '" . $id . "'");
while ($row = $db->get_row($result)) {
if ($row['file_type'] == "file") {
unlink(UPLOAD_DIR."files/" . $row['onserver']);
} elseif ($row['file_type'] == "thumb") {
unlink(UPLOAD_DIR."thumbs/" . $row['onserver']);
unlink(UPLOAD_DIR."images/" . $row['onserver']);
} else {
unlink(UPLOAD_DIR."images/" . $row['onserver']);
}
}
$db->query("DELETE FROM " . PREFIX . "_forum_files WHERE forum_id = '" . $id . "'");
Источник: