/index.php
PHP | 2365 lines | 1990 code | 164 blank | 211 comment | 607 complexity | 5f2a55f79a7284e40497b92d56c4e059 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- This script copies assets between sites in Cascade or from one
- instance of Cascade to another. You can recursively copy folders
- or containers and all their contents, or copy entire sites.
- This is version 1.6.5 for Cascade 7
- Based on the copy-folder script in Hannon Hill's CAST toolkit.
- */
- error_reporting(E_ALL ^ E_NOTICE); # ignore undefined variables
- ini_set("display_errors",1);
- ini_set("max_execution_time",600);
- ini_set("memory_limit",'512M');
- include_once("cascade_soap_lib.php");
- /* Configuration */
- $environments = array(
- 'Cascade Development' => 'dev.example.edu',
- 'Cascade Test' => 'test.example.edu',
- 'Cascade Production' => 'prod.example.edu',
- );
- $secure = 1; # whether to use http or https to connect to web services
- /* You shouldn't have to change anything below this line */
- $verbose = 2;
- $dryrun = 0;
- $exit_on_error = 1;
- $inherit_permissions = 0;
- $copytype = 'folder';
- $oldPath = '/';
- $firstPass = false;
- $multiPass = false;
- ob_implicit_flush(true);
- ob_end_flush();
- ?>
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
- <!-- Latest compiled and minified JavaScript -->
- <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
- <?php
- if (!empty($_POST) && validateInput()) {
- showForm();
- echo "<pre>";
- if ($dryrun) out1("Dry Run");
- if ($multiPass) {
- $firstPass = true;
- out1("First pass...");
- }
- update();
- setPermissions();
- if ($multiPass) {
- $firstPass = false;
- echo "</pre>";
- echo "<pre>";
- out1("Second pass...");
- editPages();
- editPageConfigurationSets();
- }
- if ($dryrun) {
- out1("Dry Run Complete");
- } else {
- out1("Done.");
- }
- echo "</pre>";
- } else {
- showForm();
- }
- function update() {
- global $host, $host2;
- global $uname, $uname2;
- global $pass, $pass2;
- global $oldPath, $newPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $copytype;
- global $dryrun;
- global $verbose;
- global $secure;
- $proto = 'http';
- if ($secure) $proto = 'https';
- $readClient = new CascadeSoapClient();
- if (preg_match('/^http/', $host)) {
- $readClient->url = $host . "/ws/services/AssetOperationService?wsdl";
- } else {
- $readClient->url = "$proto://" . $host . "/ws/services/AssetOperationService?wsdl";
- }
-
- $readClient->username = $uname;
- $readClient->password = $pass;
- $readClient->connect();
- $writeClient = new CascadeSoapClient();
- if (preg_match('/^http/', $host2)) {
- $writeClient->url = $host2 . "/ws/services/AssetOperationService?wsdl";
- } else {
- $writeClient->url = "$proto://$host2/ws/services/AssetOperationService?wsdl";
- }
-
- $writeClient->username = $uname2;
- $writeClient->password = $pass2;
- $writeClient->connect();
- if ($oldSite == 'Global')
- $oldSite = '';
- if ($newSite == 'Global')
- $newSite = '';
- #
- # admin areas to include when we copy sites
- #
- $adminAreas = array(
- 'assetFactory', 'contentType', 'dataDefinition',
- 'metadataSet', 'pageConfigurationSet', 'publishSet',
- 'workflowDefinition'
- );
- if ($oldSite == '' && $newSite == '') { # old "sites"
- array_push($adminAreas, 'target');
- } else if ($oldSite != '' && $newSite != '') { # new "Sites"
- array_push($adminAreas, 'transport');
- array_push($adminAreas, 'destination');
- }
- echo "Copying $copytype $host/$oldSite:$oldPath to $host2/$newSite:$newPath\n";
- if ($copytype == 'folder' || $copytype == 'site') {
- add_folder(NULL,$oldPath);
- } else if (preg_match('/Container$/',$copytype)) {
- add_container(NULL,$oldPath,$copytype);
- } else if (in_array($copytype,$adminAreas)) {
- checkAdminAsset(NULL,$oldPath,$copytype);
- } else if ($copytype == 'user') { // copy one or more users
- $oldPaths = preg_split("/ +/", $oldPath);
- foreach ($oldPaths as &$oldPath) {
- checkUser($oldPath);
- }
- } else if ($copytype == 'group') { // copy one or more groups
- $oldPaths = preg_split("/ +/", $oldPath);
- foreach ($oldPaths as &$oldPath) {
- checkGroup($oldPath);
- }
- } else { // home area asset
- checkAsset(NULL,$oldPath,$copytype);
- }
- if ($copytype == 'site') {
- $checkPath = preg_replace("#^.*/#","/",$oldPath);
- foreach ($adminAreas as &$adminArea) {
- if ($verbose>2) out2("\nChecking ${adminArea}s ...");
- if ($adminArea == 'destination') {
- $type = "siteDestinationContainer";
- } else if ($adminArea == 'target') {
- $type = "target";
- } else {
- $type = $adminArea . "Container";
- }
- add_container(NULL,$checkPath,$type);
- }
- }
- }
- /*
- * On the second pass, edit the pages that are in the structuredPages array
- */
- function editPages() {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $added;
- global $exit_on_error;
- global $structuredPages;
-
- //if it's the second pass and there are pages to edit
- if(is_array($structuredPages)) {
- //loop through each page and get the page from read and update write based on it
- foreach($structuredPages as $pagePath) {
- //get the page from the readClient
- $readAsset = getReadAsset($pagePath, "page");
- $writeAsset = getWriteAsset($pagePath, "page");
- //replace the write page DD with the read DD
- $writeAsset->page->structuredData = $readAsset->page->structuredData;
- adjustStructuredData(
- $writeAsset->page->path,
- $writeAsset->page->structuredData->structuredDataNodes);
- //edit the asset on the writeClient
- updateWriteAsset("page", $writeAsset);
- } //end foreach structured page
- } //end if structured pages and second pass
-
- return true;
- }
- /*
- * On the second pass, edit the pages that are in the structuredPages array
- */
- function editPageConfigurationSets() {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $pageConfigurationSets;
-
- $type = "pageConfigurationSet";
- //if it's the second pass and there are pages to edit
- if(is_array($pageConfigurationSets)) {
- //edit each config set, copying pageConfigurations from source asset
- foreach($pageConfigurationSets as $path) {
- //get the asset from the readClient
- $readAsset = getReadAsset($path, $type);
- $writeAsset = getWriteAsset($path, $type);
-
- //replace the write page configurations with the read
- $writeAsset->$type->pageConfigurations =
- $readAsset->$type->pageConfigurations;
- adjustPageConfigurations($path,$writeAsset->$type->pageConfigurations);
- //edit the asset on the writeClient
- updateWriteAsset($type, $writeAsset);
- }
- }
-
- return true;
- }
- /*
- * read the asset from the oldSite and return the object
- */
- function getReadAsset($path, $type) {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $exit_on_error;
-
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = strtolower($type);
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "getReadAsset(): Read failure on $type $path: " . cleanup($readClient->response);
- print_r($ident);
- if ($exit_on_error) cleanexit(); else return;
- }
- return $readClient->asset;
- }
- /*
- * read the asset from the newSite and return the object
- */
- function getWriteAsset($path, $type) {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $exit_on_error;
-
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $newSite;
- $ident->type = strtolower($type);
- $writeClient->read($ident);
- if (!$writeClient->success) {
- echo "getWriteAsset(): Read failure on $type $path: " . cleanup($writeClient->response);
- print_r($ident);
- if ($exit_on_error) cleanexit(); else return;
- }
- return $writeClient->asset;
- }
- /*
- * update the asset on the newSite
- */
- function updateWriteAsset($type, $writeAsset) {
- global $readClient, $writeClient;
- global $dryrun;
- global $verbose;
- global $exit_on_error;
- global $newId;
-
- if (!$dryrun) {
- $writeClient->edit($writeAsset);
- if (!$writeClient->success) {
- echo "updateWriteAsset(): Failed: " . $writeAsset->$type->path . "\n";
- print_r($writeAsset);
- echo cleanup($writeClient->response);
- print_r($readAsset);
- if ($exit_on_error) cleanexit(); else return false;
- } //is not successful write
- } //if not dry run
-
- if($verbose>1) echo "Updated $type " . $writeAsset->$type->path . "\n";
-
- return true;
- }
- /*
- * Get the ID of the asset on the newSite given the path and type
- */
- function getWriteAssetID($path, $type) {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
-
- $ident->path = $path;
- $ident->siteName = $newSite;
- $ident->type = $type;
- $writeClient->read($ident);
- if (!$writeClient->success) {
- echo "getWriteAssetID('$path', '$type'): Read failure on $type $path: " . cleanup($writeClient->response);
- print_r($ident);
- if ($exit_on_error) cleanexit(); else return;
- }
- return $writeClient->asset->$type->id;
- }
- /*
- * Read the folder, push its children, make the folder, then pop remaining children
- */
- function add_folder($id,$path) {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $folderStack;
- global $pageStack;
- global $refStack;
- global $genericStack;
- global $templateStack;
- global $skipPattern;
- global $added;
- global $exit_on_error;
- $type = 'folder';
- #
- # have we already checked folder *and* children?
- #
- if (isset($added["$type.$path"])) {
- return;
- } else {
- $added["$type.$path"] = 1;
- }
- if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
- echo "*** Skipping $type $path\n";
- return;
- }
- #
- # create the folder itself
- #
- checkFolder($id, $path);
- #
- # and its children
- #
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = "folder";
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- if (isset($asset->$type->children)
- && isset($asset->$type->children->child)) {
- $children = $asset->$type->children->child;
- if (!is_array($children)) {
- $children = array( $children );
- }
- } else {
- $children = "";
- }
- 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->id,$cur->path->path);
- }
- }
- if (is_array($genericStack)) {
- while ($cur = array_pop($genericStack)) {
- checkAsset($cur->id,$cur->path->path, $cur->type);
- }
- }
- if (is_array($templateStack)) {
- while ($cur = array_pop($templateStack)) {
- checkAsset($cur->id,$cur->path->path, $cur->type);
- }
- }
- if (is_array($pageStack)) {
- while ($cur = array_pop($pageStack)) {
- checkAsset($cur->id,$cur->path->path, $cur->type);
- }
- }
- if (is_array($refStack)) {
- while ($cur = array_pop($refStack)) {
- checkAsset($cur->id,$cur->path->path, $cur->type);
- }
- }
- }
- /*
- * Read in the file, block, symlink, or ... and add it directly
- */
- function checkAsset($id, $path, $type) {
- global $oldPath, $newPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $skipPattern;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- global $newId;
- global $targetStuff;
- global $firstPass;
- global $structuredPages;
- if (preg_match("/block_.*/",$type)) {
- $type = "block";
- } else if (preg_match("/format_.*/",$type)) {
- $type = "format";
- }
- #
- # see if we've already checked it
- #
- if (isset($checked["$type.$path"])) {
- if ($verbose>3) out3("*** Checking $type: " . getPath($path) . " (we've been here before)");
- return;
- } else {
- $checked["$type.$path"] = 1;
- }
- if ($dryrun && $type == 'file' && $verbose<2) {
- return; # speed things up a bit
- }
- if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
- echo "*** Skipping $type $path\n";
- return;
- }
- #
- # reference to another site
- #
- if (preg_match('/^(.*):(.*)/',$path,$matches)) {
- global $host, $host2;
- if ($host == $host2) {
- if ($verbose>2) out2("Ok: $type $path");
- return;
- } else {
- $site = $matches[1];
- $path = $matches[2];
- if ($verbose>2) out2("Checking $type $site:$path");
- $newident->path = $path;
- $newident->siteName = $site;
- $newident->type = strtolower($type);
- $writeClient->read($newident);
- if (!$writeClient->success) {
- if (preg_match('/Unable to identify an entity/',$writeClient->response)) {
- echo "
- *** Found cross-site reference to $site $type $path, which does not exist in the
- target environment. You must change this before the copy can proceed.
- ";
- } else {
- echo "Failed reading: " . $site . ': ' . $path . "\n";
- echo print_r($newident);
- echo cleanup($writeClient->response);
- }
- if ($exit_on_error) cleanexit(); else return;
- }
- return;
- }
- }
- #
- # read source asset
- #
- if ($verbose>2) out2("Checking $type $path");
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = $type;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Read failure on $type $path: " . cleanup($readClient->response);
- print_r($ident);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- $otype = $type;
- 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";
- } else if (isset($asset->xhtmlDataDefinitionBlock)) {
- $type = "xhtmlDataDefinitionBlock";
- } else if (isset($asset->xsltFormat)) {
- $type = "xsltFormat";
- } else if (isset($asset->scriptFormat)) {
- $type = "scriptFormat";
- }
- }
- #
- # workaround http://issues.hannonhill.com/browse/CSI-145
- # if asset is in a different site, we're done
- # (this should never happen)
- #
- if ($asset->$type->siteName != $oldSite) {
- global $host, $host2;
- if ($host == $host2) {
- $newId[$id] = $id;
- }
- if ($verbose>2)
- out2("Skipping $type $path (site " . $asset->$type->siteName . "!=" . $oldSite . ")");
- return;
- }
- //remove the structured data from the page on the first pass
- if($firstPass && isset($asset->page->structuredData)) {
- unset($asset->page->structuredData);
- $structuredPages[$asset->page->path] = $asset->page->path;
- }
- #
- # save asset id to get around CSI-108
- #
- $ident->id = $asset->$type->id;
- #
- # see if asset already exists in new location
- #
- $parent = preg_replace("#/[^/]*$#", "", $path);
- if (isset($checked["folder.$parent"])) {
- # we know it doesn't exist
- } else if (isset($newId["$otype.$path"])) {
- # we know it does exist
- $newId[$asset->$type->id] = $newId["$otype.$path"];
- return;
- } else {
- if ($verbose>3) out3("Checking new $type: " . getPath($path));
- $newident->path = getPath($path);
- $newident->siteName = $newSite;
- $newident->type = $ident->type;
- $writeClient->read($newident);
- if ($writeClient->success) {
- $newasset = $writeClient->asset;
- $newId[$asset->$type->id] = $newasset->$type->id;
- return;
- } else if (preg_match('/Unable to identify/',$writeClient->response)) {
- } else {
- echo "Read failure on destination: " . getPath($path) . cleanup($writeClient->response);
- print_r($newident);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- if ($type == 'xsltFormat') {
- $asset->$type->xml = preg_replace(
- '#1.0"xmlns#', '1.0" xmlns', $asset->$type->xml);
- }
- if ($type == 'file' || preg_match('/\.css$/',$asset->$type->name)) {
- $asset->$type->data =
- preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
- '/renderfile/global$1', $asset->$type->data);
- $asset->$type->text =
- preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
- '/renderfile/global$1', $asset->$type->text);
- }
- if ($type == 'page' && $oldPath != $newPath) {
- $asset->$type->xhtml = preg_replace(
- "#$oldPath#", $newPath, $asset->$type->xhtml);
- }
- # remove [system-asset] tags from symlinks
- if ($type == 'symlink' && isset($asset->$type->linkURL)) {
- $asset->$type->linkURL =
- preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
- '$1', $asset->$type->linkURL);
- }
- if (isset($asset->$type->parentFolderPath)) {
- checkFolder($asset->$type->parentFolderId,$asset->$type->parentFolderPath);
- $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath);
- }
- if (isset($asset->$type->metadataSetPath)) {
- checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
- }
- if (isset($asset->$type->configurationSetPath)) {
- checkAdminAsset($asset->$type->configurationSetId,$asset->$type->configurationSetPath,'pageConfigurationSet');
- } else {
- unset($asset->$type->configurationSetPath);
- }
- if (isset($asset->$type->contentTypePath)) {
- checkAdminAsset($asset->$type->contentTypeId,$asset->$type->contentTypePath,"contentType");
- }
- if (isset($asset->$type->indexedContentTypePath)) {
- checkAdminAsset($asset->$type->IndexedContentTypeId,$asset->$type->indexedContentTypePath,"contentType");
- }
- if (isset($asset->$type->indexedFolderPath)) {
- if (want($asset->$type->indexedFolderPath,'folder')) {
- checkAsset($asset->id,$asset->$type->indexedFolderPath,'folder');
- $asset->$type->indexedFolderPath = getPath($asset->$type->indexedFolderPath);
- } else {
- if ($verbose>1) echo "*** Adjusting indexedFolderPath in $type $path\n";
- $asset->$type->indexedFolderPath = null;
- }
- } else {
- # silly php, if it's not set, why do we need to unset it?
- if ($type == 'indexBlock') {
- #echo "*** Removing indexedFolderPath in $type $path\n";
- unset($asset->$type->indexedFolderPath);
- }
- }
- if (isset($asset->$type->expirationFolderPath)) {
- if (want($asset->$type->expirationFolderPath,'folder')) {
- checkAsset($asset->id,$asset->$type->expirationFolderPath,'folder');
- $asset->$type->expirationFolderPath = getPath($asset->$type->expirationFolderPath);
- } else {
- if ($verbose>1) echo "Adjusting expirationFolderPath in $type $path\n";
- $asset->$type->expirationFolderPath = null;
- }
- }
- if (isset($asset->$type->formatPath)) {
- checkAsset($asset->id,$asset->$type->formatPath,'format');
- $asset->$type->formatPath = getPath($asset->$type->formatPath);
- }
- if (isset($asset->$type->targetPath)) {
- if ($newSite) {
- # sites don't have targets, but we may need the file extension
- $targetStuff["$type.$path"] = getTargetStuff($asset->$type->targetPath);
- unset($asset->$type->targetPath);
- } else {
- checkTarget($asset->$type->targetPath);
- }
- }
- if (isset($asset->$type->structuredData) &&
- is_string($asset->$type->structuredData->definitionPath)) {
- checkAdminAsset($asset->$type->structuredData->definitionId,$asset->$type->structuredData->definitionPath,'dataDefinition');
- }
- if (isset($asset->$type->structuredData) &&
- isset($asset->$type->structuredData->structuredDataNodes)) {
- adjustStructuredData($path,$asset->$type->structuredData->structuredDataNodes);
- unset($asset->$type->structuredData->definitionId);
- } else {
- unset($asset->$type->structuredData);
- }
- if (isset($asset->$type->pageConfigurations)) {
- adjustPageConfigurations($asset->$type->configurationSetPath,$asset->$type->pageConfigurations);
- }
- if (isset($asset->$type->pageRegions)) {
- adjustPageRegions($path,$asset->$type->pageRegions);
- }
- if (isset($asset->$type->referencedAssetId)) {
- if ($asset->$type->referencedAssetType == 'folder') {
- checkFolder($asset->$type->referencedAssetId,$asset->$type->referencedAssetPath);
- } else {
- checkAsset($asset->id,$asset->$type->referencedAssetPath,
- $asset->$type->referencedAssetType);
- }
- $asset->$type->referencedAssetPath =
- getPath($asset->$type->referencedAssetPath);
- }
- setSite($asset,$type);
- removeIds($asset->$type);
- unset($asset->$type->path);
- if (isset($asset->$type->data)) {
- unset($asset->$type->text);
- //$asset->$type->data = base64_decode($asset->$type->data);
- }
- if ($verbose>1) echo "Creating: $type " . getPath($path) . "\n";
- if ($verbose==1) echo ".";
- if (!$dryrun) {
- $writeClient->create($asset);
- if ($writeClient->success) {
- $newId[$ident->id] = $writeClient->createdAssetId;
- #echo "Created $type " . $newId[$ident->id] . "\n";
- remember($ident);
- } else {
- echo "Failed: $type " . getPath($path) . "\n";
- if (isset($asset->$type->data)) {
- $asset->$type->data = "*** data ***";
- }
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- function checkTarget($path) {
- global $readClient, $writeClient;
- global $oldSite, $newSite;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- $type = "target";
- if (isset($checked["$type.$path"])) {
- return;
- } else {
- $checked["$type.$path"] = 1;
- }
- if ($path == '/') {
- return;
- }
- if ($verbose>2) out2("Checking $type $path ...");
- $ident->path = $path;
- $ident->siteName = $newSite;
- $ident->type = $type;
- $writeClient->read($ident);
- if (!$writeClient->success) {
- $ident->siteName = $oldSite;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- #
- # save asset id to get around CSI-108
- #
- $ident->id = $asset->$type->id;
- if ($asset->$type->parentTargetPath != "") {
- checkTarget($asset->$type->parentTargetPath);
- }
- $asset->$type->baseFolderPath = getPath($asset->$type->baseFolderPath);
- if ($asset->$type->cssFilePath != "") {
- checkAsset($asset->$type->cssFileId,$asset->$type->cssFilePath,'file');
- $asset->$type->cssFilePath = getPath($asset->$type->cssFilePath);
- }
- if ($asset->$type->publishIntervalUnits == "Hours") {
- $asset->$type->publishIntervalUnits = "hours";
- }
- setSite($asset,$type);
- removeIds($asset->$type);
- unset($asset->$type->path);
- unset($asset->$type->children);
- if ($verbose>1) echo "Creating: $type " . $path . "\n";
- if (!$dryrun) {
- $writeClient->create($asset);
- if ($writeClient->success) {
- remember($ident);
- } else {
- echo "\nFailed: $type " . $path . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- }
- function getTargetStuff($path) {
- global $readClient;
- global $oldSite;
- global $verbose;
- global $checked;
- global $exit_on_error;
- global $targetStuff;
- $type = "target";
- if (!isset($targetStuff["$type.$path"])) {
- if ($verbose>2) out2("Checking $type $path ...");
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = $type;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- $targetStuff["$type.$path"] =
- array($asset->$type->outputExtension, $asset->$type->serializationType);
- }
- return($targetStuff["$type.$path"]);
- }
- function checkFolder($id,$path) {
- global $readClient, $writeClient;
- global $oldPath, $newPath;
- global $oldSite, $newSite;
- global $skipPattern;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- global $newId;
- $type = 'folder';
- if (isset($checked["$type.$path"])) {
- return;
- } else {
- $checked["$type.$path"] = 1;
- }
- if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
- echo "*** Skipping $type $path\n";
- return;
- }
- # if (!preg_match("#^$oldPath(/|$)#",$path)
- # && !preg_match("#^$path(/|$)#",$oldPath)) {
- # echo "*** Skipping $path\n";
- # return; # don't back up too far
- # }
- #
- # read source asset
- #
- if ($verbose>2) out2("Checking $type $path...");
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = $type;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- #
- # save asset id to get around CSI-108
- #
- $ident->id = $asset->$type->id;
- #
- # see if asset already exists in new location
- # (even if we know its newID, we still need to check for children)
- #
- if ($verbose>3) out3("Checking new $type " . getPath($path) . " ...");
- $newident->path = getPath($path);
- $newident->siteName = $newSite;
- $newident->type = $ident->type;
- $writeClient->read($newident);
- if ($writeClient->success) {
- #
- # Note any children, since we don't need to create them
- #
- $newasset = $writeClient->asset;
- $newId[$asset->$type->id] = $newasset->$type->id;
- #echo "Found2 new Id for $type $path\n";
- if (isset($newasset->$type->children)
- && isset($newasset->$type->children->child)) {
- $children = $newasset->$type->children->child;
- if (!is_array($children)) {
- $children = array( $children );
- }
- #echo "Folder $path in $newSite has children\n";
- while ($cur = array_pop($children)) {
- $ctype = $cur->type;
- $cpath = $cur->path->path;
- #echo "Child $ctype $cpath\n";
- if (preg_match("/block_.*/",$ctype)) {
- $ctype = "block";
- } else if (preg_match("/format_.*/",$ctype)) {
- $ctype = "format";
- }
- if ($ctype != 'folder') {
- $checked["$ctype.$cpath"] = 1;
- }
- $newId["$ctype.$cpath"] = $cur->id;
- #echo "Saving new Id " . $cur->id . " for $ctype $cpath\n";
- #if ($verbose>2) echo "Ok: $ctype $cpath\n";
- }
- }
- return;
- }
- #
- # we need to create it
- #
- if (isset($asset->$type->parentFolderPath)) {
- checkFolder($asset->$type->parentFolderId,$asset->$type->parentFolderPath);
- }
- #
- # if this is the main folder we're copying, we may need to rename it
- #
- if ($path == $oldPath) {
- $oldName = preg_replace(",^.*/,", "", $oldPath);
- $newName = preg_replace(",^.*/,", "", $newPath);
- if ($oldName != $newName) {
- $asset->$type->name = $newName;
- }
- }
- $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath);
- checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
- setSite($asset,$type);
- removeIds($asset->$type);
- unset($asset->$type->path);
- unset($asset->$type->children);
- if ($verbose) echo "Creating: $type " . getPath($path) . "\n";
- if (!$dryrun) {
- $writeClient->create($asset);
- if ($writeClient->success) {
- $newId[$ident->id] = $writeClient->createdAssetId;
- #echo "Created $type " . $newId[$ident->id] . "\n";
- remember($ident);
- } else {
- echo "\nFailed: $type " . getPath($path) . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- function checkAdminAsset($id,$path,$type) {
- global $readClient, $writeClient;
- global $host, $host2;
- global $oldSite, $newSite;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- global $newId;
- global $firstPass;
- global $pageConfigurationSets;
- if (isset($checked["$type.$path"])) {
- return;
- } else {
- $checked["$type.$path"] = 1;
- }
- #
- # reference to another site
- #
- if (preg_match('/^(.*):(.*)/',$path,$matches)) {
- global $host, $host2;
- if ($host == $host2) {
- if ($verbose>2) out2("Ok: $type $path");
- return;
- } else {
- $site = $matches[1];
- $path = $matches[2];
- if ($verbose>2) out2("Checking $type $site:$path");
- $newident->path = $path;
- $newident->siteName = $site;
- $newident->type = strtolower($type);
- $writeClient->read($newident);
- if (!$writeClient->success) {
- if (preg_match('/Unable to identify an entity/',$writeClient->response)) {
- echo "
- *** Found cross-site reference to $site $type $path, which does not exist
- in target environment. You must change this before the copy can proceed.
- ";
- } else {
- echo "Failed reading: " . $site . ': ' . $path . "\n";
- echo print_r($newident);
- echo cleanup($writeClient->response);
- }
- if ($exit_on_error) cleanexit(); else return;
- }
- return;
- }
- }
- #
- # read source asset
- #
- if ($verbose>2) out2("Checking $type $path");
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = strtolower($type);
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Read failure on $type $path: " . cleanup($readClient->response);
- echo print_r($ident);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- $otype = $type;
- $container = $type.'Container';
- if ($type == 'destination') {
- if($oldSite == '') {
- $container = 'target';
- } else {
- $container = 'siteDestinationContainer';
- }
- } else if (preg_match('/Connector$/', $type)) {
- $container = 'connectorContainer';
- }
- if (!isset($asset->$type)) {
- if (isset($asset->fileSystemTransport)) {
- $type = "fileSystemTransport";
- $container = "transportContainer";
- } else if (isset($asset->ftpTransport)) {
- $type = "ftpTransport";
- $container = "transportContainer";
- } else if (isset($asset->databaseTransport)) {
- $type = "databaseTransport";
- $container = "transportContainer";
- } else if (isset($asset->metadataSet)) {
- $type = "metadataSet";
- $container = "metadataSetContainer";
- }
- }
- #
- # save asset id to get around CSI-108
- #
- $ident->id = $asset->$type->id;
- #
- # see if asset already exists in new location
- #
- $parent = preg_replace("#/[^/]*$#", "", $path);
- if (isset($checked["$container.$parent"])) {
- # we know it doesn't exist
- #echo "Not checking $type: $path (it can't exist)\n";
- } else if (isset($newId["$otype.$path"])) {
- # we know it does exist
- $newId[$asset->$type->id] = $newId["$otype.$path"];
- #echo "Found new Id for $type $path\n";
- return;
- } else {
- if ($verbose>3) out3("Checking new $type $path");
- $newident->path = $path;
- $newident->siteName = $newSite;
- $newident->type = $ident->type;
- $writeClient->read($newident);
- if ($writeClient->success) {
- $newasset = $writeClient->asset;
- $newId[$asset->$type->id] = $newasset->$type->id;
- #echo "Found2 new Id for $type $path\n";
- return;
- } else if (preg_match('/Unable to identify/',$writeClient->response)) {
- #echo "Can't find $type " . $ident->path . " in $newSite\n";
- } else {
- echo "Read failure on destination: " . getPath($path) . cleanup($writeClient->response);
- print_r($newident);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- if (isset($asset->fileSystemTransport)) {
- if (!$asset->$type->directory) {
- echo "*** Skipping $type $path: directory is required\n";
- return;
- }
- } else if (isset($asset->ftpTransport)) {
- echo "*** Can't set password on $type: $path\n";
- $asset->$type->password = 'UNKNOWN';
- } else if (isset($asset->databaseTransport)) {
- // Cascade 6.7.3 WS can't create database transport with siteId=0
- //$asset->$type->transportSiteId = 1;
- }
- if (isset($asset->$type->parentContainerPath)) {
- if ($type == 'destination' && $oldSite == '') {
- checkTarget($asset->$type->parentContainerPath);
- } else {
- checkContainer($asset->$type->parentContainerId,$asset->$type->parentContainerPath,$container);
- }
- }
- if ($type == 'destination') {
- if (isset($asset->$type->transportPath)) {
- checkAdminAsset($asset->$type->transportId,$asset->$type->transportPath,'transport');
- }
- }
- if ($type == 'assetFactory') {
- if ($asset->$type->assetType == 'format') {
- # see http://issues.hannonhill.com/browse/CSI-222
- echo "*** Skipping asset factory of type 'format': " . $path . "\n";
- return;
- }
- if (isset($asset->$type->assetType) && isset($asset->$type->baseAssetPath)) {
- if ($asset->$type->assetType == 'folder') {
- checkFolder($asset->$type->baseAssetId,$asset->$type->baseAssetPath);
- } else {
- checkAsset($asset->id,$asset->$type->baseAssetPath,$asset->$type->assetType);
- }
- }
- if (isset($asset->$type->placementFolderPath)) {
- checkFolder($asset->$type->placementFolderId,$asset->$type->placementFolderPath);
- }
- # as per CSCD-4324 asset factory's with multiple applicable groups do not persist
- if (isset($asset->$type->applicableGroups)) {
- $asset->$type->applicableGroups =
- preg_replace("/,/", ";", $asset->$type->applicableGroups);
- }
- if (isset($asset->$type->workflowDefinitionPath)) {
- checkAdminAsset($asset->$type->workflowDefinitionId,$asset->$type->workflowDefinitionPath,'workflowDefinition');
- }
- } else if ($type == 'pageConfigurationSet') {
- if (isset($asset->$type->pageConfigurations)) {
- if($firstPass && $host == $host2 && $oldSite != '' && $newSite != '') {
- // To avoid dependency loops when copying between sites,
- // where both sites are in the same instance of Cascade,
- // on the first pass we make an exact copy of the configuration sets
- // (where all regions and templates refer to the original site)
- // We record this here and fix it on the second pass
- $pageConfigurationSets[$asset->$type->path] = $asset->$type->path;
- } else {
- //update configurations to point to the new site
- adjustPageConfigurations($path,$asset->$type->pageConfigurations);
- }
- }
- if ($oldSite == '' && $newSite != '') {
- #echo "*** Please set Output File Extension in $type $path\n";
- }
- } else if ($type == 'publishSet') {
- foreach (array('pages','files','folders') as $pstype) {
- $area = $asset->$type->$pstype;
- if (isset($area->publishableAssetIdentifier) &&
- isset($area->publishableAssetIdentifier)) {
- $children = $area->publishableAssetIdentifier;
- if (!is_array($children)) {
- $children = array( $children );
- }
- #echo "*** Removing Ids from $pstype in $path\n";
- foreach ($children as &$item) {
- unset($item->id);
- }
- }
- }
- } else if ($type == 'contentType') {
- if (isset($asset->$type->metadataSetPath)) {
- checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
- }
- if (isset($asset->$type->pageConfigurationSetPath)) {
- checkAdminAsset($asset->$type->pageConfigurationSetId,$asset->$type->pageConfigurationSetPath,'pageConfigurationSet');
- }
- if (isset($asset->$type->dataDefinitionPath)) {
- checkAdminAsset($asset->$type->dataDefinitionId,$asset->$type->dataDefinitionPath,'dataDefinition');
- }
- if (isset($asset->$type->contentTypePageConfigurations)) {
- adjustPageConfigurations($asset->$type->pageConfigurationSetPath,$asset->$type->contentTypePageConfigurations);
- }
- }
- setSite($asset,$type);
- removeIds($asset->$type);
- unset($asset->$type->path);
- if ($verbose>1) echo "Creating: $type " . $path . "\n";
- if ($verbose==1) echo ".";
- if (!$dryrun) {
- $writeClient->create($asset);
- if ($writeClient->success) {
- $newId[$ident->id] = $writeClient->createdAssetId;
- #echo "Created $type " . $newId[$ident->id] . "\n";
- remember($ident);
- } else {
- echo "\nFailed: $type " . $path . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- function checkContainer($id,$path,$type) {
- global $readClient, $writeClient;
- global $oldSite, $newSite;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- global $newId;
- if (isset($checked["$type.$path"])) {
- return;
- } else {
- $checked["$type.$path"] = 1;
- }
- #
- # read source asset
- #
- if ($verbose>2) out2("Checking $type $path...");
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = strtolower($type);
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- #
- # save asset id to get around CSI-108
- #
- $ident->id = $asset->$type->id;
- #
- # see if asset already exists in new location
- # (even if we know its newID, we still need to check for children)
- #
- if ($verbose>3) out3("Checking new $type $path ...");
- $newident->path = $path;
- $newident->siteName = $newSite;
- $newident->type = $ident->type;
- $writeClient->read($newident);
- if ($writeClient->success) {
- #
- # Note any children, since we don't need to create them
- #
- $newasset = $writeClient->asset;
- $newId[$asset->$type->id] = $newasset->$type->id;
- if (isset($newasset->$type->children)
- && isset($newasset->$type->children->child)) {
- $children = $newasset->$type->children->child;
- if (!is_array($children)) {
- $children = array( $children );
- }
- while ($cur = array_pop($children)) {
- $ctype = $cur->type;
- $cpath = $cur->path->path;
- if ($ctype == 'assetfactory') $ctype = 'assetFactory';
- if ($ctype == 'contenttype') $ctype = 'contentType';
- if ($ctype == 'metadataset') $ctype = 'metadataSet';
- if ($ctype == 'pageconfigurationset') $ctype = 'pageConfigurationSet';
- if ($ctype == 'publishset') $ctype = 'publishSet';
- if ($ctype == 'workflowdefinition') $ctype = 'workflowDefinition';
- if ($ctype == 'datadefinition') $ctype = 'dataDefinition';
- if (preg_match("/transport_.*/",$ctype)) {
- $ctype = "transport";
- }
- if (!preg_match('/container$/',$ctype)) {
- $checked["$ctype.$cpath"] = 1;
- }
- $newId["$ctype.$cpath"] = $cur->id;
- #if ($verbose>2) echo "Ok: $ctype $cpath\n";
- }
- }
- return;
- }
- if (isset($asset->$type->parentContainerPath)) {
- checkContainer($asset->$type->parentContainerId,$asset->$type->parentContainerPath,$type);
- }
- setSite($asset,$type);
- removeIds($asset->$type);
- unset($asset->$type->path);
- unset($asset->$type->children);
- if ($verbose) echo "Creating: $type " . $path . "\n";
- if (!$dryrun) {
- $writeClient->create($asset);
- if ($writeClient->success) {
- $newId[$ident->id] = $writeClient->createdAssetId;
- #echo "Created $type " . $newId[$ident->id] . "\n";
- remember($ident);
- } else {
- echo "\nFailed: $type " . $path . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- /*
- * Copy a container and its contents
- */
- function add_container($id,$path,$type) {
- global $oldPath;
- global $oldSite, $newSite;
- global $readClient, $writeClient;
- global $added;
- global $verbose;
- global $exit_on_error;
- #
- # have we already checked container *and* children?
- #
- if (isset($added["$type.$group"])) {
- return;
- } else {
- $added["$type.$path"] = 1;
- }
- #if ($verbose>2) echo "Adding $type $path...\n";
- #
- # create the container
- #
- if ($type == 'target') {
- checkTarget($path);
- } else {
- checkContainer($id,$path,$type);
- }
- #
- # and its children
- #
- if (isset($id)) {
- $ident->id = $id;
- }
- $ident->path = $path;
- $ident->siteName = $oldSite;
- $ident->type = strtolower($type);
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: $type " . $path . "\n";
- echo print_r($ident);
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- if (isset($asset->$type->children)
- && isset($asset->$type->children->child)) {
- $children = $asset->$type->children->child;
- if (!is_array($children)) {
- $children = array( $children );
- }
- } else {
- $children = "";
- }
- #
- # types of things we find in containers
- #
- $types = array(
- "assetFactoryContainer",
- "pageConfigurationSetContainer",
- "contentTypeContainer",
- "dataDefinitionContainer",
- "metadataSetContainer",
- "publishSetContainer",
- "siteDestinationContainer",
- "transportContainer",
- "workflowDefinitionContainer",
- "assetFactory",
- "pageConfigurationSet",
- "contentType",
- "dataDefinition",
- "metadataSet",
- "publishSet",
- "destination",
- "target",
- "transport",
- "workflowDefinition",
- "connectorContainer",
- "twitterConnector",
- "wordPressConnector",
- "googleAnalyticsConnector",
- );
- $names['transport_db'] = 'transport';
- $names['transport_fs'] = 'transport';
- $names['transport_ftp'] = 'transport';
- foreach ($types as $type) {
- $names[strtolower($type)] = $type;
- }
- if (is_array($children)) {
- while ($cur = array_pop($children)) {
- if (array_key_exists($cur->type,$names)) {
- if (preg_match('/container$/',$cur->type)) {
- add_container($cur->id, $cur->path->path, $names[$cur->type]);
- } else if ($cur->type == 'target') {
- checkTarget($cur->path->path);
- add_container($cur->id, $cur->path->path, $names[$cur->type]);
- } else {
- checkAdminAsset($cur->id, $cur->path->path, $names[$cur->type]);
- }
- } else {
- echo "Oops: don't know what to do with "
- . $cur->type . " " . $cur->path->path . "\n";
- }
- }
- }
- }
- #
- # We want assets if they are in the original site and path,
- # or if they already exist in the new site and path.
- # When we find references to assets we don't want, we
- # try to change them, e.g. when creating a group, if we don't
- # want the groupBaseFolder, then unset this field.
- #
- function want($path,$type) {
- global $readClient, $writeClient;
- global $oldPath;
- global $newSite;
- global $want;
- if (isset($want["$type.$path"])) {
- return($want["$type.$path"]);
- }
- $homearea = array(
- 'block', 'file', 'folder', 'page', 'reference', 'xsltFormat',
- 'scriptFormat', 'symlink', 'template' );
- if (in_array($type,$homearea)) {
- $checkPath = $oldPath;
- } else if ($type == 'transport') {
- $checkPath = 'FTP and SFTP/' . $oldPath;
- } else if ($type == 'group') {
- $checkPath = preg_replace(",/,", "|", $oldPath); # match any component
- } else {
- $checkPath = preg_replace("#^www/#","",$oldPath);
- }
- if (preg_match("#^$checkPath#", $path)
- || preg_match("#^$path(/|$)#",$checkPath)) {
- # we want it for sure
- $want["$type.$path"] = true;
- return(true);
- } else {
- # we only want it if it already exists
- if ($type == 'group' || $type == 'user') {
- $ident->id = getName($path);
- } else {
- $ident->path = getPath($path);
- }
- $ident->type = strtolower($type);
- $ident->siteName = $newSite;
- $writeClient->read($ident);
- if ($writeClient->success) {
- $want["$type.$path"] = true;
- return(true);
- }
- }
- $want["$type.$path"] = false;
- return(false);
- }
- function checkGroup($group) {
- global $readClient, $writeClient;
- global $oldPath;
- global $newSite;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- $type = "group";
- if (isset($checked["$type.$group"])) {
- return;
- } else {
- $checked["$type.$group"] = 1;
- }
- if ($verbose>2) out2("Checking $type " . getName($group) . "...");
- $ident->id = getName($group);
- $ident->type = strtolower($type);
- $writeClient->read($ident);
- if (!$writeClient->success) {
- $ident->id = $group;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: " . $group . "\n";
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- $asset->$type->groupName = getName($group);
- #
- # only keep members with accounts in new environment
- #
- global $host, $host2;
- if ($host != $host2 && isset($asset->$type->users)) {
- $users = preg_split('/;/',$asset->$type->users);
- $newusers = array();
- foreach ($users as &$user) {
- $ident->id = $user;
- $ident->type = 'user';
- $writeClient->read($ident);
- if ($writeClient->success) {
- array_push($newusers,$user);
- } else {
- if ($verbose>1) echo "*** Skipping user $user\n";
- }
- }
- $asset->$type->users = join(';',$newusers);
- }
- removeIds($asset->$type);
- if (want($asset->$type->groupAssetFactoryContainerPath,'assetFactoryContainer')) {
- checkContainer($asset->$type->groupAssetFactoryContainerId,$asset->$type->groupAssetFactoryContainerPath,'assetFactoryContainer');
- } else {
- if ($verbose>1) echo "*** Adjusting groupAssetFactoryContainerPath in $type $group\n";
- $asset->$type->groupAssetFactoryContainerPath = null;
- }
- if (isset($asset->$type->groupStartingPagePath)) {
- if (want($asset->$type->groupStartingPagePath,'page')) {
- checkAsset($asset->id,$asset->$type->groupStartingPagePath,'page');
- $asset->$type->groupStartingPagePath =
- getPath($asset->$type->groupStartingPagePath);
- } else {
- if ($verbose>1) echo "*** Adjusting groupStartingPagePath in $type $group\n";
- $asset->$type->groupStartingPagePath = null;
- }
- }
- if (isset($asset->$type->groupBaseFolderPath)) {
- if (want($asset->$type->groupBaseFolderPath,'folder')) {
- checkFolder($asset->$type->$groupBaseFolderId,$asset->$type->groupBaseFolderPath);
- $asset->$type->groupBaseFolderPath =
- getPath($asset->$type->groupBaseFolderPath);
- } else {
- if ($verbose>1) echo "*** Adjusting groupBaseFolderPath in $type $group\n";
- $asset->$type->groupBaseFolderPath = null;
- }
- }
- if ($verbose) echo "Creating: $type " . getName($group) . "\n";
- if (!$dryrun) {
- $writeClient->create($asset);
- if (!$writeClient->success) {
- if (!preg_match('/already exists/', $writeClient->message)) {
- echo "\nFailed: $type " . getName($group) . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- }
- }
- function checkUser($user) {
- global $readClient, $writeClient;
- global $newSite;
- global $dryrun;
- global $verbose;
- global $checked;
- global $exit_on_error;
- $type = "user";
- if (isset($checked["$type.$user"])) {
- return;
- } else {
- $checked["$type.$user"] = 1;
- }
- if ($verbose>2) out2("Checking $type " . getName($user) . "...");
- $ident->id = getName($user);
- $ident->type = strtolower($type);
- $writeClient->read($ident);
- if (!$writeClient->success) {
- $ident->id = $user;
- $readClient->read($ident);
- if (!$readClient->success) {
- echo "Failed reading: " . $user . "\n";
- echo cleanup($readClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- $asset = $readClient->asset;
- if (isset($asset->$type->defaultGroup)) {
- checkGroup($asset->$type->defaultGroup);
- $asset->$type->defaultGroup =
- getName($asset->$type->defaultGroup);
- }
- if (isset($asset->$type->groups)) {
- $groups = preg_split('/;/',$asset->$type->groups);
- $newgroups = array();
- foreach ($groups as &$group) {
- if (getName($group) == $asset->$type->defaultGroup) {
- array_push($newgroups,getName($group));
- } else if (want($group,'group')) {
- checkGroup($group);
- array_push($newgroups,getName($group));
- }
- }
- $asset->$type->groups = join(';',$newgroups);
- }
- echo "*** Can't set password on $type: $user\n";
- if ($verbose) echo "Creating: $type " . getName($user) . "\n";
- if (!$dryrun) {
- $writeClient->create($asset);
- if (!$writeClient->success) {
- echo "\nFailed: $type " . getName($user) . "\n";
- print_r($asset);
- echo cleanup($writeClient->response);
- if ($exit_on_error) cleanexit(); else return;
- }
- }
- }
- }
- /*
- * Gets the new folder path, by converting it from the old to the new
- */
- function getPath($folderPath) {
- global $oldPath;
- global $newPath;
- if (!isset($folderPath)) {
- return($folderPath);
- }
- if ($folderPath[0] == "/") {
- $folderPath = substr($folderPath, 1);
- }
- //if it's in t…
Large files files are truncated, but you can click here to view the full file