Problem importing/updating Tailor records

I’m having trouble importing Tailor records on one site while it’s perfectly OK on another.

Maybe someone can help me out.

  1. Site one - (clean) OC 3.7 install, demo theme, multisite with 3 sites.

Exported data from demo Blog blueprint.

Imported/updated the same data with no problem (checked “Update existing records”).

  1. Site two, OC3.7 install, custom theme, multisite with 3 sites.

Duplicate of Blog blueprint from site 1 (the same that comes with Demo theme).

Exported data from demo Blog blueprint.

Importing the same data throw a notice Record ID already exists even with “Update existing records” checkbox checked


I went through code to find why and found this:

In file modules/backend/behaviors/importexportcontroller/ActionImport.php there is a method to bind ImportOptions from request to model on line 42:

if ($optionData = post('ImportOptions')) {
            $model->fill($optionData);
        }

This works perfectly on site 1 and Tailor\Models\RecordImport has an attribute update_existing set and so it updates imported records.

But on site 2 this doesn’t work and attribute update_existing is not added to the RecordImport model and this ends with notice Record ID already exists.

The only way I was able to fix this on site 2 was to change method $model->fill($optionData) to $model->forceFill($optionData) in ActionImport.php or to add fillable['update_existing'] attribute to RecordImport.php model.

Tailor’s RecordImport doesn’t have attribute fillable (not even parent ImportModel) so this make sense, but how is this working on site 1 but not on site 2?

Both sites has identical environment (Valet with PHP8.2, OC3.7.11) and identical Blog Posts blueprints from Demo theme.

Does anyone have any experience with this?

Yes. I’ve the same problem the “update existing records” checkbox does nothing. I’m using october 4.2 right now.

Thanks for reporting, confirmed bug. The import model gets blueprint content fields appended to its $fillable array at runtime, which flips Eloquent out of “everything is fillable” mode and silently drops the update_existing option from the posted form data.

Fix landing in v4.2.22. In the meantime you can patch it locally by adding this to modules/backend/models/ImportModel.php:

public function isFillable($key)
{
    return true;
}

That restores the intended behaviour, update_existing (and any other import options) will mass-assign correctly regardless of which blueprint is being imported.

Hi @daftspunk and thank you but this doesn’t work for Tailor data.

There must be also a fillableFromArray() method added into modules/backend/models/ImportModel.php:

    /**
     * fillableFromArray bypasses the strict fillable filter. Once a subclass
     * (e.g. Tailor's RecordImport) appends blueprint content fields to $fillable,
     * Laravel's array_intersect_key() drops every key not in $fillable BEFORE
     * isFillable() is ever consulted — silently discarding import options such as
     * update_existing. Import models are transient containers for arbitrary
     * user-supplied options and data, so no attribute should be filtered out.
     */
    protected function fillableFromArray(array $attributes)
    {
        return $attributes;
    }

Thanks @jan-vince

I think at this point it might just be easier to make the attribute fillable


/**
 * @var array fillable attributes for mass assignment
 */
protected $fillable = ['update_existing'];
1 Like