Fixed [E_NOTICE] Trying to access array offset on value of type null src/XF/Import/Importer/StepPostsTrait.php:120

Fajfie

Member
Affected version
2.2.7
Discourse post import error. It cause infinite loop.

Code:
[E_NOTICE] Trying to access array offset on value of type null
src/XF/Import/Importer/StepPostsTrait.php:120

Code:
#0 src/XF/Import/Importer/StepPostsTrait.php(120): XF::handlePhpError(8, '[E_NOTICE] Tryi...', '/var/www/vhosts...', 120, Array)
#1 src/XF/Import/Runner.php(244): XFI\Import\Importer\Discourse->stepPosts(Object(XF\Import\StepState), Array, 8)
#2 src/XF/Import/Runner.php(61): XF\Import\Runner->runStep('posts', Object(XF\Import\StepState), 8)
#3 src/XF/Admin/Controller/Import.php(234): XF\Import\Runner->run()
#4 src/XF/Mvc/Dispatcher.php(352): XF\Admin\Controller\Import->actionRun(Object(XF\Mvc\ParameterBag))
#5 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XF:Import', 'Run', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Import), NULL)
#6 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Import), NULL)
#7 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#8 src/XF/App.php(2345): XF\Mvc\Dispatcher->run()
#9 src/XF.php(512): XF\App->run()
#10 admin.php(13): XF::runApp('XF\\Admin\\App')
#11 {main}

Code:
array(4) {
  ["url"] => string(21) "/admin.php?import/run"
  ["referrer"] => string(46) "XXX/admin.php?import/run"
  ["_GET"] => array(1) {
    ["import/run"] => string(0) ""
  }
  ["_POST"] => array(1) {
    ["_xfToken"] => string(8) "********"
  }
}


Code:
[E_NOTICE] Undefined offset: 1
src/XF/Import/Importer/StepPostsTrait.php:120

Code:
#0 src/XF/Import/Importer/StepPostsTrait.php(120): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/var/www/vhosts...', 120, Array)
#1 src/XF/Import/Runner.php(244): XFI\Import\Importer\Discourse->stepPosts(Object(XF\Import\StepState), Array, 8)
#2 src/XF/Import/Runner.php(61): XF\Import\Runner->runStep('posts', Object(XF\Import\StepState), 8)
#3 src/XF/Admin/Controller/Import.php(234): XF\Import\Runner->run()
#4 src/XF/Mvc/Dispatcher.php(352): XF\Admin\Controller\Import->actionRun(Object(XF\Mvc\ParameterBag))
#5 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XF:Import', 'Run', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Import), NULL)
#6 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Import), NULL)
#7 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#8 src/XF/App.php(2345): XF\Mvc\Dispatcher->run()
#9 src/XF.php(512): XF\App->run()
#10 admin.php(13): XF::runApp('XF\\Admin\\App')
#11 {main}

Code:
array(4) {
  ["url"] => string(21) "/admin.php?import/run"
  ["referrer"] => string(46) "https://anim1.bearhost.pl/admin.php?import/run"
  ["_GET"] => array(1) {
    ["import/run"] => string(0) ""
  }
  ["_POST"] => array(1) {
    ["_xfToken"] => string(8) "********"
  }
}

Zrzut ekranu 2021-09-17 o 21.33.53.webp
 
Can you try this and let me know if it resolves this issue for you?

Diff:
diff --git a/src/addons/XFI/Import/Importer/Discourse.php b/src/addons/XFI/Import/Importer/Discourse.php
index 81de43269c..8f52406467 100644
--- a/src/addons/XFI/Import/Importer/Discourse.php
+++ b/src/addons/XFI/Import/Importer/Discourse.php
@@ -2106,7 +2106,7 @@ protected function getPostsForPostsStep($threadId, $startDate): array
 			$startDate = \DateTime::createFromFormat('U', $startDate)->format('Y-m-d H:i:s.u');
 		}
 
-		return $this->sourceDb->fetchAllKeyed(
+		return $this->sourceDb->fetchAll(
 			"SELECT posts.*,
 					users.username,
 					deleted_by_users.username AS deleted_by_username,
@@ -2124,7 +2124,6 @@ protected function getPostsForPostsStep($threadId, $startDate): array
 					AND posts.post_type = 1
 				ORDER BY posts.created_at, posts.id
 				LIMIT {$limit}",
-			'id',
 			[$threadId, $startDate]
 		);
 	}
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XFI release (1.5.2).

Change log:
Properly index the source posts array for Discourse posts
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom