function assetTreeFixPhantomNodes(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { // skip entire folder if (strpos($child->getPathPath(), "_extra/") !== false) { return; } if (strpos($child->getPathPath(), "_cascade/") !== false) { return; } $type = $child->getType(); if ($type != a\Page::TYPE && $type != a\DataBlock::TYPE) { return; } try { $asset = $child->getAsset($service); if ($asset->hasPhantomNodes()) { $asset->mapData(); } } catch (e\NoSuchFieldException $e) { if ($type == a\Page::TYPE) { $asset = new a\PagePhantom($service, $child->toStdClass()); } else { $asset = new a\DataDefinitionBlockPhantom($service, $child->toStdClass()); } $dd = $asset->getDataDefinition(); $healthy_sd = new p\StructuredData($dd->getStructuredData(), $service, $dd->getId()); $phantom_sd = $asset->getStructuredDataPhantom(); $healthy_sd = $healthy_sd->removePhantomNodes($phantom_sd); $asset->setStructuredData($healthy_sd); } }
function assetTreeRemoveUnwantedPage(aohs\AssetOperationHandlerService $service, p\Child $child, array $params = NULL, array &$results = NULL) { if ($child->getType() != a\Page::TYPE) { return; } $page_path = $child->getPathPath(); // junk page names if (u\StringUtility::endsWith($page_path, "/pdf") || u\StringUtility::endsWith($page_path, "/word") || u\StringUtility::endsWith($page_path, "/externallink") || u\StringUtility::endsWith($page_path, "/keytiny") || u\StringUtility::endsWith($page_path, "/index-2")) { $service->delete($child->toStdClass()); } }
public static function assetTreeUpdateDataDefinitionBlock(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { if (isset($params['source-cascade'])) { $source_cascade = $params['source-cascade']; } else { echo c\M::SOURCE_CASCADE_NOT_SET . BR; return; } if (isset($params['target-cascade'])) { $target_cascade = $params['target-cascade']; } else { echo c\M::TARGET_CASCADE_NOT_SET . BR; return; } if (isset($params['source-site'])) { $source_site = $params['source-site']; } else { echo c\M::SOURCE_SITE_NOT_SET . BR; return; } if (isset($params['target-site'])) { $target_site = $params['target-site']; } else { echo c\M::TARGET_SITE_NOT_SET . BR; return; } if (isset($params['exception-thrown'])) { $exception_thrown = $params['exception-thrown']; } else { echo c\M::EXCEPTION_THROWN_NOT_SET . BR; return; } if (isset($params['update-data'])) { $update_data = $params['update-data']; } else { $update_data = true; } if (isset($params['update-metadata'])) { $update_metadata = $params['update-metadata']; } else { $update_metadata = true; } if (self::DEBUG && self::DUMP) { u\DebugUtility::out("Retrieving block"); u\DebugUtility::dump($child->toStdClass()); } try { $source_block = $child->getAsset($service); $source_block_path = u\StringUtility::removeSiteNameFromPath($source_block->getPath()); } catch (\Exception $e) { throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Path: " . $child->getPathPath() . E_SPAN); } $target_dd = NULL; // it will fail if there is any irregularity in the block if ($source_block->hasStructuredData()) { $source_block_dd = $source_block->getDataDefinition(); $source_block_dd_path = u\StringUtility::removeSiteNameFromPath($source_block_dd->getPath()); $source_block_dd_site = $source_block_dd->getSiteName(); $target_block_dd_site = $source_block_dd_site; // compare the two data definitions $source_dd = Asset::getAsset($service, DataDefinition::TYPE, $source_block_dd_path, $source_block_dd_site); // the data definition must be there $target_dd = $target_cascade->getAsset(DataDefinition::TYPE, $source_block_dd_path, $target_block_dd_site); $source_xml = new \SimpleXMLElement($source_dd->getXml()); $target_xml = new \SimpleXMLElement($target_dd->getXml()); if (!u\XMLUtility::isXmlIdentical($source_xml, $target_xml)) { throw new e\CascadeInstancesErrorException(S_SPAN . c\M::DIFFERENT_DATA_DEFINITIONS . E_SPAN); } $source_structured_data_std = $source_block->getStructuredData()->toStdClass(); $target_dd_id = $target_dd->getId(); $target_structured_data_std = $source_structured_data_std; $target_structured_data_std->definitionId = $target_dd_id; } else { $source_content = $source_block->getXhtml(); } $source_block_path_array = u\StringUtility::getExplodedStringArray("/", $source_block_path); $source_block_path = $source_block_path_array[count($source_block_path_array) - 1]; $source_block_parent_path = $source_block->getParentContainerPath(); // create block $target_site_name = $target_site->getName(); // parent must be there $target_parent = $target_cascade->getAsset(Folder::TYPE, $source_block_parent_path, $target_site_name); $target_block = $target_cascade->createXhtmlDataDefinitionBlock($target_parent, $source_block_path, $target_dd, $source_content); // update data if ($update_data) { if ($target_block->hasStructuredData()) { if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($target_structured_data_std); } try { $target_service = $target_cascade->getService(); $identifiers = $source_block->getIdentifiers(); $identifier_asset_map = array(); foreach ($identifiers as $identifier) { if ($source_block->isAssetNode($identifier)) { $block_id = $source_block->getBlockId($identifier); if (isset($block_id)) { $resource_id = $block_id; $source_resource_type = Block::getBlockType($service, $resource_id); } $file_id = $source_block->getFileId($identifier); if (isset($file_id)) { $resource_id = $file_id; $source_resource_type = File::TYPE; } $page_id = $source_block->getPageId($identifier); if (isset($page_id)) { $resource_id = $page_id; $source_resource_type = Page::TYPE; } $symlink_id = $source_block->getSymlinkId($identifier); if (isset($symlink_id)) { $resource_id = $symlink_id; $source_resource_type = Symlink::TYPE; } if (isset($resource_id)) { $source_resource = $service->retrieve($service->createId($source_resource_type, $resource_id)); if ($service->isSuccessful()) { $source_resource_site = $source_resource->siteName; $source_resource_path = $source_resource->path; $target_resource_site = $source_resource_site; try { $asset = $target_cascade->getAsset($source_resource_type, $source_resource_path, $source_resource_site); $identifier_asset_map[$identifier] = $asset; } catch (\Exception $e) { if ($exception_thrown) { throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Block: " . $source_block->getPath() . BR . "Resource: " . $source_resource_path . E_SPAN); } else { u\DebugUtility::out($e->getMessage() . BR . "<span style='color:red;font-weight:bold;'>" . "Block: " . $source_block->getPath() . BR . "Resource: " . $source_resource_path . "</span>"); } } } else { echo "Failed to retrieve resource." . BR; } // reinitialized for the next round $resource_id = NULL; } } } $identifiers = array_keys($identifier_asset_map); $count = count($identifiers); $structured_data = new p\StructuredData($target_structured_data_std, $target_service); if ($count > 0) { foreach ($identifiers as $identifier) { $asset = $identifier_asset_map[$identifier]; $type = $asset->getType(); switch ($type) { case 'file': $method = 'setFile'; break; case 'page': $method = 'setPage'; break; case 'symlink': $method = 'setSymlink'; break; default: $method = 'setBlock'; } if ($structured_data->hasNode($identifier)) { $structured_data->{$method}($identifier, $asset); } } } $target_block->setStructuredData($structured_data); } catch (\Exception $e) { if (self::DEBUG) { u\DebugUtility::out($child->getPathPath()); } } } } if ($update_metadata) { self::setMetadataSet($target_cascade, $source_site, $target_site, $source_block, $target_block, $exception_thrown); } }
function assetTreeRemoveAsset(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { if (is_array($results) && is_array($results[c\F::REPORT_ORPHANS]) && in_array($child->getPathPath(), $results[c\F::REPORT_ORPHANS][$child->getType()])) { if (isset($params[c\F::REMOVE_ASSET][c\F::UNCONDITIONAL_REMOVAL]) && $params[c\F::REMOVE_ASSET][c\F::UNCONDITIONAL_REMOVAL] == true) { $service->delete($child->toStdClass()); } else { if (!in_array($child->getId(), $params[c\F::REMOVE_ASSET][$child->getType()]) && !in_array($child->getPathPath(), $params[c\F::REMOVE_ASSET][$child->getType()])) { $service->delete($child->toStdClass()); } } } }