Undefined variable $importResults

I’m trying to do a import but are getting the same error over and over again.

“Undefined variable $importResults” on line 9 of /srv/www/gfp/public_html/modules/backend/behaviors/importexportcontroller/partials/_import_result_form.php"

My import model looks like this:

class TourImport extends \Backend\Models\ImportModel
    public $rules = [];

    public function importData($results, $sessionKey = null)
        foreach ($results as $row => $data) {

            try {
                $tour = new Tour;
                $tour->name = $data['name'];
                $tour->slug = $data['name'];
                $tour->description = $data['description'];
                $tour->is_published = 1;

            } catch (Exception $ex) {
                $this->logError($row, $ex->getMessage());

I know that the problem happens when saving the model, when $tour->save() is removed the errors disappears but obviously the model isn’t saved.

Hey @adamo

The first place might be to check the error logs.

Then, try changing the \Exception to \Throwable to see if it makes any difference.

This variable is set in the file

  • File: modules/backend/behaviors/importexportcontroller/ActionImport.php
  • Method: actionImport

Called in the file

  • File: modules/backend/behaviors/ImportExportController.php
  • Method: onImport

If this process fails along the way (somehow without setting $this->fatalError) then this missing variable error can happen.

1 Like

OK to this is what has happen. In the tour model the validation rules have been

public $rules = [
        'name' => 'required',
        'slug' => 'required|unique:depcore_tours_tours',
        'description' => 'required',
        'short_description' => 'required',

    public $customMessages = [
        'name.required' => 'The tour name is required.',
        'slug.required' => 'The slug is required.',
        'slug.unique' => 'The slug must be unique.',
        'description.required' => 'The description is required.',
        'short_description.required' => '',

The error was due to having an empty error message for short_description.required. I blame this on copilot :wink:

1 Like

“Copilot” is good as “copilot”. Programmer is always responsible doing the ctrl+s in their code! haha

1 Like

Cant argue with that, a cautionary tale non the less :wink: