public static function assetTreeUpdatePageConfigurationSet(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { if (isset($params['source-cascade'])) { $source_cascade = $params['source-cascade']; } else { echo c\M::TARGET_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['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; } $source_pcs = $child->getAsset($service); $source_pcs_name = $source_pcs->getName(); $source_pcs_parent_path = $source_pcs->getParentContainerPath(); // the default definition $source_pcs_default_config = $source_pcs->getDefaultConfiguration(); $source_pcs_default_config_name = $source_pcs_default_config->getName(); $source_pcs_default_config_template_path = u\StringUtility::removeSiteNameFromPath($source_pcs_default_config->getTemplatePath()); $source_pcs_default_config_template_name = u\StringUtility::getNameFromPath($source_pcs_default_config_template_path); $source_pcs_default_config_template = $source_pcs_default_config->getTemplate(); $source_pcs_default_config_template_site = $source_pcs_default_config_template->getSiteName(); $source_pcs_default_config_extension = $source_pcs_default_config->getOutputExtension(); $source_pcs_default_config_type = $source_pcs_default_config->getSerializationType(); if (self::DEBUG) { u\DebugUtility::out("Extension: " . $source_pcs_default_config_extension . BR . "Type: " . $source_pcs_default_config_type); } $target_pcs_default_config_template_site = $source_pcs_default_config_template_site; try { // the template must be there $template = $target_cascade->getAsset(Template::TYPE, $source_pcs_default_config_template_path, $target_pcs_default_config_template_site); $target_site_name = $target_site->getName(); // parent must be there $target_parent = $target_cascade->getAsset(PageConfigurationSetContainer::TYPE, $source_pcs_parent_path, $target_site_name); $target_pcs = $target_cascade->createPageConfigurationSet($target_parent, $source_pcs_name, $source_pcs_default_config_name, $template, $source_pcs_default_config_extension, $source_pcs_default_config_type); // update other configuration sets $source_config_names = $source_pcs->getPageConfigurationNames(); foreach ($source_config_names as $source_config_name) { // retrieve config info $source_config = $source_pcs->getPageConfiguration($source_config_name); $source_template = $source_config->getTemplate(); $source_template_path = u\StringUtility::removeSiteNameFromPath($source_template->getPath()); $source_template_site = $source_template->getSiteName(); $target_template_site = $source_template_site; // template must be there $target_template = $target_cascade->getAsset(Template::TYPE, $source_template_path, $target_template_site); // add missing configurations if ($source_pcs_default_config_name != $source_config_name && !$target_pcs->hasPageConfiguration($source_config_name)) { $source_config_extension = $source_config->getOutputExtension(); $source_config_type = $source_config->getSerializationType(); $source_config_publishable = $source_config->getPublishable(); try { $target_config = $target_pcs->getPageConfiguration($source_config_name); } catch (e\NoSuchPageConfigurationException $e) { $target_pcs->addPageConfiguration($source_config_name, $target_template, $source_config_extension, $source_config_type); $target_config = $target_pcs->getPageConfiguration($source_config_name); } // update config $target_pcs->setOutputExtension($source_config_name, $source_config_extension); $target_pcs->setSerializationType($source_config_name, $source_config_type); $target_pcs->setPublishable($source_config_name, $source_config_publishable); } // config format!!! $source_config_format_id = $source_config->getFormatId(); if (isset($source_config_format_id)) { $source_config_format = $source_cascade->getXsltFormat($source_config_format_id); $source_config_format_path = u\StringUtility::removeSiteNameFromPath($source_config_format->getPath()); $source_config_format_site = $source_config_format->getSiteName(); $target_config_format_site = $source_config_format_site; try { if ($exception_thrown) { $target_format = $target_cascade->getAsset(XsltFormat::TYPE, $source_config_format_path, $target_config_format_site); } else { $target_format = $target_cascade->getXsltFormat($source_config_format_path, $target_config_format_site); } $source_config->setFormat($target_format); $target_pcs->edit(); } catch (\Exception $e) { $msg = "The format {$source_config_format_path} does not exist in {$target_config_format_site}. "; throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e); } } // set blocks and formats, if not $exception_thrown, skip missing ones $region_names = $target_template->getRegionNames(); if (count($region_names) > 0) { foreach ($region_names as $region_name) { if (!$source_pcs->hasPageRegion($source_config_name, $region_name)) { continue; } $source_block = $source_pcs->getPageRegion($source_config_name, $region_name)->getBlock(); $source_format = $source_pcs->getPageRegion($source_config_name, $region_name)->getFormat(); if ($source_block) { $source_block_path = u\StringUtility::removeSiteNameFromPath($source_block->getPath()); $source_block_site = $source_block->getSiteName(); $source_block_type = $source_block->getType(); $target_block_site = $source_block_site; try { if ($exception_thrown) { $target_block = $target_cascade->getAsset($source_block_type, $source_block_path, $target_block_site); } else { $class_name = c\T::getClassNameByType($source_block_type); $method = 'get' . $class_name; $target_block = $target_cascade->{$method}($source_block_path, $target_block_site); } $target_pcs->setConfigurationPageRegionBlock($source_config_name, $region_name, $target_block)->edit(); } catch (\Exception $e) { $msg = "The block {$source_block_path} does not exist in {$target_block_site}. "; throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e); } } if ($source_format) { $source_format_path = u\StringUtility::removeSiteNameFromPath($source_format->getPath()); $source_format_site = $source_format->getSiteName(); $source_format_type = $source_format->getType(); $target_format_site = $source_format_site; try { if ($exception_thrown) { $target_format = $target_cascade->getAsset($source_format_type, $source_format_path, $target_format_site); } else { $class_name = c\T::getClassNameByType($source_format_type); $method = 'get' . $class_name; $target_format = $target_cascade->{$method}($source_format_path, $target_format_site); } $target_pcs->setConfigurationPageRegionFormat($source_config_name, $region_name, $target_format); } catch (\Exception $e) { $msg = "The format {$source_format_path} does not exist in {$target_format_site}. "; throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e); } } } } $target_pcs->edit(); } } catch (\Exception $e) { //$msg = "The configuration set $source_pcs_default_config_template_path does not exist in $target_pcs_default_config_template_site. "; throw new e\CascadeInstancesErrorException($e); } }
echo "Tis true", BR; } else { echo "Tis false", BR; } if (u\StringUtility::stringToBool(0)) { echo "Tis true", BR; } else { echo "Tis false", BR; } if (u\StringUtility::stringToBool("")) { echo "Tis true", BR; } else { echo "Tis false", BR; } echo u\StringUtility::boolToString(true), BR; echo u\StringUtility::startsWith("Hello", "He") ? "yes" : "no", BR; echo u\StringUtility::startsWith("Hello", "e") ? "yes" : "no", BR; echo u\StringUtility::removeSiteNameFromPath("site://cascade-admin/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getParentPathFromPath("/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getNameFromPath("/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getMethodName("structuredData"), BR; u\DebugUtility::dump(u\StringUtility::getExplodedStringArray(";", "this;0;that;3;these")); echo u\StringUtility::getFullyQualifiedIdentifierWithoutPositions("this;0;that;3;these"), BR; echo u\StringUtility::endsWith("Hello", "lo") ? "yes" : "no", BR; echo u\StringUtility::endsWith("Hello", "l") ? "yes" : "no", BR; echo u\ReflectionUtility::getClassDocumentation("cascade_ws_utility\\StringUtility", true); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }