/** * Generates the static cache from the configured INI settings. * * @param bool $force If true then it will create all static caches even if it is not outdated. * @param bool $quiet If true then the function will not output anything. * @param eZCLI|false $cli The eZCLI object or false if no output can be done. * @param bool $delay */ public function generateCache( $force = false, $quiet = false, $cli = false, $delay = true ) { $staticURLArray = $this->cachedURLArray(); $db = eZDB::instance(); $configSettingCount = count( $staticURLArray ); $currentSetting = 0; // This contains parent elements which must checked to find new urls and put them in $generateList // Each entry contains: // - url - Url of parent // - glob - A glob string to filter direct children based on name // - org_url - The original url which was requested // - parent_id - The element ID of the parent (optional) // The parent_id will be used to quickly fetch the children, if not it will use the url $parentList = array(); // A list of urls which must generated, each entry is a string with the url $generateList = array(); foreach ( $staticURLArray as $url ) { $currentSetting++; if ( strpos( $url, '*') === false ) { $generateList[] = $url; } else { $queryURL = ltrim( str_replace( '*', '', $url ), '/' ); $dir = dirname( $queryURL ); if ( $dir == '.' ) $dir = ''; $glob = basename( $queryURL ); $parentList[] = array( 'url' => $dir, 'glob' => $glob, 'org_url' => $url ); } } // As long as we have urls to generate or parents to check we loop while ( count( $generateList ) > 0 || count( $parentList ) > 0 ) { // First generate single urls foreach ( $generateList as $generateURL ) { if ( !$quiet and $cli ) $cli->output( "caching: $generateURL ", false ); $this->cacheURL( $generateURL, false, !$force, $delay ); if ( !$quiet and $cli ) $cli->output( "done" ); } $generateList = array(); // Then check for more data $newParentList = array(); foreach ( $parentList as $parentURL ) { if ( isset( $parentURL['parent_id'] ) ) { $elements = eZURLAliasML::fetchByParentID( $parentURL['parent_id'], true, true, false ); foreach ( $elements as $element ) { $path = '/' . $element->getPath(); $generateList[] = $path; $newParentList[] = array( 'parent_id' => $element->attribute( 'id' ) ); } } else { if ( !$quiet and $cli and $parentURL['glob'] ) $cli->output( "wildcard cache: " . $parentURL['url'] . '/' . $parentURL['glob'] . "*" ); $elements = eZURLAliasML::fetchByPath( $parentURL['url'], $parentURL['glob'] ); foreach ( $elements as $element ) { $path = '/' . $element->getPath(); $generateList[] = $path; $newParentList[] = array( 'parent_id' => $element->attribute( 'id' ) ); } } } $parentList = $newParentList; } }