url = $host . "/ws/services/AssetOperationService?wsdl"; $readAuth = new authentication; $readAuth->username = $uname; $readAuth->password = $pass; $writeClient = new AssetOperationHandlerService(); $writeClient->url = $host2 . "/ws/services/AssetOperationService?wsdl"; $writeAuth = new authentication; $writeAuth->username = $name2; $writeAuth->password = $pass2; /* Parse the XML folder */ add_folder($oldPath); } function parse_xml($file) { global $template_xml; global $tagstack; /* Initialize the tag stack. This will be a stack of the tag * structure we are currently in */ $tagstack = array(); /* Create an XML Parser object */ $xml_parser = xml_parser_create(); /* Turn off case folding on the XML Parser object, this * will ensure that the parser will be case sensitive */ xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); /* Set the callback functions for the XML Parser object. The object * will call these functions when various actions happen */ xml_set_element_handler($xml_parser, "start_element", "end_element"); xml_set_character_data_handler($xml_parser, "character_data"); /* Try to open the XML file */ if (file_exists($file)) { $fp = fopen($file, "r"); } else { die ("Cannot find: " . $file); } /* Read the data a bit at a a time */ while ($data = fread($fp, 4096)) { /* Try to parse that bit */ if (!xml_parse($xml_parser, $data, feof($fp))) { /* Give and error and quit if the parsing fails */ die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } /* Free the parser data */ xml_parser_free($xml_parser); } /* This function will be called by the XML parser when it * finds an opening tag */ function start_element($parser, $name, $attrs) { global $tagstack; global $template_xml; /* Push the current tag name onto our tag stack */ array_unshift($tagstack, $name); /* If we have just entered the context of the path tag, * append a new path to our path array */ /** Use this when using a n-sized array */ if ($name == "path") $template_xml['path'][] = ""; } /* This function will be called by the XML parser when it * finds a closing tag */ function end_element($parser, $name) { global $tagstack; /* We are exiting a tag, so we want to pop it off of our * tag stack */ array_shift($tagstack); } /* This function will be called by the XML parser when it * finds character data between the opening and the closing * of a tag */ function character_data($parser, $data) { /** * If we're not on a real character_data node, run away. This is basically to * ignore all whitespace nodes, because no one likes them anyway */ if (trim($data) == "") { return; } global $tagstack; global $template_xml; /* If we aren't deep enough to be in "template don't do anything */ if (count($tagstack) < 2) return; /** here's where we traverse everything */ switch ($tagstack[count($tagstack) - 1]) { /** If we're on the config file: */ case "system-data-structure": switch ($tagstack[count($tagstack) - 2]) { case "curServer": switch ($tagstack[count($tagstack) - 3]) { case "server": global $host; $host = $data; break; case "username": global $uname; $uname = $data; break; case "password": global $pass; $pass = $data; break; case "path": global $oldPath; $oldPath = $data; break; } break; case "newServer": switch ($tagstack[count($tagstack) - 3]) { case "server": global $host2; $host2 = $data; break; case "username": global $name2; $name2 = $data; break; case "password": global $pass2; $pass2 = $data; break; case "path": global $newPath; $newPath = $data; break; } break; } break ; } } /** * Reads in the folder, pushes its children, makes the folder, then pops remaining children */ function add_folder($loc) { global $oldPath; global $newPath; global $readClient; global $readAuth; global $parentFolderPath; global $writeClient; global $writeAuth; global $folderStack; global $pageStack; global $refStack; global $genericStack; global $templateStack; $id = new identifier; $id->path = $loc; $id->type = "folder"; $readClient->read($readAuth, $id); if ($readClient->success == false) { echo "Failure: " . $readClient->message; } else { $asset = $readClient->asset; $asset->folder->parentFolderPath = getPath($asset->folder->parentFolderPath); if (getPath($asset->folder->parentFolderPath) != "") { checkFolder($asset->folder->parentFolderPath); } // $asset->folder->metadataSetPath = str_replace("Metadata Sets", "", $asset->folder->metadataSetPath); checkMetadataSet($asset->folder->metadataSetPath); $asset->folder->path = ""; $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "\r\n"; echo $writeClient->message; flush(); } $children = $asset->folder->children->child; if (is_array($children)) { while ($cur = array_pop($children)) { if ($cur->type == "folder") { $folderStack[] = $cur; } else if ($cur->type == "page") { $pageStack[] = $cur; } else if ($cur->type == "reference") { $refStack[] = $cur; } else if ($cur->type == "template") { $templateStack[] = $cur; } else { $genericStack[] = $cur; } } } if (is_array($folderStack)) { while ($cur = array_pop($folderStack)) { add_folder($cur->path); } } if (is_array($genericStack)) { while ($cur = array_pop($genericStack)) { add_asset($cur->path, $cur->type); } } if (is_array($templateStack)) { while ($cur = array_pop($templateStack)) { add_asset($cur->path, $cur->type); } } if (is_array($pageStack)) { while ($cur = array_pop($pageStack)) { add_asset($cur->path, $cur->type); } } if (is_array($refStack)) { while ($cur = array_pop($refStack)) { // add_reference($cur->path); } } } } /** * Read in the file, block, symlink, or stylesheet and add it directly */ function add_asset($loc, $type) { global $oldPath; global $newPath; global $readClient; global $readAuth; global $parentFolderPath; global $writeClient; global $writeAuth; global $folderStack; $id = new identifier; $id->path = $loc; $id->type = $type; $readClient->read($readAuth, $id); if ($readClient->success == false) { echo "Read failure: " . $readClient->message; } else { $asset = $readClient->asset; if (!isset($asset->$type)) { if (isset($asset->indexBlock)) { $type = "indexBlock"; } else if (isset($asset->textBlock)) { $type = "textBlock"; } else if (isset($asset->feedBlock)) { $type = "feedBlock"; } else if (isset($asset->xmlBlock)) { $type = "xmlBlock"; } else if (isset($asset->xhtmlBlock)) { $type = "xhtmlBlock"; } } $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath); if (is_string($asset->$type->metadataSetPath)) { checkMetadataSet($asset->$type->metadataSetPath); } if (is_string($asset->$type->structuredData->definitionPath)) { checkDefinition($asset->$type->structuredData->definitionPath); } if (is_string($asset->$type->configurationSetPath)) { checkConfigurationSet($asset->$type->configurationSetPath); } if (is_string($asset->$type->indexedFolderPath)) { $asset->$type->indexedFolderPath = getPath($asset->$type->indexedFolderPath); } if (is_string($asset->$type->expirationFolderPath)) { $asset->$type->expirationFolderPath = getPath($asset->$type->expirationFolderPath); } if (is_string($asset->$type->targetPath)) { checkTarget($asset->$type->targetPath); } if (is_array($asset->$type->pageRegions->pageRegion)) { $regions = $asset->$type->pageRegions->pageRegion; foreach ($regions as &$region) { if ($region->blockPath != "") { $blockPath = $region->blockPath; $region->blockPath = getPath($region->blockPath); if ($blockPath == $region->blockPath) { checkBlock($blockPath); } } if ($region->stylesheetPath != "") { $stylesheetPath = $region->stylesheetPath; $region->stylesheetPath = getPath($region->stylesheetPath); if ($stylesheetPath == $region->stylesheetPath) { checkStylesheet($stylesheetPath); } } } } $asset->$type->path = ""; echo $writeClient->create($writeAuth, $asset) . "\r\n"; if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "@$type\r\n"; echo $writeClient->message; print_r($asset->serialize()); flush(); } } } function checkTarget($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "target"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->target->path = null; $asset->target->parentTargetPath = str_replace("Targets", "/", $asset->target->parentTargetPath); if ($asset->target->parentTargetPath != "") { checkTarget($asset->target->parentTargetPath); } $asset->target->baseFolderPath = getPath($asset->target->baseFolderPath); if (is_string($asset->target->cssFilePath)) { $filePath = $asset->target->cssFilePath; $asset->target->cssFilePath = getPath($asset->target->cssFilePath); if ($filePath != $asset->target->cssFilePath) { checkFile($asset->target->cssFilePath); } } if ($asset->target->publishIntervalUnits == "Hours") { $asset->target->publishIntervalUnits = "hours"; } $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath . "\r\n"; echo $writeClient->message; flush(); } } } function checkBlock($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "block"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; if (isset($asset->indexBlock)) { $type = "indexBlock"; } else if (isset($asset->textBlock)) { $type = "textBlock"; } else if (isset($asset->feedBlock)) { $type = "feedBlock"; } else if (isset($asset->xmlBlock)) { $type = "xmlBlock"; } else if (isset($asset->xhtmlBlock)) { $type = "xhtmlBlock"; } $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath); checkFolder($asset->$type->parentFolderPath); if (is_string($asset->$type->metadataSetPath)) { checkMetadataSet($asset->$type->metadataSetPath); } if (is_string($asset->$type->structuredData->definitionPath)) { checkDefinition($asset->$type->structuredData->definitionPath); } if (is_string($asset->$type->configurationSetPath)) { checkConfigurationSet($asset->$type->configurationSetPath); } if (is_string($asset->$type->indexedFolderPath)) { $asset->$type->indexedFolderPath = getPath($asset->$type->indexedFolderPath); checkFolder($asset->$type->indexedFolderPath); } if (is_string($asset->$type->expirationFolderPath)) { $asset->$type->expirationFolderPath = getPath($asset->$type->expirationFolderPath); checkFolder($asset->$type->expirationFolderPath); } if (is_string($asset->$type->targetPath)) { checkTarget($asset->$type->targetPath); } $asset->$type->path = null; $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath . "\r\n"; echo $writeClient->message; flush(); } } } function checkStylesheet($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "stylesheet"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->stylesheet->path = null; if ($asset->stylesheet->parentFolderPath != "") { checkFolder($asset->stylesheet->parentFolderPath); } $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath . "\r\n"; echo $writeClient->message; flush(); } } } function checkFile($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "file"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->file->path = null; if ($asset->file->parentFolderPath != "") { checkFolder($asset->file->parentFolderPath); } $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath . "\r\n"; echo $writeClient->message; flush(); } } } function checkFolder($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; echo $setPath; $id = new identifier; $id->path = $setPath; $id->type = "folder"; $writeClient->read($writeAuth, $id); if ($writeClient->success != "true") { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->folder->path = null; if ($asset->folder->parentFolderPath != "") { checkFolder($asset->folder->parentFolderPath); } $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath . "\r\n"; echo $writeClient->message; flush(); } } } function checkMetadataSet($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "metadataset"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->metadataSet->path = null; checkMetadataSetContainer($asset->metadataSet->parentContainerPath); $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . $setPath; flush(); } else { echo "\r\nFailed: " . $setPath; echo $writeClient->message; flush(); } } } function checkMetadataSetContainer($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "metadatasetcontainer"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->metadataSetContainer->path = null; $asset->metadataSetContainer->parentContainerPath = str_replace("Metadata Sets", "/", $asset->metadataSetContainer->parentContainerPath); checkMetadataSetContainer($asset->metadataSetContainer->parentContainerPath); $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "\r\n"; echo $writeClient->message; flush(); } } } function checkConfigurationSet($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "pageconfigurationset"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->pageConfigurationSet->path = null; $asset->pageConfigurationSet->parentContainerPath = str_replace("Configuration Sets", "/", $asset->pageConfigurationSet->parentContainerPath); checkConfigurationSetContainer($asset->pageConfigurationSet->parentContainerPath); if (isset($asset->pageConfigurationSet->pageConfigurations)) { $configurations = $asset->pageConfigurationSet->pageConfigurations->pageConfiguration; foreach ($configurations as &$configuration) { $path = $configuration->templatePath; $configuration->templatePath = getPath($configuration->templatePath); if ($path == $configuration->templatePath) { checkTemplate($path); } if (isset($configuration->pageRegions)) { $regions = $configuration->pageRegions->pageRegion; foreach ($regions as &$region) { if ($region->blockPath != "") { $blockPath = $region->blockPath; $region->blockPath = getPath($region->blockPath); if ($blockPath == $region->blockPath) { checkBlock($blockPath); } } if ($region->stylesheetPath != "") { $stylesheetPath = $region->stylesheetPath; $region->stylesheetPath = getPath($region->stylesheetPath); if ($stylesheetPath == $region->stylesheetPath) { checkStylesheet($stylesheetPath); } } } } } } $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "@\r\n"; echo $writeClient->message; flush(); } } } function checkConfigurationSetContainer($setPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $setPath; $id->type = "pageconfigurationsetcontainer"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->pageConfigurationSetContainer->path = null; $asset->pageConfigurationSetContainer->parentContainerPath = str_replace("Configuration Sets", "/", $asset->pageConfigurationSetContainer->parentContainerPath); checkConfigurationSetContainer($asset->pageConfigurationSetContainer->parentContainerPath); $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "\r\n"; echo $writeClient->message; flush(); } } } function checkDefinition($defPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $defPath; $id->type = "structureddatadefinition"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->structuredDataDefinition->path = null; $asset->structuredDataDefinition->parentContainerPath = str_replace("Data Definitions", "/", $asset->structuredDataDefinition->parentContainerPath); checkDefinitionContainer($asset->structuredDataDefinition->parentContainerPath); $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "\r\n"; echo $writeClient->message; flush(); } } } function checkDefinitionContainer($defPath) { global $writeClient; global $readClient; global $readAuth; global $writeAuth; $id = new identifier; $id->path = $defPath; $id->type = "structureddatadefinitioncontainer"; $writeClient->read($writeAuth, $id); if (!$writeClient->success) { $readClient->read($readAuth, $id); $asset = $readClient->asset; $asset->structuredDataDefinitionContainer->path = null; $asset->structuredDataDefinitionContainer->parentContainerPath = str_replace("Data Definitions", "/", $asset->structuredDataDefinitionContainer->parentContainerPath); checkDefinitionContainer($asset->structuredDataDefinitionContainer->parentContainerPath); $writeClient->create($writeAuth, $asset); if ($writeClient->success) { echo "\r\nCreated: " . getPath($loc); flush(); } else { echo "\r\nFailed: " . getPath($loc) . "\r\n"; echo $writeClient->message; flush(); } } } /** * Gets the new parent folder path, by converting it from the old to the new */ function getPath($parentFolderPath) { global $oldPath; global $newPath; if ($parentFolderPath[0] == "/") { $tempPath = substr($parentFolderPath, 1); } else { $tempPath = $parentFolderPath; } //if it's in the current path if (strpos($tempPath, $oldPath) === 0) { /** If the user added on a trailing '/', kill it before it kills the script */ if (substr($parentFolderPath, strlen($parentFolderPath) - 1) === "/") { $parentFolderPath = substr($parentFolderPath, 0, strlen($parentFolderPath) - 1); } /** tack the newPath stuff in front, then strip the trailing / again if there is one */ $modifier = 0; if (dirname($oldPath) == ".") { $modifier = 1; } $parentFolderPath = $newPath . "/" . substr($parentFolderPath, strlen(dirname($oldPath)) - $modifier); $parentFolderPath = str_replace("//", "/", $parentFolderPath); if (substr($parentFolderPath, strlen($parentFolderPath) - 1) === "/") { $parentFolderPath = substr($parentFolderPath, 0, strlen($parentFolderPath) - 1); } return $parentFolderPath; } if ($tempPath == "") { return $newPath; } return $parentFolderPath; } ?>