From 2a10e1c6b0981b15d6fdc3bb5bbd66f7e735c0fe Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 16 Apr 2021 20:49:23 +0100 Subject: [PATCH] MDL-71359 mod_forum: empty forums shouldn't export anything. --- mod/forum/export.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mod/forum/export.php b/mod/forum/export.php index 725c1aba0a3..1810d6bef0e 100644 --- a/mod/forum/export.php +++ b/mod/forum/export.php @@ -90,7 +90,6 @@ if ($form->is_cancelled()) { raise_memory_limit(MEMORY_HUGE); $discussionvault = $vaultfactory->get_discussion_vault(); - $postvault = $vaultfactory->get_post_vault(); if ($data->discussionids) { $discussionids = $data->discussionids; } else if (empty($discussionids)) { @@ -111,8 +110,13 @@ if ($form->is_cancelled()) { $filters['to'] = $data->to; } - // Retrieve posts based on the selected filters. - $posts = $postvault->get_from_filters($USER, $filters, $capabilitymanager->can_view_any_private_reply($USER)); + // Retrieve posts based on the selected filters, note if forum has no discussions then there is nothing to export. + if (!empty($filters['discussionids'])) { + $postvault = $vaultfactory->get_post_vault(); + $posts = $postvault->get_from_filters($USER, $filters, $capabilitymanager->can_view_any_private_reply($USER)); + } else { + $posts = []; + } $striphtml = !empty($data->striphtml); $humandates = !empty($data->humandates);