PageRenderTime 59ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/index.php

https://github.com/earlfogel/Cascade-to-Cascade-Migration-Scripts
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

  1. <?php
  2. /*
  3. This script copies assets between sites in Cascade or from one
  4. instance of Cascade to another. You can recursively copy folders
  5. or containers and all their contents, or copy entire sites.
  6. This is version 1.6.5 for Cascade 7
  7. Based on the copy-folder script in Hannon Hill's CAST toolkit.
  8. */
  9. error_reporting(E_ALL ^ E_NOTICE); # ignore undefined variables
  10. ini_set("display_errors",1);
  11. ini_set("max_execution_time",600);
  12. ini_set("memory_limit",'512M');
  13. include_once("cascade_soap_lib.php");
  14. /* Configuration */
  15. $environments = array(
  16. 'Cascade Development' => 'dev.example.edu',
  17. 'Cascade Test' => 'test.example.edu',
  18. 'Cascade Production' => 'prod.example.edu',
  19. );
  20. $secure = 1; # whether to use http or https to connect to web services
  21. /* You shouldn't have to change anything below this line */
  22. $verbose = 2;
  23. $dryrun = 0;
  24. $exit_on_error = 1;
  25. $inherit_permissions = 0;
  26. $copytype = 'folder';
  27. $oldPath = '/';
  28. $firstPass = false;
  29. $multiPass = false;
  30. ob_implicit_flush(true);
  31. ob_end_flush();
  32. ?>
  33. <!-- Latest compiled and minified CSS -->
  34. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
  35. <!-- Latest compiled and minified JavaScript -->
  36. <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
  37. <?php
  38. if (!empty($_POST) && validateInput()) {
  39. showForm();
  40. echo "<pre>";
  41. if ($dryrun) out1("Dry Run");
  42. if ($multiPass) {
  43. $firstPass = true;
  44. out1("First pass...");
  45. }
  46. update();
  47. setPermissions();
  48. if ($multiPass) {
  49. $firstPass = false;
  50. echo "</pre>";
  51. echo "<pre>";
  52. out1("Second pass...");
  53. editPages();
  54. editPageConfigurationSets();
  55. }
  56. if ($dryrun) {
  57. out1("Dry Run Complete");
  58. } else {
  59. out1("Done.");
  60. }
  61. echo "</pre>";
  62. } else {
  63. showForm();
  64. }
  65. function update() {
  66. global $host, $host2;
  67. global $uname, $uname2;
  68. global $pass, $pass2;
  69. global $oldPath, $newPath;
  70. global $oldSite, $newSite;
  71. global $readClient, $writeClient;
  72. global $copytype;
  73. global $dryrun;
  74. global $verbose;
  75. global $secure;
  76. $proto = 'http';
  77. if ($secure) $proto = 'https';
  78. $readClient = new CascadeSoapClient();
  79. if (preg_match('/^http/', $host)) {
  80. $readClient->url = $host . "/ws/services/AssetOperationService?wsdl";
  81. } else {
  82. $readClient->url = "$proto://" . $host . "/ws/services/AssetOperationService?wsdl";
  83. }
  84. $readClient->username = $uname;
  85. $readClient->password = $pass;
  86. $readClient->connect();
  87. $writeClient = new CascadeSoapClient();
  88. if (preg_match('/^http/', $host2)) {
  89. $writeClient->url = $host2 . "/ws/services/AssetOperationService?wsdl";
  90. } else {
  91. $writeClient->url = "$proto://$host2/ws/services/AssetOperationService?wsdl";
  92. }
  93. $writeClient->username = $uname2;
  94. $writeClient->password = $pass2;
  95. $writeClient->connect();
  96. if ($oldSite == 'Global')
  97. $oldSite = '';
  98. if ($newSite == 'Global')
  99. $newSite = '';
  100. #
  101. # admin areas to include when we copy sites
  102. #
  103. $adminAreas = array(
  104. 'assetFactory', 'contentType', 'dataDefinition',
  105. 'metadataSet', 'pageConfigurationSet', 'publishSet',
  106. 'workflowDefinition'
  107. );
  108. if ($oldSite == '' && $newSite == '') { # old "sites"
  109. array_push($adminAreas, 'target');
  110. } else if ($oldSite != '' && $newSite != '') { # new "Sites"
  111. array_push($adminAreas, 'transport');
  112. array_push($adminAreas, 'destination');
  113. }
  114. echo "Copying $copytype $host/$oldSite:$oldPath to $host2/$newSite:$newPath\n";
  115. if ($copytype == 'folder' || $copytype == 'site') {
  116. add_folder(NULL,$oldPath);
  117. } else if (preg_match('/Container$/',$copytype)) {
  118. add_container(NULL,$oldPath,$copytype);
  119. } else if (in_array($copytype,$adminAreas)) {
  120. checkAdminAsset(NULL,$oldPath,$copytype);
  121. } else if ($copytype == 'user') { // copy one or more users
  122. $oldPaths = preg_split("/ +/", $oldPath);
  123. foreach ($oldPaths as &$oldPath) {
  124. checkUser($oldPath);
  125. }
  126. } else if ($copytype == 'group') { // copy one or more groups
  127. $oldPaths = preg_split("/ +/", $oldPath);
  128. foreach ($oldPaths as &$oldPath) {
  129. checkGroup($oldPath);
  130. }
  131. } else { // home area asset
  132. checkAsset(NULL,$oldPath,$copytype);
  133. }
  134. if ($copytype == 'site') {
  135. $checkPath = preg_replace("#^.*/#","/",$oldPath);
  136. foreach ($adminAreas as &$adminArea) {
  137. if ($verbose>2) out2("\nChecking ${adminArea}s ...");
  138. if ($adminArea == 'destination') {
  139. $type = "siteDestinationContainer";
  140. } else if ($adminArea == 'target') {
  141. $type = "target";
  142. } else {
  143. $type = $adminArea . "Container";
  144. }
  145. add_container(NULL,$checkPath,$type);
  146. }
  147. }
  148. }
  149. /*
  150. * On the second pass, edit the pages that are in the structuredPages array
  151. */
  152. function editPages() {
  153. global $oldPath;
  154. global $oldSite, $newSite;
  155. global $readClient, $writeClient;
  156. global $added;
  157. global $exit_on_error;
  158. global $structuredPages;
  159. //if it's the second pass and there are pages to edit
  160. if(is_array($structuredPages)) {
  161. //loop through each page and get the page from read and update write based on it
  162. foreach($structuredPages as $pagePath) {
  163. //get the page from the readClient
  164. $readAsset = getReadAsset($pagePath, "page");
  165. $writeAsset = getWriteAsset($pagePath, "page");
  166. //replace the write page DD with the read DD
  167. $writeAsset->page->structuredData = $readAsset->page->structuredData;
  168. adjustStructuredData(
  169. $writeAsset->page->path,
  170. $writeAsset->page->structuredData->structuredDataNodes);
  171. //edit the asset on the writeClient
  172. updateWriteAsset("page", $writeAsset);
  173. } //end foreach structured page
  174. } //end if structured pages and second pass
  175. return true;
  176. }
  177. /*
  178. * On the second pass, edit the pages that are in the structuredPages array
  179. */
  180. function editPageConfigurationSets() {
  181. global $oldPath;
  182. global $oldSite, $newSite;
  183. global $readClient, $writeClient;
  184. global $pageConfigurationSets;
  185. $type = "pageConfigurationSet";
  186. //if it's the second pass and there are pages to edit
  187. if(is_array($pageConfigurationSets)) {
  188. //edit each config set, copying pageConfigurations from source asset
  189. foreach($pageConfigurationSets as $path) {
  190. //get the asset from the readClient
  191. $readAsset = getReadAsset($path, $type);
  192. $writeAsset = getWriteAsset($path, $type);
  193. //replace the write page configurations with the read
  194. $writeAsset->$type->pageConfigurations =
  195. $readAsset->$type->pageConfigurations;
  196. adjustPageConfigurations($path,$writeAsset->$type->pageConfigurations);
  197. //edit the asset on the writeClient
  198. updateWriteAsset($type, $writeAsset);
  199. }
  200. }
  201. return true;
  202. }
  203. /*
  204. * read the asset from the oldSite and return the object
  205. */
  206. function getReadAsset($path, $type) {
  207. global $oldPath;
  208. global $oldSite, $newSite;
  209. global $readClient, $writeClient;
  210. global $exit_on_error;
  211. if (isset($id)) {
  212. $ident->id = $id;
  213. }
  214. $ident->path = $path;
  215. $ident->siteName = $oldSite;
  216. $ident->type = strtolower($type);
  217. $readClient->read($ident);
  218. if (!$readClient->success) {
  219. echo "getReadAsset(): Read failure on $type $path: " . cleanup($readClient->response);
  220. print_r($ident);
  221. if ($exit_on_error) cleanexit(); else return;
  222. }
  223. return $readClient->asset;
  224. }
  225. /*
  226. * read the asset from the newSite and return the object
  227. */
  228. function getWriteAsset($path, $type) {
  229. global $oldPath;
  230. global $oldSite, $newSite;
  231. global $readClient, $writeClient;
  232. global $exit_on_error;
  233. if (isset($id)) {
  234. $ident->id = $id;
  235. }
  236. $ident->path = $path;
  237. $ident->siteName = $newSite;
  238. $ident->type = strtolower($type);
  239. $writeClient->read($ident);
  240. if (!$writeClient->success) {
  241. echo "getWriteAsset(): Read failure on $type $path: " . cleanup($writeClient->response);
  242. print_r($ident);
  243. if ($exit_on_error) cleanexit(); else return;
  244. }
  245. return $writeClient->asset;
  246. }
  247. /*
  248. * update the asset on the newSite
  249. */
  250. function updateWriteAsset($type, $writeAsset) {
  251. global $readClient, $writeClient;
  252. global $dryrun;
  253. global $verbose;
  254. global $exit_on_error;
  255. global $newId;
  256. if (!$dryrun) {
  257. $writeClient->edit($writeAsset);
  258. if (!$writeClient->success) {
  259. echo "updateWriteAsset(): Failed: " . $writeAsset->$type->path . "\n";
  260. print_r($writeAsset);
  261. echo cleanup($writeClient->response);
  262. print_r($readAsset);
  263. if ($exit_on_error) cleanexit(); else return false;
  264. } //is not successful write
  265. } //if not dry run
  266. if($verbose>1) echo "Updated $type " . $writeAsset->$type->path . "\n";
  267. return true;
  268. }
  269. /*
  270. * Get the ID of the asset on the newSite given the path and type
  271. */
  272. function getWriteAssetID($path, $type) {
  273. global $oldPath;
  274. global $oldSite, $newSite;
  275. global $readClient, $writeClient;
  276. $ident->path = $path;
  277. $ident->siteName = $newSite;
  278. $ident->type = $type;
  279. $writeClient->read($ident);
  280. if (!$writeClient->success) {
  281. echo "getWriteAssetID('$path', '$type'): Read failure on $type $path: " . cleanup($writeClient->response);
  282. print_r($ident);
  283. if ($exit_on_error) cleanexit(); else return;
  284. }
  285. return $writeClient->asset->$type->id;
  286. }
  287. /*
  288. * Read the folder, push its children, make the folder, then pop remaining children
  289. */
  290. function add_folder($id,$path) {
  291. global $oldPath;
  292. global $oldSite, $newSite;
  293. global $readClient, $writeClient;
  294. global $folderStack;
  295. global $pageStack;
  296. global $refStack;
  297. global $genericStack;
  298. global $templateStack;
  299. global $skipPattern;
  300. global $added;
  301. global $exit_on_error;
  302. $type = 'folder';
  303. #
  304. # have we already checked folder *and* children?
  305. #
  306. if (isset($added["$type.$path"])) {
  307. return;
  308. } else {
  309. $added["$type.$path"] = 1;
  310. }
  311. if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
  312. echo "*** Skipping $type $path\n";
  313. return;
  314. }
  315. #
  316. # create the folder itself
  317. #
  318. checkFolder($id, $path);
  319. #
  320. # and its children
  321. #
  322. if (isset($id)) {
  323. $ident->id = $id;
  324. }
  325. $ident->path = $path;
  326. $ident->siteName = $oldSite;
  327. $ident->type = "folder";
  328. $readClient->read($ident);
  329. if (!$readClient->success) {
  330. echo "Failed reading: $type " . $path . "\n";
  331. echo print_r($ident);
  332. echo cleanup($readClient->response);
  333. if ($exit_on_error) cleanexit(); else return;
  334. }
  335. $asset = $readClient->asset;
  336. if (isset($asset->$type->children)
  337. && isset($asset->$type->children->child)) {
  338. $children = $asset->$type->children->child;
  339. if (!is_array($children)) {
  340. $children = array( $children );
  341. }
  342. } else {
  343. $children = "";
  344. }
  345. if (is_array($children)) {
  346. while ($cur = array_pop($children)) {
  347. if ($cur->type == "folder") {
  348. $folderStack[] = $cur;
  349. } else if ($cur->type == "page") {
  350. $pageStack[] = $cur;
  351. } else if ($cur->type == "reference") {
  352. $refStack[] = $cur;
  353. } else if ($cur->type == "template") {
  354. $templateStack[] = $cur;
  355. } else {
  356. $genericStack[] = $cur;
  357. }
  358. }
  359. }
  360. if (is_array($folderStack)) {
  361. while ($cur = array_pop($folderStack)) {
  362. add_folder($cur->id,$cur->path->path);
  363. }
  364. }
  365. if (is_array($genericStack)) {
  366. while ($cur = array_pop($genericStack)) {
  367. checkAsset($cur->id,$cur->path->path, $cur->type);
  368. }
  369. }
  370. if (is_array($templateStack)) {
  371. while ($cur = array_pop($templateStack)) {
  372. checkAsset($cur->id,$cur->path->path, $cur->type);
  373. }
  374. }
  375. if (is_array($pageStack)) {
  376. while ($cur = array_pop($pageStack)) {
  377. checkAsset($cur->id,$cur->path->path, $cur->type);
  378. }
  379. }
  380. if (is_array($refStack)) {
  381. while ($cur = array_pop($refStack)) {
  382. checkAsset($cur->id,$cur->path->path, $cur->type);
  383. }
  384. }
  385. }
  386. /*
  387. * Read in the file, block, symlink, or ... and add it directly
  388. */
  389. function checkAsset($id, $path, $type) {
  390. global $oldPath, $newPath;
  391. global $oldSite, $newSite;
  392. global $readClient, $writeClient;
  393. global $skipPattern;
  394. global $dryrun;
  395. global $verbose;
  396. global $checked;
  397. global $exit_on_error;
  398. global $newId;
  399. global $targetStuff;
  400. global $firstPass;
  401. global $structuredPages;
  402. if (preg_match("/block_.*/",$type)) {
  403. $type = "block";
  404. } else if (preg_match("/format_.*/",$type)) {
  405. $type = "format";
  406. }
  407. #
  408. # see if we've already checked it
  409. #
  410. if (isset($checked["$type.$path"])) {
  411. if ($verbose>3) out3("*** Checking $type: " . getPath($path) . " (we've been here before)");
  412. return;
  413. } else {
  414. $checked["$type.$path"] = 1;
  415. }
  416. if ($dryrun && $type == 'file' && $verbose<2) {
  417. return; # speed things up a bit
  418. }
  419. if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
  420. echo "*** Skipping $type $path\n";
  421. return;
  422. }
  423. #
  424. # reference to another site
  425. #
  426. if (preg_match('/^(.*):(.*)/',$path,$matches)) {
  427. global $host, $host2;
  428. if ($host == $host2) {
  429. if ($verbose>2) out2("Ok: $type $path");
  430. return;
  431. } else {
  432. $site = $matches[1];
  433. $path = $matches[2];
  434. if ($verbose>2) out2("Checking $type $site:$path");
  435. $newident->path = $path;
  436. $newident->siteName = $site;
  437. $newident->type = strtolower($type);
  438. $writeClient->read($newident);
  439. if (!$writeClient->success) {
  440. if (preg_match('/Unable to identify an entity/',$writeClient->response)) {
  441. echo "
  442. *** Found cross-site reference to $site $type $path, which does not exist in the
  443. target environment. You must change this before the copy can proceed.
  444. ";
  445. } else {
  446. echo "Failed reading: " . $site . ': ' . $path . "\n";
  447. echo print_r($newident);
  448. echo cleanup($writeClient->response);
  449. }
  450. if ($exit_on_error) cleanexit(); else return;
  451. }
  452. return;
  453. }
  454. }
  455. #
  456. # read source asset
  457. #
  458. if ($verbose>2) out2("Checking $type $path");
  459. if (isset($id)) {
  460. $ident->id = $id;
  461. }
  462. $ident->path = $path;
  463. $ident->siteName = $oldSite;
  464. $ident->type = $type;
  465. $readClient->read($ident);
  466. if (!$readClient->success) {
  467. echo "Read failure on $type $path: " . cleanup($readClient->response);
  468. print_r($ident);
  469. if ($exit_on_error) cleanexit(); else return;
  470. }
  471. $asset = $readClient->asset;
  472. $otype = $type;
  473. if (!isset($asset->$type)) {
  474. if (isset($asset->indexBlock)) {
  475. $type = "indexBlock";
  476. } else if (isset($asset->textBlock)) {
  477. $type = "textBlock";
  478. } else if (isset($asset->feedBlock)) {
  479. $type = "feedBlock";
  480. } else if (isset($asset->xmlBlock)) {
  481. $type = "xmlBlock";
  482. } else if (isset($asset->xhtmlBlock)) {
  483. $type = "xhtmlBlock";
  484. } else if (isset($asset->xhtmlDataDefinitionBlock)) {
  485. $type = "xhtmlDataDefinitionBlock";
  486. } else if (isset($asset->xsltFormat)) {
  487. $type = "xsltFormat";
  488. } else if (isset($asset->scriptFormat)) {
  489. $type = "scriptFormat";
  490. }
  491. }
  492. #
  493. # workaround http://issues.hannonhill.com/browse/CSI-145
  494. # if asset is in a different site, we're done
  495. # (this should never happen)
  496. #
  497. if ($asset->$type->siteName != $oldSite) {
  498. global $host, $host2;
  499. if ($host == $host2) {
  500. $newId[$id] = $id;
  501. }
  502. if ($verbose>2)
  503. out2("Skipping $type $path (site " . $asset->$type->siteName . "!=" . $oldSite . ")");
  504. return;
  505. }
  506. //remove the structured data from the page on the first pass
  507. if($firstPass && isset($asset->page->structuredData)) {
  508. unset($asset->page->structuredData);
  509. $structuredPages[$asset->page->path] = $asset->page->path;
  510. }
  511. #
  512. # save asset id to get around CSI-108
  513. #
  514. $ident->id = $asset->$type->id;
  515. #
  516. # see if asset already exists in new location
  517. #
  518. $parent = preg_replace("#/[^/]*$#", "", $path);
  519. if (isset($checked["folder.$parent"])) {
  520. # we know it doesn't exist
  521. } else if (isset($newId["$otype.$path"])) {
  522. # we know it does exist
  523. $newId[$asset->$type->id] = $newId["$otype.$path"];
  524. return;
  525. } else {
  526. if ($verbose>3) out3("Checking new $type: " . getPath($path));
  527. $newident->path = getPath($path);
  528. $newident->siteName = $newSite;
  529. $newident->type = $ident->type;
  530. $writeClient->read($newident);
  531. if ($writeClient->success) {
  532. $newasset = $writeClient->asset;
  533. $newId[$asset->$type->id] = $newasset->$type->id;
  534. return;
  535. } else if (preg_match('/Unable to identify/',$writeClient->response)) {
  536. } else {
  537. echo "Read failure on destination: " . getPath($path) . cleanup($writeClient->response);
  538. print_r($newident);
  539. if ($exit_on_error) cleanexit(); else return;
  540. }
  541. }
  542. if ($type == 'xsltFormat') {
  543. $asset->$type->xml = preg_replace(
  544. '#1.0"xmlns#', '1.0" xmlns', $asset->$type->xml);
  545. }
  546. if ($type == 'file' || preg_match('/\.css$/',$asset->$type->name)) {
  547. $asset->$type->data =
  548. preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
  549. '/renderfile/global$1', $asset->$type->data);
  550. $asset->$type->text =
  551. preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
  552. '/renderfile/global$1', $asset->$type->text);
  553. }
  554. if ($type == 'page' && $oldPath != $newPath) {
  555. $asset->$type->xhtml = preg_replace(
  556. "#$oldPath#", $newPath, $asset->$type->xhtml);
  557. }
  558. # remove [system-asset] tags from symlinks
  559. if ($type == 'symlink' && isset($asset->$type->linkURL)) {
  560. $asset->$type->linkURL =
  561. preg_replace('#\[system-asset(?::id=\w+)?\]([^\[]*)\[/system-asset\]#',
  562. '$1', $asset->$type->linkURL);
  563. }
  564. if (isset($asset->$type->parentFolderPath)) {
  565. checkFolder($asset->$type->parentFolderId,$asset->$type->parentFolderPath);
  566. $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath);
  567. }
  568. if (isset($asset->$type->metadataSetPath)) {
  569. checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
  570. }
  571. if (isset($asset->$type->configurationSetPath)) {
  572. checkAdminAsset($asset->$type->configurationSetId,$asset->$type->configurationSetPath,'pageConfigurationSet');
  573. } else {
  574. unset($asset->$type->configurationSetPath);
  575. }
  576. if (isset($asset->$type->contentTypePath)) {
  577. checkAdminAsset($asset->$type->contentTypeId,$asset->$type->contentTypePath,"contentType");
  578. }
  579. if (isset($asset->$type->indexedContentTypePath)) {
  580. checkAdminAsset($asset->$type->IndexedContentTypeId,$asset->$type->indexedContentTypePath,"contentType");
  581. }
  582. if (isset($asset->$type->indexedFolderPath)) {
  583. if (want($asset->$type->indexedFolderPath,'folder')) {
  584. checkAsset($asset->id,$asset->$type->indexedFolderPath,'folder');
  585. $asset->$type->indexedFolderPath = getPath($asset->$type->indexedFolderPath);
  586. } else {
  587. if ($verbose>1) echo "*** Adjusting indexedFolderPath in $type $path\n";
  588. $asset->$type->indexedFolderPath = null;
  589. }
  590. } else {
  591. # silly php, if it's not set, why do we need to unset it?
  592. if ($type == 'indexBlock') {
  593. #echo "*** Removing indexedFolderPath in $type $path\n";
  594. unset($asset->$type->indexedFolderPath);
  595. }
  596. }
  597. if (isset($asset->$type->expirationFolderPath)) {
  598. if (want($asset->$type->expirationFolderPath,'folder')) {
  599. checkAsset($asset->id,$asset->$type->expirationFolderPath,'folder');
  600. $asset->$type->expirationFolderPath = getPath($asset->$type->expirationFolderPath);
  601. } else {
  602. if ($verbose>1) echo "Adjusting expirationFolderPath in $type $path\n";
  603. $asset->$type->expirationFolderPath = null;
  604. }
  605. }
  606. if (isset($asset->$type->formatPath)) {
  607. checkAsset($asset->id,$asset->$type->formatPath,'format');
  608. $asset->$type->formatPath = getPath($asset->$type->formatPath);
  609. }
  610. if (isset($asset->$type->targetPath)) {
  611. if ($newSite) {
  612. # sites don't have targets, but we may need the file extension
  613. $targetStuff["$type.$path"] = getTargetStuff($asset->$type->targetPath);
  614. unset($asset->$type->targetPath);
  615. } else {
  616. checkTarget($asset->$type->targetPath);
  617. }
  618. }
  619. if (isset($asset->$type->structuredData) &&
  620. is_string($asset->$type->structuredData->definitionPath)) {
  621. checkAdminAsset($asset->$type->structuredData->definitionId,$asset->$type->structuredData->definitionPath,'dataDefinition');
  622. }
  623. if (isset($asset->$type->structuredData) &&
  624. isset($asset->$type->structuredData->structuredDataNodes)) {
  625. adjustStructuredData($path,$asset->$type->structuredData->structuredDataNodes);
  626. unset($asset->$type->structuredData->definitionId);
  627. } else {
  628. unset($asset->$type->structuredData);
  629. }
  630. if (isset($asset->$type->pageConfigurations)) {
  631. adjustPageConfigurations($asset->$type->configurationSetPath,$asset->$type->pageConfigurations);
  632. }
  633. if (isset($asset->$type->pageRegions)) {
  634. adjustPageRegions($path,$asset->$type->pageRegions);
  635. }
  636. if (isset($asset->$type->referencedAssetId)) {
  637. if ($asset->$type->referencedAssetType == 'folder') {
  638. checkFolder($asset->$type->referencedAssetId,$asset->$type->referencedAssetPath);
  639. } else {
  640. checkAsset($asset->id,$asset->$type->referencedAssetPath,
  641. $asset->$type->referencedAssetType);
  642. }
  643. $asset->$type->referencedAssetPath =
  644. getPath($asset->$type->referencedAssetPath);
  645. }
  646. setSite($asset,$type);
  647. removeIds($asset->$type);
  648. unset($asset->$type->path);
  649. if (isset($asset->$type->data)) {
  650. unset($asset->$type->text);
  651. //$asset->$type->data = base64_decode($asset->$type->data);
  652. }
  653. if ($verbose>1) echo "Creating: $type " . getPath($path) . "\n";
  654. if ($verbose==1) echo ".";
  655. if (!$dryrun) {
  656. $writeClient->create($asset);
  657. if ($writeClient->success) {
  658. $newId[$ident->id] = $writeClient->createdAssetId;
  659. #echo "Created $type " . $newId[$ident->id] . "\n";
  660. remember($ident);
  661. } else {
  662. echo "Failed: $type " . getPath($path) . "\n";
  663. if (isset($asset->$type->data)) {
  664. $asset->$type->data = "*** data ***";
  665. }
  666. print_r($asset);
  667. echo cleanup($writeClient->response);
  668. if ($exit_on_error) cleanexit(); else return;
  669. }
  670. }
  671. }
  672. function checkTarget($path) {
  673. global $readClient, $writeClient;
  674. global $oldSite, $newSite;
  675. global $dryrun;
  676. global $verbose;
  677. global $checked;
  678. global $exit_on_error;
  679. $type = "target";
  680. if (isset($checked["$type.$path"])) {
  681. return;
  682. } else {
  683. $checked["$type.$path"] = 1;
  684. }
  685. if ($path == '/') {
  686. return;
  687. }
  688. if ($verbose>2) out2("Checking $type $path ...");
  689. $ident->path = $path;
  690. $ident->siteName = $newSite;
  691. $ident->type = $type;
  692. $writeClient->read($ident);
  693. if (!$writeClient->success) {
  694. $ident->siteName = $oldSite;
  695. $readClient->read($ident);
  696. if (!$readClient->success) {
  697. echo "Failed reading: $type " . $path . "\n";
  698. echo print_r($ident);
  699. echo cleanup($readClient->response);
  700. if ($exit_on_error) cleanexit(); else return;
  701. }
  702. $asset = $readClient->asset;
  703. #
  704. # save asset id to get around CSI-108
  705. #
  706. $ident->id = $asset->$type->id;
  707. if ($asset->$type->parentTargetPath != "") {
  708. checkTarget($asset->$type->parentTargetPath);
  709. }
  710. $asset->$type->baseFolderPath = getPath($asset->$type->baseFolderPath);
  711. if ($asset->$type->cssFilePath != "") {
  712. checkAsset($asset->$type->cssFileId,$asset->$type->cssFilePath,'file');
  713. $asset->$type->cssFilePath = getPath($asset->$type->cssFilePath);
  714. }
  715. if ($asset->$type->publishIntervalUnits == "Hours") {
  716. $asset->$type->publishIntervalUnits = "hours";
  717. }
  718. setSite($asset,$type);
  719. removeIds($asset->$type);
  720. unset($asset->$type->path);
  721. unset($asset->$type->children);
  722. if ($verbose>1) echo "Creating: $type " . $path . "\n";
  723. if (!$dryrun) {
  724. $writeClient->create($asset);
  725. if ($writeClient->success) {
  726. remember($ident);
  727. } else {
  728. echo "\nFailed: $type " . $path . "\n";
  729. print_r($asset);
  730. echo cleanup($writeClient->response);
  731. if ($exit_on_error) cleanexit(); else return;
  732. }
  733. }
  734. }
  735. }
  736. function getTargetStuff($path) {
  737. global $readClient;
  738. global $oldSite;
  739. global $verbose;
  740. global $checked;
  741. global $exit_on_error;
  742. global $targetStuff;
  743. $type = "target";
  744. if (!isset($targetStuff["$type.$path"])) {
  745. if ($verbose>2) out2("Checking $type $path ...");
  746. $ident->path = $path;
  747. $ident->siteName = $oldSite;
  748. $ident->type = $type;
  749. $readClient->read($ident);
  750. if (!$readClient->success) {
  751. echo "Failed reading: $type " . $path . "\n";
  752. echo print_r($ident);
  753. echo cleanup($readClient->response);
  754. if ($exit_on_error) cleanexit(); else return;
  755. }
  756. $asset = $readClient->asset;
  757. $targetStuff["$type.$path"] =
  758. array($asset->$type->outputExtension, $asset->$type->serializationType);
  759. }
  760. return($targetStuff["$type.$path"]);
  761. }
  762. function checkFolder($id,$path) {
  763. global $readClient, $writeClient;
  764. global $oldPath, $newPath;
  765. global $oldSite, $newSite;
  766. global $skipPattern;
  767. global $dryrun;
  768. global $verbose;
  769. global $checked;
  770. global $exit_on_error;
  771. global $newId;
  772. $type = 'folder';
  773. if (isset($checked["$type.$path"])) {
  774. return;
  775. } else {
  776. $checked["$type.$path"] = 1;
  777. }
  778. if (isset($skipPattern) && preg_match("#$skipPattern#i",$path)) {
  779. echo "*** Skipping $type $path\n";
  780. return;
  781. }
  782. # if (!preg_match("#^$oldPath(/|$)#",$path)
  783. # && !preg_match("#^$path(/|$)#",$oldPath)) {
  784. # echo "*** Skipping $path\n";
  785. # return; # don't back up too far
  786. # }
  787. #
  788. # read source asset
  789. #
  790. if ($verbose>2) out2("Checking $type $path...");
  791. if (isset($id)) {
  792. $ident->id = $id;
  793. }
  794. $ident->path = $path;
  795. $ident->siteName = $oldSite;
  796. $ident->type = $type;
  797. $readClient->read($ident);
  798. if (!$readClient->success) {
  799. echo "Failed reading: $type " . $path . "\n";
  800. echo print_r($ident);
  801. echo cleanup($readClient->response);
  802. if ($exit_on_error) cleanexit(); else return;
  803. }
  804. $asset = $readClient->asset;
  805. #
  806. # save asset id to get around CSI-108
  807. #
  808. $ident->id = $asset->$type->id;
  809. #
  810. # see if asset already exists in new location
  811. # (even if we know its newID, we still need to check for children)
  812. #
  813. if ($verbose>3) out3("Checking new $type " . getPath($path) . " ...");
  814. $newident->path = getPath($path);
  815. $newident->siteName = $newSite;
  816. $newident->type = $ident->type;
  817. $writeClient->read($newident);
  818. if ($writeClient->success) {
  819. #
  820. # Note any children, since we don't need to create them
  821. #
  822. $newasset = $writeClient->asset;
  823. $newId[$asset->$type->id] = $newasset->$type->id;
  824. #echo "Found2 new Id for $type $path\n";
  825. if (isset($newasset->$type->children)
  826. && isset($newasset->$type->children->child)) {
  827. $children = $newasset->$type->children->child;
  828. if (!is_array($children)) {
  829. $children = array( $children );
  830. }
  831. #echo "Folder $path in $newSite has children\n";
  832. while ($cur = array_pop($children)) {
  833. $ctype = $cur->type;
  834. $cpath = $cur->path->path;
  835. #echo "Child $ctype $cpath\n";
  836. if (preg_match("/block_.*/",$ctype)) {
  837. $ctype = "block";
  838. } else if (preg_match("/format_.*/",$ctype)) {
  839. $ctype = "format";
  840. }
  841. if ($ctype != 'folder') {
  842. $checked["$ctype.$cpath"] = 1;
  843. }
  844. $newId["$ctype.$cpath"] = $cur->id;
  845. #echo "Saving new Id " . $cur->id . " for $ctype $cpath\n";
  846. #if ($verbose>2) echo "Ok: $ctype $cpath\n";
  847. }
  848. }
  849. return;
  850. }
  851. #
  852. # we need to create it
  853. #
  854. if (isset($asset->$type->parentFolderPath)) {
  855. checkFolder($asset->$type->parentFolderId,$asset->$type->parentFolderPath);
  856. }
  857. #
  858. # if this is the main folder we're copying, we may need to rename it
  859. #
  860. if ($path == $oldPath) {
  861. $oldName = preg_replace(",^.*/,", "", $oldPath);
  862. $newName = preg_replace(",^.*/,", "", $newPath);
  863. if ($oldName != $newName) {
  864. $asset->$type->name = $newName;
  865. }
  866. }
  867. $asset->$type->parentFolderPath = getPath($asset->$type->parentFolderPath);
  868. checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
  869. setSite($asset,$type);
  870. removeIds($asset->$type);
  871. unset($asset->$type->path);
  872. unset($asset->$type->children);
  873. if ($verbose) echo "Creating: $type " . getPath($path) . "\n";
  874. if (!$dryrun) {
  875. $writeClient->create($asset);
  876. if ($writeClient->success) {
  877. $newId[$ident->id] = $writeClient->createdAssetId;
  878. #echo "Created $type " . $newId[$ident->id] . "\n";
  879. remember($ident);
  880. } else {
  881. echo "\nFailed: $type " . getPath($path) . "\n";
  882. print_r($asset);
  883. echo cleanup($writeClient->response);
  884. if ($exit_on_error) cleanexit(); else return;
  885. }
  886. }
  887. }
  888. function checkAdminAsset($id,$path,$type) {
  889. global $readClient, $writeClient;
  890. global $host, $host2;
  891. global $oldSite, $newSite;
  892. global $dryrun;
  893. global $verbose;
  894. global $checked;
  895. global $exit_on_error;
  896. global $newId;
  897. global $firstPass;
  898. global $pageConfigurationSets;
  899. if (isset($checked["$type.$path"])) {
  900. return;
  901. } else {
  902. $checked["$type.$path"] = 1;
  903. }
  904. #
  905. # reference to another site
  906. #
  907. if (preg_match('/^(.*):(.*)/',$path,$matches)) {
  908. global $host, $host2;
  909. if ($host == $host2) {
  910. if ($verbose>2) out2("Ok: $type $path");
  911. return;
  912. } else {
  913. $site = $matches[1];
  914. $path = $matches[2];
  915. if ($verbose>2) out2("Checking $type $site:$path");
  916. $newident->path = $path;
  917. $newident->siteName = $site;
  918. $newident->type = strtolower($type);
  919. $writeClient->read($newident);
  920. if (!$writeClient->success) {
  921. if (preg_match('/Unable to identify an entity/',$writeClient->response)) {
  922. echo "
  923. *** Found cross-site reference to $site $type $path, which does not exist
  924. in target environment. You must change this before the copy can proceed.
  925. ";
  926. } else {
  927. echo "Failed reading: " . $site . ': ' . $path . "\n";
  928. echo print_r($newident);
  929. echo cleanup($writeClient->response);
  930. }
  931. if ($exit_on_error) cleanexit(); else return;
  932. }
  933. return;
  934. }
  935. }
  936. #
  937. # read source asset
  938. #
  939. if ($verbose>2) out2("Checking $type $path");
  940. if (isset($id)) {
  941. $ident->id = $id;
  942. }
  943. $ident->path = $path;
  944. $ident->siteName = $oldSite;
  945. $ident->type = strtolower($type);
  946. $readClient->read($ident);
  947. if (!$readClient->success) {
  948. echo "Read failure on $type $path: " . cleanup($readClient->response);
  949. echo print_r($ident);
  950. if ($exit_on_error) cleanexit(); else return;
  951. }
  952. $asset = $readClient->asset;
  953. $otype = $type;
  954. $container = $type.'Container';
  955. if ($type == 'destination') {
  956. if($oldSite == '') {
  957. $container = 'target';
  958. } else {
  959. $container = 'siteDestinationContainer';
  960. }
  961. } else if (preg_match('/Connector$/', $type)) {
  962. $container = 'connectorContainer';
  963. }
  964. if (!isset($asset->$type)) {
  965. if (isset($asset->fileSystemTransport)) {
  966. $type = "fileSystemTransport";
  967. $container = "transportContainer";
  968. } else if (isset($asset->ftpTransport)) {
  969. $type = "ftpTransport";
  970. $container = "transportContainer";
  971. } else if (isset($asset->databaseTransport)) {
  972. $type = "databaseTransport";
  973. $container = "transportContainer";
  974. } else if (isset($asset->metadataSet)) {
  975. $type = "metadataSet";
  976. $container = "metadataSetContainer";
  977. }
  978. }
  979. #
  980. # save asset id to get around CSI-108
  981. #
  982. $ident->id = $asset->$type->id;
  983. #
  984. # see if asset already exists in new location
  985. #
  986. $parent = preg_replace("#/[^/]*$#", "", $path);
  987. if (isset($checked["$container.$parent"])) {
  988. # we know it doesn't exist
  989. #echo "Not checking $type: $path (it can't exist)\n";
  990. } else if (isset($newId["$otype.$path"])) {
  991. # we know it does exist
  992. $newId[$asset->$type->id] = $newId["$otype.$path"];
  993. #echo "Found new Id for $type $path\n";
  994. return;
  995. } else {
  996. if ($verbose>3) out3("Checking new $type $path");
  997. $newident->path = $path;
  998. $newident->siteName = $newSite;
  999. $newident->type = $ident->type;
  1000. $writeClient->read($newident);
  1001. if ($writeClient->success) {
  1002. $newasset = $writeClient->asset;
  1003. $newId[$asset->$type->id] = $newasset->$type->id;
  1004. #echo "Found2 new Id for $type $path\n";
  1005. return;
  1006. } else if (preg_match('/Unable to identify/',$writeClient->response)) {
  1007. #echo "Can't find $type " . $ident->path . " in $newSite\n";
  1008. } else {
  1009. echo "Read failure on destination: " . getPath($path) . cleanup($writeClient->response);
  1010. print_r($newident);
  1011. if ($exit_on_error) cleanexit(); else return;
  1012. }
  1013. }
  1014. if (isset($asset->fileSystemTransport)) {
  1015. if (!$asset->$type->directory) {
  1016. echo "*** Skipping $type $path: directory is required\n";
  1017. return;
  1018. }
  1019. } else if (isset($asset->ftpTransport)) {
  1020. echo "*** Can't set password on $type: $path\n";
  1021. $asset->$type->password = 'UNKNOWN';
  1022. } else if (isset($asset->databaseTransport)) {
  1023. // Cascade 6.7.3 WS can't create database transport with siteId=0
  1024. //$asset->$type->transportSiteId = 1;
  1025. }
  1026. if (isset($asset->$type->parentContainerPath)) {
  1027. if ($type == 'destination' && $oldSite == '') {
  1028. checkTarget($asset->$type->parentContainerPath);
  1029. } else {
  1030. checkContainer($asset->$type->parentContainerId,$asset->$type->parentContainerPath,$container);
  1031. }
  1032. }
  1033. if ($type == 'destination') {
  1034. if (isset($asset->$type->transportPath)) {
  1035. checkAdminAsset($asset->$type->transportId,$asset->$type->transportPath,'transport');
  1036. }
  1037. }
  1038. if ($type == 'assetFactory') {
  1039. if ($asset->$type->assetType == 'format') {
  1040. # see http://issues.hannonhill.com/browse/CSI-222
  1041. echo "*** Skipping asset factory of type 'format': " . $path . "\n";
  1042. return;
  1043. }
  1044. if (isset($asset->$type->assetType) && isset($asset->$type->baseAssetPath)) {
  1045. if ($asset->$type->assetType == 'folder') {
  1046. checkFolder($asset->$type->baseAssetId,$asset->$type->baseAssetPath);
  1047. } else {
  1048. checkAsset($asset->id,$asset->$type->baseAssetPath,$asset->$type->assetType);
  1049. }
  1050. }
  1051. if (isset($asset->$type->placementFolderPath)) {
  1052. checkFolder($asset->$type->placementFolderId,$asset->$type->placementFolderPath);
  1053. }
  1054. # as per CSCD-4324 asset factory's with multiple applicable groups do not persist
  1055. if (isset($asset->$type->applicableGroups)) {
  1056. $asset->$type->applicableGroups =
  1057. preg_replace("/,/", ";", $asset->$type->applicableGroups);
  1058. }
  1059. if (isset($asset->$type->workflowDefinitionPath)) {
  1060. checkAdminAsset($asset->$type->workflowDefinitionId,$asset->$type->workflowDefinitionPath,'workflowDefinition');
  1061. }
  1062. } else if ($type == 'pageConfigurationSet') {
  1063. if (isset($asset->$type->pageConfigurations)) {
  1064. if($firstPass && $host == $host2 && $oldSite != '' && $newSite != '') {
  1065. // To avoid dependency loops when copying between sites,
  1066. // where both sites are in the same instance of Cascade,
  1067. // on the first pass we make an exact copy of the configuration sets
  1068. // (where all regions and templates refer to the original site)
  1069. // We record this here and fix it on the second pass
  1070. $pageConfigurationSets[$asset->$type->path] = $asset->$type->path;
  1071. } else {
  1072. //update configurations to point to the new site
  1073. adjustPageConfigurations($path,$asset->$type->pageConfigurations);
  1074. }
  1075. }
  1076. if ($oldSite == '' && $newSite != '') {
  1077. #echo "*** Please set Output File Extension in $type $path\n";
  1078. }
  1079. } else if ($type == 'publishSet') {
  1080. foreach (array('pages','files','folders') as $pstype) {
  1081. $area = $asset->$type->$pstype;
  1082. if (isset($area->publishableAssetIdentifier) &&
  1083. isset($area->publishableAssetIdentifier)) {
  1084. $children = $area->publishableAssetIdentifier;
  1085. if (!is_array($children)) {
  1086. $children = array( $children );
  1087. }
  1088. #echo "*** Removing Ids from $pstype in $path\n";
  1089. foreach ($children as &$item) {
  1090. unset($item->id);
  1091. }
  1092. }
  1093. }
  1094. } else if ($type == 'contentType') {
  1095. if (isset($asset->$type->metadataSetPath)) {
  1096. checkAdminAsset($asset->$type->metadataSetId,$asset->$type->metadataSetPath,'metadataSet');
  1097. }
  1098. if (isset($asset->$type->pageConfigurationSetPath)) {
  1099. checkAdminAsset($asset->$type->pageConfigurationSetId,$asset->$type->pageConfigurationSetPath,'pageConfigurationSet');
  1100. }
  1101. if (isset($asset->$type->dataDefinitionPath)) {
  1102. checkAdminAsset($asset->$type->dataDefinitionId,$asset->$type->dataDefinitionPath,'dataDefinition');
  1103. }
  1104. if (isset($asset->$type->contentTypePageConfigurations)) {
  1105. adjustPageConfigurations($asset->$type->pageConfigurationSetPath,$asset->$type->contentTypePageConfigurations);
  1106. }
  1107. }
  1108. setSite($asset,$type);
  1109. removeIds($asset->$type);
  1110. unset($asset->$type->path);
  1111. if ($verbose>1) echo "Creating: $type " . $path . "\n";
  1112. if ($verbose==1) echo ".";
  1113. if (!$dryrun) {
  1114. $writeClient->create($asset);
  1115. if ($writeClient->success) {
  1116. $newId[$ident->id] = $writeClient->createdAssetId;
  1117. #echo "Created $type " . $newId[$ident->id] . "\n";
  1118. remember($ident);
  1119. } else {
  1120. echo "\nFailed: $type " . $path . "\n";
  1121. print_r($asset);
  1122. echo cleanup($writeClient->response);
  1123. if ($exit_on_error) cleanexit(); else return;
  1124. }
  1125. }
  1126. }
  1127. function checkContainer($id,$path,$type) {
  1128. global $readClient, $writeClient;
  1129. global $oldSite, $newSite;
  1130. global $dryrun;
  1131. global $verbose;
  1132. global $checked;
  1133. global $exit_on_error;
  1134. global $newId;
  1135. if (isset($checked["$type.$path"])) {
  1136. return;
  1137. } else {
  1138. $checked["$type.$path"] = 1;
  1139. }
  1140. #
  1141. # read source asset
  1142. #
  1143. if ($verbose>2) out2("Checking $type $path...");
  1144. if (isset($id)) {
  1145. $ident->id = $id;
  1146. }
  1147. $ident->path = $path;
  1148. $ident->siteName = $oldSite;
  1149. $ident->type = strtolower($type);
  1150. $readClient->read($ident);
  1151. if (!$readClient->success) {
  1152. echo "Failed reading: $type " . $path . "\n";
  1153. echo print_r($ident);
  1154. echo cleanup($readClient->response);
  1155. if ($exit_on_error) cleanexit(); else return;
  1156. }
  1157. $asset = $readClient->asset;
  1158. #
  1159. # save asset id to get around CSI-108
  1160. #
  1161. $ident->id = $asset->$type->id;
  1162. #
  1163. # see if asset already exists in new location
  1164. # (even if we know its newID, we still need to check for children)
  1165. #
  1166. if ($verbose>3) out3("Checking new $type $path ...");
  1167. $newident->path = $path;
  1168. $newident->siteName = $newSite;
  1169. $newident->type = $ident->type;
  1170. $writeClient->read($newident);
  1171. if ($writeClient->success) {
  1172. #
  1173. # Note any children, since we don't need to create them
  1174. #
  1175. $newasset = $writeClient->asset;
  1176. $newId[$asset->$type->id] = $newasset->$type->id;
  1177. if (isset($newasset->$type->children)
  1178. && isset($newasset->$type->children->child)) {
  1179. $children = $newasset->$type->children->child;
  1180. if (!is_array($children)) {
  1181. $children = array( $children );
  1182. }
  1183. while ($cur = array_pop($children)) {
  1184. $ctype = $cur->type;
  1185. $cpath = $cur->path->path;
  1186. if ($ctype == 'assetfactory') $ctype = 'assetFactory';
  1187. if ($ctype == 'contenttype') $ctype = 'contentType';
  1188. if ($ctype == 'metadataset') $ctype = 'metadataSet';
  1189. if ($ctype == 'pageconfigurationset') $ctype = 'pageConfigurationSet';
  1190. if ($ctype == 'publishset') $ctype = 'publishSet';
  1191. if ($ctype == 'workflowdefinition') $ctype = 'workflowDefinition';
  1192. if ($ctype == 'datadefinition') $ctype = 'dataDefinition';
  1193. if (preg_match("/transport_.*/",$ctype)) {
  1194. $ctype = "transport";
  1195. }
  1196. if (!preg_match('/container$/',$ctype)) {
  1197. $checked["$ctype.$cpath"] = 1;
  1198. }
  1199. $newId["$ctype.$cpath"] = $cur->id;
  1200. #if ($verbose>2) echo "Ok: $ctype $cpath\n";
  1201. }
  1202. }
  1203. return;
  1204. }
  1205. if (isset($asset->$type->parentContainerPath)) {
  1206. checkContainer($asset->$type->parentContainerId,$asset->$type->parentContainerPath,$type);
  1207. }
  1208. setSite($asset,$type);
  1209. removeIds($asset->$type);
  1210. unset($asset->$type->path);
  1211. unset($asset->$type->children);
  1212. if ($verbose) echo "Creating: $type " . $path . "\n";
  1213. if (!$dryrun) {
  1214. $writeClient->create($asset);
  1215. if ($writeClient->success) {
  1216. $newId[$ident->id] = $writeClient->createdAssetId;
  1217. #echo "Created $type " . $newId[$ident->id] . "\n";
  1218. remember($ident);
  1219. } else {
  1220. echo "\nFailed: $type " . $path . "\n";
  1221. print_r($asset);
  1222. echo cleanup($writeClient->response);
  1223. if ($exit_on_error) cleanexit(); else return;
  1224. }
  1225. }
  1226. }
  1227. /*
  1228. * Copy a container and its contents
  1229. */
  1230. function add_container($id,$path,$type) {
  1231. global $oldPath;
  1232. global $oldSite, $newSite;
  1233. global $readClient, $writeClient;
  1234. global $added;
  1235. global $verbose;
  1236. global $exit_on_error;
  1237. #
  1238. # have we already checked container *and* children?
  1239. #
  1240. if (isset($added["$type.$group"])) {
  1241. return;
  1242. } else {
  1243. $added["$type.$path"] = 1;
  1244. }
  1245. #if ($verbose>2) echo "Adding $type $path...\n";
  1246. #
  1247. # create the container
  1248. #
  1249. if ($type == 'target') {
  1250. checkTarget($path);
  1251. } else {
  1252. checkContainer($id,$path,$type);
  1253. }
  1254. #
  1255. # and its children
  1256. #
  1257. if (isset($id)) {
  1258. $ident->id = $id;
  1259. }
  1260. $ident->path = $path;
  1261. $ident->siteName = $oldSite;
  1262. $ident->type = strtolower($type);
  1263. $readClient->read($ident);
  1264. if (!$readClient->success) {
  1265. echo "Failed reading: $type " . $path . "\n";
  1266. echo print_r($ident);
  1267. echo cleanup($readClient->response);
  1268. if ($exit_on_error) cleanexit(); else return;
  1269. }
  1270. $asset = $readClient->asset;
  1271. if (isset($asset->$type->children)
  1272. && isset($asset->$type->children->child)) {
  1273. $children = $asset->$type->children->child;
  1274. if (!is_array($children)) {
  1275. $children = array( $children );
  1276. }
  1277. } else {
  1278. $children = "";
  1279. }
  1280. #
  1281. # types of things we find in containers
  1282. #
  1283. $types = array(
  1284. "assetFactoryContainer",
  1285. "pageConfigurationSetContainer",
  1286. "contentTypeContainer",
  1287. "dataDefinitionContainer",
  1288. "metadataSetContainer",
  1289. "publishSetContainer",
  1290. "siteDestinationContainer",
  1291. "transportContainer",
  1292. "workflowDefinitionContainer",
  1293. "assetFactory",
  1294. "pageConfigurationSet",
  1295. "contentType",
  1296. "dataDefinition",
  1297. "metadataSet",
  1298. "publishSet",
  1299. "destination",
  1300. "target",
  1301. "transport",
  1302. "workflowDefinition",
  1303. "connectorContainer",
  1304. "twitterConnector",
  1305. "wordPressConnector",
  1306. "googleAnalyticsConnector",
  1307. );
  1308. $names['transport_db'] = 'transport';
  1309. $names['transport_fs'] = 'transport';
  1310. $names['transport_ftp'] = 'transport';
  1311. foreach ($types as $type) {
  1312. $names[strtolower($type)] = $type;
  1313. }
  1314. if (is_array($children)) {
  1315. while ($cur = array_pop($children)) {
  1316. if (array_key_exists($cur->type,$names)) {
  1317. if (preg_match('/container$/',$cur->type)) {
  1318. add_container($cur->id, $cur->path->path, $names[$cur->type]);
  1319. } else if ($cur->type == 'target') {
  1320. checkTarget($cur->path->path);
  1321. add_container($cur->id, $cur->path->path, $names[$cur->type]);
  1322. } else {
  1323. checkAdminAsset($cur->id, $cur->path->path, $names[$cur->type]);
  1324. }
  1325. } else {
  1326. echo "Oops: don't know what to do with "
  1327. . $cur->type . " " . $cur->path->path . "\n";
  1328. }
  1329. }
  1330. }
  1331. }
  1332. #
  1333. # We want assets if they are in the original site and path,
  1334. # or if they already exist in the new site and path.
  1335. # When we find references to assets we don't want, we
  1336. # try to change them, e.g. when creating a group, if we don't
  1337. # want the groupBaseFolder, then unset this field.
  1338. #
  1339. function want($path,$type) {
  1340. global $readClient, $writeClient;
  1341. global $oldPath;
  1342. global $newSite;
  1343. global $want;
  1344. if (isset($want["$type.$path"])) {
  1345. return($want["$type.$path"]);
  1346. }
  1347. $homearea = array(
  1348. 'block', 'file', 'folder', 'page', 'reference', 'xsltFormat',
  1349. 'scriptFormat', 'symlink', 'template' );
  1350. if (in_array($type,$homearea)) {
  1351. $checkPath = $oldPath;
  1352. } else if ($type == 'transport') {
  1353. $checkPath = 'FTP and SFTP/' . $oldPath;
  1354. } else if ($type == 'group') {
  1355. $checkPath = preg_replace(",/,", "|", $oldPath); # match any component
  1356. } else {
  1357. $checkPath = preg_replace("#^www/#","",$oldPath);
  1358. }
  1359. if (preg_match("#^$checkPath#", $path)
  1360. || preg_match("#^$path(/|$)#",$checkPath)) {
  1361. # we want it for sure
  1362. $want["$type.$path"] = true;
  1363. return(true);
  1364. } else {
  1365. # we only want it if it already exists
  1366. if ($type == 'group' || $type == 'user') {
  1367. $ident->id = getName($path);
  1368. } else {
  1369. $ident->path = getPath($path);
  1370. }
  1371. $ident->type = strtolower($type);
  1372. $ident->siteName = $newSite;
  1373. $writeClient->read($ident);
  1374. if ($writeClient->success) {
  1375. $want["$type.$path"] = true;
  1376. return(true);
  1377. }
  1378. }
  1379. $want["$type.$path"] = false;
  1380. return(false);
  1381. }
  1382. function checkGroup($group) {
  1383. global $readClient, $writeClient;
  1384. global $oldPath;
  1385. global $newSite;
  1386. global $dryrun;
  1387. global $verbose;
  1388. global $checked;
  1389. global $exit_on_error;
  1390. $type = "group";
  1391. if (isset($checked["$type.$group"])) {
  1392. return;
  1393. } else {
  1394. $checked["$type.$group"] = 1;
  1395. }
  1396. if ($verbose>2) out2("Checking $type " . getName($group) . "...");
  1397. $ident->id = getName($group);
  1398. $ident->type = strtolower($type);
  1399. $writeClient->read($ident);
  1400. if (!$writeClient->success) {
  1401. $ident->id = $group;
  1402. $readClient->read($ident);
  1403. if (!$readClient->success) {
  1404. echo "Failed reading: " . $group . "\n";
  1405. echo cleanup($readClient->response);
  1406. if ($exit_on_error) cleanexit(); else return;
  1407. }
  1408. $asset = $readClient->asset;
  1409. $asset->$type->groupName = getName($group);
  1410. #
  1411. # only keep members with accounts in new environment
  1412. #
  1413. global $host, $host2;
  1414. if ($host != $host2 && isset($asset->$type->users)) {
  1415. $users = preg_split('/;/',$asset->$type->users);
  1416. $newusers = array();
  1417. foreach ($users as &$user) {
  1418. $ident->id = $user;
  1419. $ident->type = 'user';
  1420. $writeClient->read($ident);
  1421. if ($writeClient->success) {
  1422. array_push($newusers,$user);
  1423. } else {
  1424. if ($verbose>1) echo "*** Skipping user $user\n";
  1425. }
  1426. }
  1427. $asset->$type->users = join(';',$newusers);
  1428. }
  1429. removeIds($asset->$type);
  1430. if (want($asset->$type->groupAssetFactoryContainerPath,'assetFactoryContainer')) {
  1431. checkContainer($asset->$type->groupAssetFactoryContainerId,$asset->$type->groupAssetFactoryContainerPath,'assetFactoryContainer');
  1432. } else {
  1433. if ($verbose>1) echo "*** Adjusting groupAssetFactoryContainerPath in $type $group\n";
  1434. $asset->$type->groupAssetFactoryContainerPath = null;
  1435. }
  1436. if (isset($asset->$type->groupStartingPagePath)) {
  1437. if (want($asset->$type->groupStartingPagePath,'page')) {
  1438. checkAsset($asset->id,$asset->$type->groupStartingPagePath,'page');
  1439. $asset->$type->groupStartingPagePath =
  1440. getPath($asset->$type->groupStartingPagePath);
  1441. } else {
  1442. if ($verbose>1) echo "*** Adjusting groupStartingPagePath in $type $group\n";
  1443. $asset->$type->groupStartingPagePath = null;
  1444. }
  1445. }
  1446. if (isset($asset->$type->groupBaseFolderPath)) {
  1447. if (want($asset->$type->groupBaseFolderPath,'folder')) {
  1448. checkFolder($asset->$type->$groupBaseFolderId,$asset->$type->groupBaseFolderPath);
  1449. $asset->$type->groupBaseFolderPath =
  1450. getPath($asset->$type->groupBaseFolderPath);
  1451. } else {
  1452. if ($verbose>1) echo "*** Adjusting groupBaseFolderPath in $type $group\n";
  1453. $asset->$type->groupBaseFolderPath = null;
  1454. }
  1455. }
  1456. if ($verbose) echo "Creating: $type " . getName($group) . "\n";
  1457. if (!$dryrun) {
  1458. $writeClient->create($asset);
  1459. if (!$writeClient->success) {
  1460. if (!preg_match('/already exists/', $writeClient->message)) {
  1461. echo "\nFailed: $type " . getName($group) . "\n";
  1462. print_r($asset);
  1463. echo cleanup($writeClient->response);
  1464. if ($exit_on_error) cleanexit(); else return;
  1465. }
  1466. }
  1467. }
  1468. }
  1469. }
  1470. function checkUser($user) {
  1471. global $readClient, $writeClient;
  1472. global $newSite;
  1473. global $dryrun;
  1474. global $verbose;
  1475. global $checked;
  1476. global $exit_on_error;
  1477. $type = "user";
  1478. if (isset($checked["$type.$user"])) {
  1479. return;
  1480. } else {
  1481. $checked["$type.$user"] = 1;
  1482. }
  1483. if ($verbose>2) out2("Checking $type " . getName($user) . "...");
  1484. $ident->id = getName($user);
  1485. $ident->type = strtolower($type);
  1486. $writeClient->read($ident);
  1487. if (!$writeClient->success) {
  1488. $ident->id = $user;
  1489. $readClient->read($ident);
  1490. if (!$readClient->success) {
  1491. echo "Failed reading: " . $user . "\n";
  1492. echo cleanup($readClient->response);
  1493. if ($exit_on_error) cleanexit(); else return;
  1494. }
  1495. $asset = $readClient->asset;
  1496. if (isset($asset->$type->defaultGroup)) {
  1497. checkGroup($asset->$type->defaultGroup);
  1498. $asset->$type->defaultGroup =
  1499. getName($asset->$type->defaultGroup);
  1500. }
  1501. if (isset($asset->$type->groups)) {
  1502. $groups = preg_split('/;/',$asset->$type->groups);
  1503. $newgroups = array();
  1504. foreach ($groups as &$group) {
  1505. if (getName($group) == $asset->$type->defaultGroup) {
  1506. array_push($newgroups,getName($group));
  1507. } else if (want($group,'group')) {
  1508. checkGroup($group);
  1509. array_push($newgroups,getName($group));
  1510. }
  1511. }
  1512. $asset->$type->groups = join(';',$newgroups);
  1513. }
  1514. echo "*** Can't set password on $type: $user\n";
  1515. if ($verbose) echo "Creating: $type " . getName($user) . "\n";
  1516. if (!$dryrun) {
  1517. $writeClient->create($asset);
  1518. if (!$writeClient->success) {
  1519. echo "\nFailed: $type " . getName($user) . "\n";
  1520. print_r($asset);
  1521. echo cleanup($writeClient->response);
  1522. if ($exit_on_error) cleanexit(); else return;
  1523. }
  1524. }
  1525. }
  1526. }
  1527. /*
  1528. * Gets the new folder path, by converting it from the old to the new
  1529. */
  1530. function getPath($folderPath) {
  1531. global $oldPath;
  1532. global $newPath;
  1533. if (!isset($folderPath)) {
  1534. return($folderPath);
  1535. }
  1536. if ($folderPath[0] == "/") {
  1537. $folderPath = substr($folderPath, 1);
  1538. }
  1539. //if it's in t…

Large files files are truncated, but you can click here to view the full file