Lesson 3.2: Importing with xrowextract: dry runs and repeatable imports
xrowextract is the most complete importer Exponential has. This lesson teaches the way of working the tools page
recommends: export one sample of the target class to get the format right, convert the source into that format, and
always run a dry run before --apply. Learners also see why the same file can be imported twice without creating
duplicates.
Note
Use a training installation, never a live site. The importer writes nothing without --apply; in this lesson
learners apply only once, to their own course folder.
At a glance
| Course | Migrating to Exponential |
| Module | Module 3: Import and export tools |
| Duration | 60 minutes (15 presenting, 45 exercise) |
| Level | Intermediate |
| Audience | Developers and administrators |
| Prerequisites | Lesson 3.1; a course folder of their own on the training installation and its node id |
Learning objectives
After this lesson, learners can:
- export a sample of a class with the migration column set to learn the file format;
- run an import as a dry run and read its report;
- explain the three values of
--matchand what each does on a second run; - apply an import into a given parent node and check the result in the admin.
Trainer's notes
How to present it
Source: Exponential's import and export tools, xrowextract.
- The format comes from an export (4 minutes). The easiest way to get the format right is to export one sample
object of the target class and copy its columns. Every export carries a typed column manifest
(
<file>.manifest.json), so a file with a manifest maps back exactly. - Dry run first (3 minutes). Nothing is written without
--apply. Show the dry run's report on the projector. - Matching (5 minutes). The importer's own help:
--matchisremote_id(the default, when the file has a remote id column),object_id, ornone(always create). With the default, a second run of the same file updates the same objects. That is the "repeatable import" of the checklist. - Foreign files (3 minutes). A file from another system maps its columns with
--map=column=attribute,.... Large files run with--backgroundand resume with--resume-from.
Common questions
Can editors import in the admin? Yes: the node view's Import/Export button, Import into this item, runs the same importer (tools page). Check the button on your own installation before you show it.
What about images? Image and file columns name files; copy the storage or the source's files with the export.
Does the import respect permissions? The tools page says it checks the user's permissions.
Pitfalls
--match=nonewith--applyon a file that was already imported. That creates duplicates. Learners usenoneonly in a dry run in this lesson.- Wrong parent node. Learners write their course folder's node id on paper before they start.
- Editing the CSV in a spreadsheet program that changes the separator or the encoding. Use a plain text editor for the exercise.
Hands-on exercise
Use your own training installation, with a course folder that holds at least one article (from an earlier course,
or create one in the admin). Work in var/tmp/import/ below the installation root.
Note the node id of your course folder (shown on its page in the admin). Below it is called
<folder>.Create the working directory:
mkdir -p var/tmp/importExport the articles below your folder with the migration column set:
php bin/php/console ext:xrowextract:csv --class=article --node=<folder> --sets=migration --output=var/tmp/import/articles.csvLook at the file and its manifest:
head -3 var/tmp/import/articles.csv ls var/tmp/import/Run the import of the same file as a dry run:
php bin/php/console ext:xrowextract:import --file=var/tmp/import/articles.csv --class=article --parent=<folder>Read the report: how many rows would be created, how many updated?
Run the same dry run with
--match=noneadded. Compare the report.In
articles.csv, change the title of one article in a text editor (keep the remote id as it is). Save.Apply the import with the default matching:
php bin/php/console ext:xrowextract:import --file=var/tmp/import/articles.csv --class=article --parent=<folder> --applyIn the admin, open your folder. Check the title you changed and the number of articles.
Open the article's Manage versions page (or its version history) and note the new version.
Expected result
- Step 3 wrote
articles.csv; step 4 shows a header with the migration columns and a.manifest.jsonnext to the file. - Step 5: the dry run reports updates for the existing articles (matched by remote id) and writes nothing.
- Step 6: with
--match=nonethe dry run reports creates for every row. - After step 8 the folder holds the same number of articles as before; the changed article shows the new title as a new version.
- The trainer checks one learner's folder: no duplicates, one changed title.
Quiz
- What does the importer do when you leave out
--apply? - Which
--matchvalue always creates new objects? A.remote_idB.object_idC.noneD.apply - Why export one sample object of the target class before converting a foreign file?
- What does the manifest file next to an export contain?
- A file with 400 000 rows stopped at row 40 000. Which option continues the import?
Answers
- It runs a dry run and writes nothing (tools page, xrowextract).
- C.
nonealways creates;remote_idis the default when the file has a remote id column (the importer's help text,extension/xrowextract/bin/php/import.php). - Its columns show exactly the format the importer expects (tools page, xrowextract).
- A typed column manifest: per column its datatype, format, language and import target (tools page, xrowextract).
--resume-from=40001(with--apply, and--backgroundfor a large file) (tools page, xrowextract).
Further reading
- Exponential's import and export tools: xrowextract import, export and packages.
- The common migration checklist, section 6: what a repeatable import is.
- Publishing, versions and the trash: what a new version means for editors.
Related pages
- Module 3: Import and export tools
- Migrating to Exponential: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.