function assetTreeFindDDBlockPageWithIntialId(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    if (!isset($params['partial-id'])) {
        throw new \Exception("The id is not included");
    }
    $partial_id = $params['partial-id'];
    $type = $child->getType();
    if ($type != a\DataBlock::TYPE && $type != a\Page::TYPE) {
        return;
    }
    $id = $child->getId();
    if (!u\StringUtility::startsWith($id, $partial_id)) {
        return;
    } else {
        echo $id;
    }
}
 /**
  * Create an id object for an asset
  * @param string $type The type of the asset
  * @param string $id_path Either the id or the path of an asset
  * @param string $siteName The site name
  *
  * @return stdClass The identifier
  */
 public function createId($type, $id_path, $site_name = NULL)
 {
     if (!(is_string($type) && (is_string($id_path) || is_int($id_path)))) {
         throw new e\UnacceptableValueException("Only strings are accepted in createId.");
     }
     $non_digital_id_types = array(c\T::GROUP, c\T::ROLE, c\T::SITE, c\T::USER);
     $id_path = trim($id_path);
     if (strlen($id_path) > 1) {
         $id_path = trim($id_path);
         $id_path = trim($id_path, '/');
     }
     $identifier = new \stdClass();
     if ($this->isHexString($id_path)) {
         // if id string is passed in, ignore site name
         $identifier->id = $id_path;
     } else {
         if (in_array($type, $non_digital_id_types)) {
             if ($type != c\T::SITE) {
                 $identifier->id = $id_path;
             } else {
                 $identifier->path = new \stdClass();
                 $identifier->path->path = $id_path;
             }
         } else {
             if (u\StringUtility::startsWith($id_path, "ROOT_")) {
                 $identifier->id = $id_path;
             } else {
                 if ($site_name == NULL) {
                     $identifier->path = new \stdClass();
                     $identifier->path->path = $id_path;
                     $identifier->path->siteName = $site_name;
                 } else {
                     if (trim($site_name) == "") {
                         throw new e\EmptyValueException(S_SPAN . c\M::EMPTY_SITE_NAME . E_SPAN);
                     }
                     $identifier->path = new \stdClass();
                     $identifier->path->path = $id_path;
                     $identifier->path->siteName = $site_name;
                 }
             }
         }
     }
     $identifier->type = $type;
     return $identifier;
 }
 public static function assetTreeUpdateDestination(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;
     }
     $source_d = $child->getAsset($service);
     $source_d_name = $source_d->getName();
     $source_d_parent_path = $source_d->getParentContainerPath();
     $source_d_transport_id = $source_d->getTransportId();
     $source_d_transport_path = $source_d->getTransportPath();
     // fix the path if from Global by removing "Global:"
     if (u\StringUtility::startsWith($source_d_transport_path, "Global:")) {
         $source_d_transport_path = str_replace("Global:", "", $source_d_transport_path);
     }
     $source_d_transport_type = $service->getType($source_d_transport_id);
     $source_d_transport = $source_cascade->getAsset($source_d_transport_type, $source_d_transport_id);
     $source_d_transport_site = $source_d_transport->getSiteName();
     $target_d_transport_site = $source_d_transport_site;
     $target_d_transport = $target_cascade->getAsset($source_d_transport_type, $source_d_transport_path, $target_d_transport_site);
     $target_site_name = $target_site->getName();
     // parent must be there
     $target_parent = $target_cascade->getAsset(SiteDestinationContainer::TYPE, $source_d_parent_path, $target_site_name);
     $target_d = $target_cascade->createDestination($target_parent, $source_d_name, $target_d_transport);
     // set data
     $target_d->setCheckedByDefault($source_d->getCheckedByDefault())->setDirectory($source_d->getDirectory())->setEnabled($source_d->getEnabled())->setPublishASCII($source_d->getPublishASCII())->setWebUrl($source_d->getWebUrl())->edit();
 }
        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;
}
 public function __construct(\stdClass $message)
 {
     if (isset($message)) {
         $this->id = $message->id;
         $this->to = $message->to;
         $this->from = $message->from;
         $this->date = new \DateTime($message->date);
         $this->subject = trim($message->subject);
         $this->body = $message->body;
         if (u\StringUtility::startsWith($this->subject, self::TYPE_EXPIRATION)) {
             //echo "Type " . self::TYPE_EXPIRATION . BR;
             $this->type = self::TYPE_EXPIRATION;
         } else {
             if (u\StringUtility::startsWith($this->subject, self::TYPE_PUBLISH)) {
                 //echo "Type " . self::TYPE_PUBLISH . BR;
                 $this->type = self::TYPE_PUBLISH;
             } else {
                 if (u\StringUtility::startsWith($this->subject, self::TYPE_UNPUBLISH)) {
                     //echo "Type " . self::TYPE_UNPUBLISH . BR;
                     $this->type = self::TYPE_UNPUBLISH;
                 } else {
                     if (u\StringUtility::startsWith($this->subject, self::TYPE_SUMMARY)) {
                         //echo "Type " . self::TYPE_SUMMARY . BR;
                         $this->type = self::TYPE_SUMMARY;
                     } else {
                         if (u\StringUtility::startsWith($this->subject, self::TYPE_WORKFLOW)) {
                             //echo "Type " . self::TYPE_WORKFLOW . BR;
                             $this->type = self::TYPE_WORKFLOW;
                         } else {
                             $this->type = self::TYPE_OTHERS;
                         }
                     }
                 }
             }
         }
         if (strpos($this->subject, "(0 issue(s))") !== false) {
             $this->with_issues = false;
         } else {
             $this->with_issues = true;
         }
         if (strpos($this->subject, "(0 failures)") !== false) {
             $this->with_failures = false;
         } else {
             $this->with_failures = true;
         }
         if (strpos($this->subject, "is complete") !== false) {
             $this->is_complete = true;
         } else {
             $this->is_complete = false;
         }
         // body processing
         $matches = array();
         preg_match(self::PATTERN_SUCCESSFUL_JOBS, $this->body, $matches);
         if (isset($matches[1])) {
             $this->num_successful_jobs = intval($matches[1]);
         } else {
             $this->num_successful_jobs = NULL;
         }
         preg_match(self::PATTERN_JOBS_WITH_ERRORS, $this->body, $matches);
         if (isset($matches[1])) {
             $this->num_jobs_with_errors = intval($matches[1]);
         } else {
             $this->num_jobs_with_errors = NULL;
         }
         preg_match(self::PATTERN_SKIPPED_JOBS, $this->body, $matches);
         if (isset($matches[1])) {
             $this->num_skipped_jobs = intval($matches[1]);
         } else {
             $this->num_skipped_jobs = NULL;
         }
         preg_match(self::PATTERN_BROKEN_LINKS, $this->body, $matches);
         if (isset($matches[1])) {
             $this->num_broken_links = intval($matches[1]);
         } else {
             $this->num_broken_links = NULL;
         }
         preg_match(self::PATTERN_SUCCESSFUL_JOBS_MSG, $this->body, $matches);
         if (isset($matches[1])) {
             $this->msg_successful_jobs = $matches[1];
         } else {
             $this->msg_successful_jobs = "";
         }
         preg_match(self::PATTERN_JOBS_WITH_ERRORS_MSG, $this->body, $matches);
         if (isset($matches[1])) {
             $this->msg_jobs_with_errors = $matches[1];
         } else {
             $this->msg_jobs_with_errors = "";
         }
         if (strpos($this->body, "=\"brokenlinks\"") !== false) {
             preg_match(self::PATTERN_SKIPPED_JOBS_MSG1, $this->body, $matches);
         } else {
             preg_match(self::PATTERN_SKIPPED_JOBS_MSG2, $this->body, $matches);
         }
         if (isset($matches[1])) {
             $this->msg_skipped_jobs = $matches[1];
         } else {
             $this->msg_skipped_jobs = "";
         }
         preg_match(self::PATTERN_BROKEN_LINKS_MSG, $this->body, $matches);
         if (isset($matches[1])) {
             $this->msg_broken_links = $matches[1];
         } else {
             $this->msg_broken_links = "";
         }
         $this->msg_errors = array();
         preg_match_all(self::PATTERN_ERRORS, $this->body, $matches);
         if (isset($matches[1])) {
             $errors = $matches[1];
             if (!is_array($errors)) {
                 $errors = array($errors);
             }
             foreach ($errors as $error) {
                 $this->msg_errors[] = trim($error);
             }
         }
     }
 }
 public function setBaseAsset(Asset $a = NULL)
 {
     if (isset($a)) {
         $type = $a->getType();
         if (u\StringUtility::startsWith(strtolower($type), 'block')) {
             $type = 'block';
         } else {
             if (u\StringUtility::startsWith(strtolower($type), 'format')) {
                 $type = 'format';
             }
         }
         $this->getProperty()->assetType = $type;
         $this->getProperty()->baseAssetId = $a->getId();
         $this->getProperty()->baseAssetPath = $a->getPath();
     } else {
         $this->getProperty()->assetType = File::TYPE;
         // dummpy type
         $this->getProperty()->baseAssetId = NULL;
         $this->getProperty()->baseAssetPath = NULL;
     }
     return $this;
 }
