Commit 890666b0 authored by Thomas Löffler's avatar Thomas Löffler

Change importer to handle each object in one XML file

parent 51e16db5
......@@ -42,10 +42,10 @@ class OpenImmoImportService
*/
public function getZipFiles()
{
if (chdir(ConfigurationService::getDataFolder())) {
if (chdir('.Build/Web/uploads/')) {
return glob('*.zip');
} else {
throw new \RuntimeException('Directory ' . ConfigurationService::getDataFolder() . ' does not exist!');
throw new \RuntimeException('Directory .Build/Web/uploads/ does not exist!');
}
}
......@@ -61,12 +61,25 @@ class OpenImmoImportService
if ($res === true) {
$xmlFile = pathinfo($zipFile, PATHINFO_FILENAME) . '.xml';
$xml = @simplexml_load_string($zip->getFromName($xmlFile));
$annoId = (string)$xml->xpath('//openimmo_anid')[0];
if ($annoId) {
if (!@mkdir($annoId) && !is_dir($annoId)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $annoId));
}
if ($zip->extractTo($annoId)) {
$objects = $xml->xpath('//immobilie');
foreach ($objects as $key => $object) {
$objectId = (string)$object->xpath('//openimmo_obid')[$key];
if ($objectId) {
// create folder for object
if (!@mkdir($objectId) && !is_dir($objectId)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $objectId));
}
// save object XML into dir
$object->asXML($objectId . '/' . $objectId . '.xml');
// extract depending files into dir
$attachments = (array)$object->xpath('//anhaenge')[$key];
$files = [];
foreach ($attachments['anhang'] as $attachment) {
$files[] = (string)$attachment->daten->pfad;
}
if ($files) {
$zip->extractTo($objectId, $files);
}
$extracted = true;
}
}
......@@ -88,6 +101,3 @@ class OpenImmoImportService
echo $message;
}
}
$service = new OpenImmoImportService();
$service->import();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment