{"cms-login-info"}->server; // The location of the Cascade instance $cascade_login["user"] = $xml_config->{"cms-login-info"}->username; // The username to login to the Cascade instance above $cascade_login["pass"] = $xml_config->{"cms-login-info"}->password; // The username's password $copyto_folder = $xml_config->{"copyto-folder"}; // The folder to copy all the symlinks to $symlinks_xml_feed = $xml_config->{"xml-feed"}; // The XML containing the symlinks to be imported // Load the system-index-block into a SimpleXML Object $xml = simplexml_load_file($symlinks_xml_feed); // Find out the folder you are copying from so that all paths can be relative to the directory $tpath = $xml->xpath('/system-index-block/*[position()=1]/path'); // Find the first child-node of the root-node that includes a path $path = $tpath[0]; // Store that path found $pathlen = strlen($path); // Find the string length of the path $folder_loc = strrpos($path, "/"); // Find the position of the last path separator $copyfrom_folder = substr($path, 0, $folder_loc); // The folder path will be the substring before this separator (doesn't include trailing '/') // If there is a trailing '/' character at the end of the cascade server // location, then remove it if(substr($cascade_loc, strlen($cascade_loc) - 1, 1) == '/') { $cascade_loc = substring($cascade_loc, 0, strlen($cascade_loc) - 1); } // Construct a SOAP client connecting to Cascade instance $client = new SoapClient($cascade_loc."/ws/services/AssetOperationService?wsdl", array('trace' => 1)); // Import all the symlinks contained in the copyfrom folder import_symlinks($xml->{"system-symlink"}, $client); // Begin recursing through each of the subfolders to add each folder to the CMS, // as well as any symlinks the subfolders may have. foreach($xml->{"system-folder"} as $folder) { symlinkSync($folder, $client); } /** * Imports all symlinks contained within the SimpleXML object $folder and * recursively repeats the process for any of $folder's sub-folders. * * @param $folder SimpleXML Object of a system-folder within a system-index-block * @param $client SOAP client connecting to Cascade instance */ function symlinkSync($folder, $client) { // Create the folder that has been recursed to add_folder($folder->path, $client); // Import all the symlinks contained in this folder import_symlinks($folder->{"system-symlink"}, $client); // Recurse through all the subfolders of this folder also foreach($folder->{"system-folder"} as $folder){ symlinkSync($folder, $client); } } /** * Imports all symlinks contained within the array of SimpleXML objects, * $symlinks, to the Cascade instance specified in the configuration XML file * using its specified login information as well. It copies the symlink's * linkURL, system-name, title metadata, and summary metadata. * * @param $symlinks SimpleXML Object array that holds symlink information * @param $client SOAP client connecting to Cascade instance */ function import_symlinks($symlinks, $client){ global $cascade_login, $cascade_loc; // Iterate through each symlink in the provided $symlinks array foreach($symlinks as $symlink) { // Construct the parameters to create system-symlinks $create_params = array ( 'authentication' => array ( 'password' => $cascade_login["pass"], 'username' => $cascade_login["user"] ), 'asset' => array ( 'symlink' => array ( 'name' => $symlink->name, // Convert the system-symlink's link attribute to UTF-8 encoding 'linkURL' => utf8_encode($symlink->link), 'parentFolderPath' => getParentFolderPath(formatPath($symlink->path)), 'metadataSetPath' => "/Default", 'metadata' => array ( // Convert the metadata's content to UTF-8 encoding 'title' => utf8_encode($symlink->title), 'summary' => utf8_encode($symlink->summary) ) ) ) ); try{ // Pass this request to Web Services $response = $client->create($create_params); // If something goes wrong check the value of getLastResponse() // But we won't because all it does now is print out true // print("\n". $client->__getLastResponse() . "\n"); } catch (Exception $e) { /* The request will throw an exception when parameters do * not conform to the WSDL. This will *not* catch errors * in the parameters themselves */ print("Page creation request failed to conform to the WSDL.\n"); } } } function add_folder($path, $client) { global $cascade_login; // CMS login info /* We need to find the last element on the path, which will * be the directory we want to create. We do this similarly to * the way we separated the page name from the path */ /* Find the string length of the path */ $pathlen = strlen($path); /* Find the position of the last path separator */ $folder_loc = strrpos($path, "/"); /* The folder name will be the substring after this separator */ $folder_name = substr($path, $folder_loc + 1, $pathlen - $folder_loc - 1); /* Now we fill an associative array that we will pass to the PHP * SOAP functions. The structure of this array will be determined * by the WSDL specification. PHP will interpret the structure * and create appropriate XML to pass to the Web Services */ $create_params = array ( 'authentication' => array ( 'password' => $cascade_login["pass"], 'username' => $cascade_login["user"] ), 'asset' => array ( 'folder' => array ( 'name' => $folder_name, 'metadataSetPath' => "/Default", 'parentFolderPath' => getParentFolderPath(formatPath($path)) ) ) ); try { /* Pass the create parameters through the PHP SOAP client. */ $response = $client->create($create_params); /* If something goes wrong, it will be reported with * __getLastResponse, so be sure to take a look at the * message it returns. */ // But we won't because all it does now is print out true // print($client->__getLastResponse() . "\n"); } catch (Exception $e) { /* The request will throw an exception when parameters do * not conform to the WSDL. This will *not* catch errors * in the parameters themselves */ print("Folder creation request failed to conform to the WSDL.\n"); } } /** * Return a new path with the $copyfrom_folder stripped out of the beginning * of the provided path and the $copyto_folder added to the beginning of the * path for a path that correlates to the CMS server being copied to. * * @param path CMS path included in system-index-block */ function formatPath($path) { global $copyfrom_folder, $copyto_folder; return $copyto_folder.'/'.substr($path, strlen($copyfrom_folder) + 1); } /** * Return the path of the parent folder of the provided path parameter. * * @param path CMS path for finding its parent folder path */ function getParentFolderPath($path) { $pathlen = strlen($path); // Find the string length of the path $folder_loc = strrpos($path, "/"); // Find the position of the last path separator $parent_folder = substr($path, 0, $folder_loc); // The folder path will be the substring before this separator (doesn't include trailing '/') return $parent_folder; } echo 'Done.'; ?>