Using Import/Export feature from a theme / frontend?

Anyone previously ported the existing Import/Export feature from a theme / frontend (therefore from a component)?

Hi @chris

This could help.

Importing with PHP

Use the importFile method process an import manually from a local file stored on the disk.

$importModel = new MyImportClass;

$importModel->file_format = 'json';

$importModel->importFile('/path/to/import/file.json');

If the file is coming from an uploaded file use the Input facade to access the local path.

$importModel->importFile(
    Input::file('file')->getRealPath()
);

Exporting with PHP

Use the exportDownload method to process an export manually and return a download response.

$exportColumns = ['id', 'title'];

$exportModel = new MyExportClass;

$exportModel->file_format = 'json';

return $exportModel->exportDownload('myexportfile.json', ['columns' => $exportColumns]);

digging an old thread :crazy_face: )

I am trying to export with PHP as per the documentation from a backend list but nothing happens.
i checked that it goes inside the code as expected but it is as if the return response:download does not happen at all. Any idea @daft please?

public function onExport()
    {
        $exportColumns = ['id', 'name'];
        $exportModel = new CourseExport;
        $exportModel->file_format = 'json';
        return $exportModel->exportDownload('courses.json', ['columns' => $exportColumns]);
    }

EDIT: I found a file in storage/temp/export/ that looks like my export with a strange name oc6594387be6f37xjson with no extension