Fix pathbuilder export

This commit is contained in:
Tom Wiesing 2022-10-21 19:39:46 +02:00
parent 7a53703aaa
commit 7bedeefb50
No known key found for this signature in database

View file

@ -27,20 +27,25 @@ function one_xml(string $id): string {
// ================================================================================= // =================================================================================
function entity_to_xml($pb) { function entity_to_xml($pathbuilderEntity) {
$xml = new \SimpleXMLElement("<pathbuilderinterface></pathbuilderinterface>"); // NOTE: This function is verbatum copied from wisski_pathbuilder/src/PathbuilderManager.php.
// The original code is licensed GPL-2-or-later, we choose GPL 3.0.
//
// As per section 13 of GPL 3.0, we can reuse it under AGPL-3.0 (which this project is licensed under).
$paths = $pb->getAllPaths(); // Create initial XML tree.
$xmlTree = new \SimpleXMLElement("<pathbuilderinterface></pathbuilderinterface>");
// Get the paths.
$paths = $pathbuilderEntity->getPbPaths();
// Iterate over every path.
foreach ($paths as $key => $path) { foreach ($paths as $key => $path) {
$id = $path->getID(); $pathbuilder = $pathbuilderEntity->getPbPath($path['id']);
$pathChild = $xmlTree->addChild("path");
$path = $pb->getPbPath($id); $pathObject = WisskiPathEntity::load($path['id']);
$pathChild = $xml->addChild("path");
$pathObject = WisskiPathEntity::load($id);
foreach ($path as $subkey => $value) {
foreach ($pathbuilder as $subkey => $value) {
if (in_array($subkey, ['relativepath'])) { if (in_array($subkey, ['relativepath'])) {
continue; continue;
} }
@ -64,14 +69,17 @@ function entity_to_xml($pb) {
$pathChild->addChild('uuid', htmlspecialchars($pathObject->uuid())); $pathChild->addChild('uuid', htmlspecialchars($pathObject->uuid()));
if ($pathObject->getType() == "Group" || $pathObject->getType() == "Smartgroup") { if ($pathObject->getType() == "Group" || $pathObject->getType() == "Smartgroup") {
$pathChild->addChild('is_group', "1"); $pathChild->addChild('is_group', "1");
} else { }
else {
$pathChild->addChild('is_group', "0"); $pathChild->addChild('is_group', "0");
} }
$pathChild->addChild('name', htmlspecialchars($pathObject->getName())); $pathChild->addChild('name', htmlspecialchars($pathObject->getName()));
} }
// turn it into XML // Create XML DOM.
$dom = dom_import_simplexml($xml)->ownerDocument; $dom = dom_import_simplexml($xmlTree)->ownerDocument;
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
return $dom->saveXML(); return $dom->saveXML();
} }