Problem/Motivation
The core migrate system needs a way to import things from CSV files.
Immediate use case is for the Umami Demo profile now in core in 8.6.x. The imported content is in CSV files and we have code to read it and create the relevant entries. Having migrate_source_csv in core would allow us to remove that code and use migrate instead.
See #2809635-37: Create experimental installation profile for where @larowlan suggested bring migrate_source_csv into core.
Other good reasons to have CSV as a migration source in core:
- "I use this constantly. I've seen it forked into the Contenta distro, and a few of my own projects (I just want the source plugin, not another module.) It'll also be vital to Commerce integrations as CSV is a common way to import data from an ERP." @mglaman (#4)
- "CSV format is the first format used by non technical professionnals who need to import data and to generate/edit those datas thanks to software they knew (MS Excel without mention it). It's also the easiest way to export data from many ERP and big solutions with datas." @GoZ (#5)
- "CSV is simply a really common used format and it would make migrate more usable by default for many usecases. One could say: Oh it is easy to parse CSV, but it turns out it is not. On top of that the module also doesn't load the entire CSV file upfront, but rather reads line by line. I think this makes it a good candidate also for bigger migrations out there." @dawehner (#14)
- "This would help the Out of the Box Initiative. Let's do it! Consider this my maintainer +1 :)" @phenaproxima (#18)
Proposed resolution
The migrate_source_csv module has a stable release (2.0), has been downloaded almost 100k times, and comes complete with tests. The contenta CMS has been using this for their migrations, too.
Rename the files/namespaces, and move it in, as-is, to the core migrate module.
Since this is a straight port from contrib, discussions about fetchers, etc. are postponed to follow-ups. See #16, #36 and #37 for some of the highlights of the discussion.
Follow-up: #2962091: Adopt fetchers/parsers logic for use by source csv plugin
Remaining tasks
Patch that renames files/namespaces and moves the contrib code into core Done.Tests Done.Word-smithing PHPDocs Done.Decide if we're okay with a straight port (done), or if we need to hash out all the fetcher/parser stuff first, figure out the design, class names, avoid conflicts, possible BC hell, etc. Done. See comments #80 through #83. Punted to #2962091: Adopt fetchers/parsers logic for use by source csv plugin.- Finish cleaning up the docs and tests.
None.
User interface changes
None.
API changes
Adds a new migrate source plugin called "csv" in migration yml definition files. The class providing the plugin (\Drupal\migrate\Plugin\migrate\source\CSV) is heavily commented with PHPDoc.
Adds a \Drupal\migrate\CSVFileObject class (which extends \SplFileObject).
Existing users of this plugin from contrib are unharmed. The name is the same, but we haven't changed anything about how it works. Contrib users simply disable migrate_source_csv module before upgrading to core 8.X.Y and none of their migration files have to be changed to continue working.
Data model changes
None.
Original report by @smaz
In #2809635: Create experimental installation profile, we are using CSV files to provide default content for a demo installation profile of Drupal.
In a review, @larowlan suggested bringing the CSV migration sources into core:
https://www.drupal.org/project/drupal/issues/2809635#comment-12381619
I agree that a CSV migrate source would be a very useful feature for core.
The migrate_source_csv module has a stable release (2.0), has been downloaded almost 100k times (not sure if that includes composer stats?), and comes complete with tests. The contenta CMS has been using this for their migrations, too.
So would it be ok to look at moving this into Core's migrate module? If so, I'm happy to try and turn the module into a patch.