Fixed IPB 40x - Invalid argument supplied for foreach() - moderators

Jake Bunce

Well-known member
Server Error

Invalid argument supplied for foreach()

XenForo_Application::handlePhpError() in XenForo/Importer/IPBoard40x.php at line 1251
XenForo_Importer_IPBoard40x->stepModerators() in XenForo/Importer/Abstract.php at line 97
XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 189
XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 241
XenForo_ControllerAdmin_Import->_startStep() in XenForo/ControllerAdmin/Import.php at line 184
XenForo_ControllerAdmin_Import->actionStartStep() in XenForo/FrontController.php at line 351
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /var/www/vhosts/ugm.org.uk/httpdocs/admin.php at line 13

And this is what I have in core_moderators.perms:

Code:
{"can_manage_sidebar":false,"can_use_ip_tools":false,"can_edit_member_status":true,"can_hide_member_status":true,"can_unhide_member_status":true,"can_view_hidden_member_status":true,"can_lock_member_status":true,"can_unlock_member_status":true,"can_reply_to_locked_member_status":true,"can_delete_member_status":true,"can_edit_status_reply":true,"can_hide_status_reply":true,"can_unhide_status_reply":true,"can_view_hidden_status_reply":true,"can_delete_status_reply":true,"forums":0,"can_pin_topic":true,"can_unpin_topic":true,"can_feature_topic":true,"can_unfeature_topic":true,"can_edit_topic":true,"can_hide_topic":true,"can_unhide_topic":true,"can_view_hidden_topic":true,"can_move_topic":true,"can_lock_topic":true,"can_unlock_topic":true,"can_reply_to_locked_topic":true,"can_delete_topic":true,"can_split_merge_topic":true,"can_edit_post":true,"can_hide_post":true,"can_unhide_post":true,"can_view_hidden_post":true,"can_delete_post":true,"can_read_all_topics":true,"calendar_calendars":0,"can_feature_calendar_event":true,"can_unfeature_calendar_event":true,"can_edit_calendar_event":true,"can_hide_calendar_event":true,"can_unhide_calendar_event":true,"can_view_hidden_calendar_event":true,"can_move_calendar_event":true,"can_lock_calendar_event":true,"can_unlock_calendar_event":true,"can_reply_to_locked_calendar_event":true,"can_delete_calendar_event":true,"can_edit_calendar_event_comment":true,"can_hide_calendar_event_comment":true,"can_unhide_calendar_event_comment":true,"can_view_hidden_calendar_event_comment":true,"can_delete_calendar_event_comment":true,"can_edit_calendar_event_review":true,"can_hide_calendar_event_review":true,"can_unhide_calendar_event_review":true,"can_view_hidden_calendar_event_review":true,"can_delete_calendar_event_review":true,"download_categories":0,"can_pin_downloads_file":true,"can_unpin_downloads_file":true,"can_feature_downloads_file":true,"can_unfeature_downloads_file":true,"can_edit_downloads_file":true,"can_hide_downloads_file":true,"can_unhide_downloads_file":true,"can_view_hidden_downloads_file":true,"can_move_downloads_file":true,"can_lock_downloads_file":true,"can_unlock_downloads_file":true,"can_reply_to_locked_downloads_file":true,"can_delete_downloads_file":true,"can_edit_downloads_file_comment":true,"can_hide_downloads_file_comment":true,"can_unhide_downloads_file_comment":true,"can_view_hidden_downloads_file_comment":true,"can_delete_downloads_file_comment":true,"can_edit_downloads_file_review":true,"can_hide_downloads_file_review":true,"can_unhide_downloads_file_review":true,"can_view_hidden_downloads_file_review":true,"can_delete_downloads_file_review":true,"gallery_categories":0,"can_pin_gallery_image":true,"can_unpin_gallery_image":true,"can_feature_gallery_image":true,"can_unfeature_gallery_image":true,"can_edit_gallery_image":true,"can_hide_gallery_image":true,"can_unhide_gallery_image":true,"can_view_hidden_gallery_image":true,"can_move_gallery_image":true,"can_lock_gallery_image":true,"can_unlock_gallery_image":true,"can_reply_to_locked_gallery_image":true,"can_delete_gallery_image":true,"can_edit_gallery_image_comment":true,"can_hide_gallery_image_comment":true,"can_unhide_gallery_image_comment":true,"can_view_hidden_gallery_image_comment":true,"can_delete_gallery_image_comment":true,"can_edit_product_reviews":true,"can_hide_product_reviews":true,"can_unhide_product_reviews":true,"can_view_hidden_product_reviews":true,"can_delete_product_reviews":true,"can_see_emails":true,"can_flag_as_spammer":true,"can_modify_profiles":true,"can_pin_content":true,"can_unpin_content":true,"can_feature_content":true,"can_unfeature_content":true,"can_edit_content":true,"can_hide_content":true,"can_unhide_content":true,"can_view_hidden_content":true,"can_future_publish_content":true,"can_view_future_content":true,"can_move_content":true,"can_lock_content":true,"can_unlock_content":true,"can_reply_to_locked_content":true,"can_delete_content":true,"can_split_merge_content":true,"can_view_moderation_log":true,"can_view_reports":true,"can_manage_announcements":true,"can_see_poll_voters":true,"can_edit_poll_votes":true,"mod_see_warn":true,"mod_can_warn":true,"mod_revoke_warn":true,"warning_custom_noaction":true,"warnings_enable_other":true,"warn_mod_day":-1}

It's not handling the data correctly, or this data is a different case.

Unfortunately I don't have the exact version of IPB because it was hosted and I no longer have access. The backup is all encoded PHP files and I am not aware of IPB storing its version in the database.
 
As far as I can tell, this is suggesting there's a moderator that could well be a super moderator, but also is a forum specific moderator, but if he's a forum specific moderator then he isn't actually assigned to moderate any forums - it's 0, rather than being an array of forum IDs.

With that in mind, it should just be a case of replacing this:
PHP:
$forumPerms = $this->_calculateModeratorPermissions($moderator);

foreach ($forumIds AS $forumId)
{
   $newNodeId = $this->_mapLookUp($nodeMap, $forumId);
   if (!$newNodeId)
   {
      continue;
   }

   $mod = array(
      'content_id' => $newNodeId,
      'user_id' => $newUserId,
      'moderator_permissions' => array('forum' => $forumPerms['forum'])
   );

   $model->importNodeModerator($forumId, $newUserId, $mod);

   $total++;
}

With:
PHP:
if ($forumIds && is_array($forumIds))
{
   $forumPerms = $this->_calculateModeratorPermissions($moderator);

   foreach ($forumIds AS $forumId)
   {
      $newNodeId = $this->_mapLookUp($nodeMap, $forumId);
      if (!$newNodeId)
      {
         continue;
      }

      $mod = array(
         'content_id' => $newNodeId,
         'user_id' => $newUserId,
         'moderator_permissions' => array('forum' => $forumPerms['forum'])
      );

      $model->importNodeModerator($forumId, $newUserId, $mod);

      $total++;
   }
}
else
{
   if (!$superMod)
   {
      continue;
   }
}
So we bail out of the forum specific stuff if there are no forums, and further bail out and skip that moderator completely if they are also not a super moderator.

Let me know if that helps.
 
Top Bottom