diff --git a/Sources/Actions/TopicSplit.php b/Sources/Actions/TopicSplit.php index 287e23b7c0..35cb933778 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) {