[Regression] Clean up temporary files created by XML data parser plugin

Created on 7 November 2024, 2 months ago

Problem/Motivation

This is a regression that has been introduced in XML parser ignores the data-fetcher plugin Needs work .

The XML data parser plugin gets the XML contents from the data fetcher plugin and then writes these contents to a temporary file, which is then used by the XML reader. The temporary file is created using \Drupal\Core\File\FileSystem::tempnam(), which in turn uses PHP's tempnam(). The temporary files are never deleted by the plugin, resulting in a lot of stray files in temporary directories.

Note: Unlike files created using tmpfile(), which are deleted by PHP automatically at some point, files created using tempnam() are not and have to be deleted by the implementing code.

Steps to reproduce

  1. Set up a migration using the XML data parser plugin.
  2. Verify that your temporary directory contains no files starting with file.
  3. Run the migration, e.g. using drush mim.
  4. Wait until the migration is complete.
  5. Verify that your temporary directory contains files starting with file that contain the contents of the XML file used for import. This should be at least one file, but may be more, e.g. if you performed a rollback first.

Sample source config using http data fetcher, file data fetcher works as well:

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls: 'https://updates.drupal.org/release-history/drupal/current'
  item_selector: '/project/releases/release'

Proposed resolution

Delete the file on destruction of the plugin. Or maybe there is a better way using the API, although I didn't see it?

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

6.0

Component

Plugins

Created by

🇩🇪Germany FeyP

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024