Improve handling of mis-named import runner step


Well-known member
Affected version
2.2.6 PL2
Just sunk a chunk of time debugging an issue with an importer where the key from the getSteps array was comments but the associated method was called stepPosts instead of stepComments, and it threw this error on the CLI:

Argument 3 passed to XF\Cli\Command\Import::XF\Cli\Command\{closure}() must be an instance of XF\Import\StepState, null given, called in /home/staging/public_html/community/src/XF/Import/Runner.php on line 171

Looking at XF\Import\Runner:

protected function triggerOnTick(\Closure $onTick, $step = null, StepState $stepState = null)
    if ($step === null)
        $step = $this->session->currentStep;
    if ($stepState === null)
        $stepState = $this->session->currentState;

    $onTick($this->session->runComplete, $step, $stepState, $this->getImportCompletionDetails(), $this);

If $stepState is still null, it still gets passed through to the $onTick callback, which then throws the above error.

I don't know if an exception can be thrown at any point here, or maybe from within setupRunnableStep:

if (is_callable([$this->importer, $runMethod]))
    $state = new StepState();
    $state->startDate = time();
    $state->title = $this->getStepTitle($step);

    $stepSetupMethod = 'setupStep' . $step;
    if (is_callable([$this->importer, $stepSetupMethod]))
        $stepConfig = $this->importer->getStepSpecificConfig(

    $stepEndMethod = 'getStepEnd' . $step;
    if (is_callable([$this->importer, $stepEndMethod]))
        $state->end = $this->importer->$stepEndMethod();

    $session->currentStep = $step;
    $session->currentState = $state;

The first is_callable check fails so it never sets $session->currentState so then just fails when it gets to triggerOnTick

Essentially, it's not super clear from the CLI error that it's failing as it has no current state set inside setupRunnableStep, due to the method name not being callable because it's named incorrectly. It looks like a higher level application issue and not something caused by a misspelt method name. Some sort of hint that, in this instance, method stepComments is not callable would have flagged the issue immediately as I'd have realised it was called stepPosts straight away instead of after... much longer 😂
Last edited:
Top Bottom