Skip to content

Commit 2aeff27

Browse files
committed
Work on #463: added shutdown hook script to provide option of using XML instead of CSV as Migrate Plus input.
1 parent 0371cae commit 2aeff27

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Shutdown hook script for MIK that combines all the XML files
5+
* in an output directory into one big XML file. Useful for preparing
6+
* content for importing in Drupal 8 using Migrate Plus.
7+
*/
8+
9+
$config_path = trim($argv[1]);
10+
$config = parse_ini_file($config_path, TRUE);
11+
$temp_dir = $config['FETCHER']['temp_directory'];
12+
13+
$wrapper_element_name = 'migrate_plus_source';
14+
15+
$dir = $config['WRITER']['output_directory'];
16+
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
17+
$xml_files = glob($dir . '/*.xml');
18+
19+
$output_file_path_temp = $dir . '/metadata.temp';
20+
$output_file_path = $dir . '/metadata.xml';
21+
22+
file_put_contents($output_file_path_temp, '<?xml version="1.0"?>' . "\n" .'<' . $wrapper_element_name . '>' . "\n");
23+
24+
foreach ($xml_files as $xml_file_path) {
25+
$dom = new DOMDocument();
26+
$dom->preserveWhiteSpace = false;
27+
$dom->load($xml_file_path);
28+
$dom->formatOutput = true;
29+
$xml_file_content = $dom->saveXML($dom->documentElement);
30+
file_put_contents($output_file_path_temp, $xml_file_content . "\n", FILE_APPEND);
31+
unlink($xml_file_path);
32+
}
33+
34+
file_put_contents($output_file_path_temp, '</' . $wrapper_element_name . '>', FILE_APPEND);
35+
rename($output_file_path_temp, $output_file_path);

0 commit comments

Comments
 (0)