From 9db81597b24a3d269db12637e51abe74c86af708 Mon Sep 17 00:00:00 2001 From: albertlast Date: Sun, 9 Aug 2026 23:27:07 +0200 Subject: [PATCH] Loads the SplitTopics template for the page that needs it The ternary was inverted, so every HTML request got the Xml template and the ask/select sub-templates were never there - clicking Split Topic under a post answered "Unable to load the ask sub-template". Two more faults sat behind that one, which is why they went unnoticed: - num_messages comes back from COUNT(*) as a string and messages_per_page comes from modSettings, so PageIndex's typed int parameters rejected both and the select-posts screen was a 500. - $split2_first_msg and $split2_last_msg were never initialised. The second query returns nothing when the messages have already moved, which is what a resubmitted split looks like, and getMsgMemberID() then got null. That is exactly the case the sanity check below it was written to catch, so start them at 0 and let it. Signed-off-by: Mathias Papenbrock Signed-off-by: albertlast --- Sources/Actions/TopicSplit.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Sources/Actions/TopicSplit.php b/Sources/Actions/TopicSplit.php index 287e23b7c0e..35cb9337789 100644 --- a/Sources/Actions/TopicSplit.php +++ b/Sources/Actions/TopicSplit.php @@ -111,7 +111,7 @@ public function execute(): void User::$me->isAllowedTo('split_any'); // Load up the "dependencies" - the template and getMsgMemberID(). - Theme::loadTemplate(!isset($_REQUEST['xml']) ? 'Xml' : 'SplitTopics'); + Theme::loadTemplate(isset($_REQUEST['xml']) ? 'Xml' : 'SplitTopics'); $call = \is_string(self::$subactions[$this->subaction]) && method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); @@ -299,7 +299,7 @@ public function select(): void Utils::$context['sub_template'] = isset($_REQUEST['xml']) ? 'split' : 'select'; // Are we using a custom messages per page? - Utils::$context['messages_per_page'] = empty(Config::$modSettings['disableCustomPerPage']) && !empty(Theme::$current->options['messages_per_page']) ? Theme::$current->options['messages_per_page'] : Config::$modSettings['defaultMaxMessages']; + Utils::$context['messages_per_page'] = (int) (empty(Config::$modSettings['disableCustomPerPage']) && !empty(Theme::$current->options['messages_per_page']) ? Theme::$current->options['messages_per_page'] : Config::$modSettings['defaultMaxMessages']); // Get the message ID's from before the move. if (isset($_REQUEST['xml'])) { @@ -412,7 +412,7 @@ public function select(): void ); while ($row = Db::$db->fetch_assoc($request)) { - Utils::$context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = $row['num_messages']; + Utils::$context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = (int) $row['num_messages']; } Db::$db->free_result($request); @@ -648,8 +648,8 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st ErrorHandler::fatalLang('selected_all_posts', false); } - $split1_first_msg = null; - $split1_last_msg = null; + $split1_first_msg = 0; + $split1_last_msg = 0; while ($row = Db::$db->fetch_assoc($request)) { // Get the right first and last message dependent on approved state... @@ -697,6 +697,13 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st ], ); + // Nothing comes back if the messages have already been moved elsewhere, + // which is what a resubmitted split looks like. Start these at 0 so the + // sanity check below is what answers that, rather than the two + // getMsgMemberID() calls that come before it. + $split2_first_msg = 0; + $split2_last_msg = 0; + while ($row = Db::$db->fetch_assoc($request)) { // As before get the right first and last message dependent on approved state... if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) {