Exemple #1
0
 function RecurseIndex($path = array(), $max_execution_time = 0, &$NS)
 {
     CMain::InitPathVars($site, $path);
     $DOC_ROOT = CSite::GetSiteDocRoot($site);
     $abs_path = $DOC_ROOT . $path;
     if (strlen($site) <= 0) {
         return 0;
     }
     if (!file_exists($abs_path) || !is_dir($abs_path)) {
         return 0;
     }
     $handle = @opendir($abs_path);
     while (false !== ($file = @readdir($handle))) {
         if ($file == "." || $file == "..") {
             continue;
         }
         $full_path = $path . "/" . $file;
         if (is_dir($abs_path . "/" . $file)) {
             if ($full_path == "/bitrix" || $full_path == "/" . COption::GetOptionString("main", "upload_dir", "upload")) {
                 continue;
             }
             //this is not first step and we had stopped here, so go on to reindex
             if ($max_execution_time <= 0 || strlen($NS["FLG"]) <= 0 || strlen($NS["FLG"]) > 0 && substr($NS["ID"] . "/", 0, strlen($site . "|" . $full_path . "/")) == $site . "|" . $full_path . "/") {
                 $new_site = CSite::GetSiteByFullPath($DOC_ROOT . $full_path);
                 if (CUrlRewriter::RecurseIndex(array($new_site, $full_path), $max_execution_time, $NS) === false) {
                     return false;
                 }
             } else {
                 //all done
                 continue;
             }
         } else {
             //not the first step and we found last file from previos one
             if ($max_execution_time > 0 && strlen($NS["FLG"]) > 0 && $NS["ID"] == $site . "|" . $full_path) {
                 $NS["FLG"] = "";
             } elseif (strlen($NS["FLG"]) <= 0) {
                 $ID = CUrlRewriter::ReindexFile(array($site, $full_path), $NS["SESS_ID"], $NS["max_file_size"]);
                 if ($ID) {
                     $NS["CNT"] = intval($NS["CNT"]) + 1;
                 }
             }
             if ($max_execution_time > 0 && getmicrotime() - START_EXEC_TIME > $max_execution_time) {
                 $NS["FLG"] = "Y";
                 $NS["ID"] = $site . "|" . $full_path;
                 return false;
             }
         }
     }
     return true;
 }