Category: Teknograd

DC-X batch import

Batch importing stuff to DC-X often consists of these two steps.

  1. Creating DC-XML files containing metadata to populate document.
  2. Batch importing the DC-xml files and original files.

1. Creating DC-XML

This process is not mandatory. For example image files often contain lots of metadata in EXIF, IPTC or XMP inside the file itself. This information is pulled into DC-X on import so no need to create a sidecar file. But if the filename contains publication information or other relevant information it could be a good idea to build a sidecar file.
For newspaper migrations we often see that publication information is part of the filename and for product related import we often see product id in the filename.

The below PHP file is an example of a newspaper migration file which pulls publication information from the filename and creates a DC-XML sidecar file. It scans the the folder defined on row 12 under the path defined in row 9. As you see in this case we disregard lots of different filetypes (see row 21). The reason for this is so that we don’t need to clean up all folders and subfolders prior to running the migration. This is pretty useful as migrations tend to include really large amounts of files.

The script dig down a couple of levels of folders (see row 26 and row 34) and this is obviously something you need to change in accordance with your folder structure.

On row 52 you see the function buildXML. This function builds the actual XML files. I’d recommend that you limit the first tests by removing the // (rem) on line 28. This so you can test and validate the XML manually. I recommend that you use xmllint –format for this.

Take the above code and save it in your data folder under the name create_xml.php. When you’ve done editing the file to conform to your data it’s time to run it. If you look into the created XML files you’ll notice how we point at the sidecar parent file on line 108 (local_path tag).

The script will create xml files at the same level as your original files (in this case PDF files). To prepare for the next step we need to create a file that points to all the XML files. The following steps finds the XML files and put the path of all XML files into a text file.

2. Import files

Time for batch import. If you don’t have any sidecar files this is pretty straight forward.

Copy the code below and save the file (filename: onto your DC-X system in the folder where you have your data.

In the above file we do some post processing. The main action is the actual import done in line 23. You can take this row and run it manually in shell/consol to import a single file. But the mentioned post processing happens on row 35 and 38. On row 35 we render a preview of the PDF file and on row 38 we ask DC-X to try to pull any text included inside the PDF file. The above post handling is not needed for images.

If you don’t have sidecar files you still need to have a text file which points to the files you want to import. Basically you can add a couple of files manually to a text file. Just add the path to the file and the filename to import, one file per line.

The script will spit out the created documents doc-id. So it’s pretty easy to find the newly created document inside DC-X to make sure everything looks ok.


The PHP script above is pretty specific and works only for a couple of scenarios. But the structure gives you an idea on how to build DC-XML sidecar files.
I really encourage you to approach this in a trail and error mindset. Go through each step, test, make change and try again. On the last step import maybe 10-20 files and let someone else look at the imported files in DC-X. If it’s a migration let someone who knows the old system and the data imported to have a look at the “new” data in DC-X.
All this to make sure you don’t import a million documents and find out you missed something important which forces you to post process on a production system or reimport the entire dataset.