Import CSV programmatically (from code), not the GUI

Created on 24 November 2020, about 4 years ago
Updated 7 June 2024, 7 months ago

Problem/Motivation

In some cases, such as if you have file_entity enabled on your site and you have hundreds of thousands of files (making it impractical to temporarily disable file_entity to import a csv -- see #3166609: Add a note on the home page of the project stating incompatibility with file_entity ); or during a Jenkins process or other situation where you don't want to use the graphical user interface (GUI), you might find yourself wanting to import a CSV file in code.

Steps to reproduce

Currently you need to log in and click in GUI to import a CSV.

Proposed resolution

Decouple the GUI from the API code.

Remaining tasks

Test patch.

User interface changes

None. The GUI in the Drupal\csv_importer\Form\ImporterForm should no longer perform any business logic, but rather call some code to import CSV. The same operation should be done from the command line.

API changes

It should be possible to import some CSV using:

drush ev "\Drupal::service('plugin.manager.importer')->import('node', 'article', '/full/path/to/my/csv/file.csv', ',', 'node_importer');"

Data model changes

For files imported through the GUI, file entities are created, and left over after the import until the temporary files are deleted. For files imported programmatically, no file entities are created.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇨🇦Canada alberto56

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024