Skip to content
Snippets Groups Projects

Issue #3486188: [Regression] Clean up temporary files created by XML data parser plugin

1 file
+ 24
5
Compare changes
  • Side-by-side
  • Inline
@@ -87,6 +87,13 @@ class Xml extends DataParserPluginBase implements ContainerFactoryPluginInterfac
*/
protected bool $prefixedName = FALSE;
/**
* The temporary file name of the XML, or FALSE.
*
* @var string|false
*/
protected $temporaryFileName = FALSE;
/**
* Constructs a new XML data parser.
*
@@ -137,6 +144,16 @@ class Xml extends DataParserPluginBase implements ContainerFactoryPluginInterfac
}
}
/**
* Destructs an XML data parser.
*/
public function __destruct() {
if ($this->temporaryFileName !== FALSE) {
$this->fileSystem->unlink($this->temporaryFileName);
$this->temporaryFileName = FALSE;
}
}
/**
* {@inheritdoc}
*/
@@ -200,10 +217,12 @@ class Xml extends DataParserPluginBase implements ContainerFactoryPluginInterfac
$this->reader->close();
// Fetch the data and save it to a temporary file.
$xml_data = $this->getDataFetcherPlugin()->getResponseContent($url);
$url = $this->fileSystem->tempnam('temporary://', 'file');
if (file_put_contents($url, $xml_data) === FALSE) {
throw new MigrateException('Unable to save temporary XML');
if (!$this->temporaryFileName) {
$xml_data = $this->getDataFetcherPlugin()->getResponseContent($url);
$this->temporaryFileName = $this->fileSystem->tempnam('temporary://', 'file');
if (!$this->temporaryFileName || file_put_contents($this->temporaryFileName, $xml_data) === FALSE) {
throw new MigrateException('Unable to save temporary XML');
}
}
// Clear XML error buffer. Other Drupal code that executed during the
@@ -212,7 +231,7 @@ class Xml extends DataParserPluginBase implements ContainerFactoryPluginInterfac
// that occur from attempting to load the XML string into an object here.
libxml_clear_errors();
return $this->reader->open($url, NULL, \LIBXML_NOWARNING);
return $this->reader->open($this->temporaryFileName, NULL, \LIBXML_NOWARNING);
}
/**
Loading