use cascade_ws_exception as e;
use cascade_ws_AOHS as aohs;
$start_time = time();
// Warning: this program can take a very long time to run!!!
// My run lasts for more than 6 minutes.
try {
    // to prevent time-out
    set_time_limit(10000);
    // to prevent using up memory when traversing a large site
    ini_set('memory_limit', '2048M');
    $sites = $cascade->getSites();
    //$sites   = array( new p\Child( $cascade->getAsset( a\Site::TYPE, '22q' )->getIdentifier() ) );
    $results = array();
    foreach ($sites as $site) {
        $site_name = $site->getPathPath();
        if (u\StringUtility::endsWith($site_name, "-dev") || u\StringUtility::endsWith($site_name, "-test") || u\StringUtility::endsWith($site_name, "-old") || u\StringUtility::startsWith($site_name, "_") || u\StringUtility::startsWith($site_name, "test")) {
            continue;
        }
        $cascade->getAsset(a\Folder::TYPE, '/', $site_name)->getAssetTree()->traverse(array(a\Page::TYPE => array("assetTreeCountAsset")), array($site_name), $results);
    }
    u\DebugUtility::dump($results);
    $end_time = time();
    echo "\nTotal time taken: " . ($end_time - $start_time) . " seconds\n";
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
    $end_time = time();
    echo "\nTotal time taken: " . ($end_time - $start_time) . " seconds\n";
}
function assetTreeCountAsset(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    $type = $child->getType();