/** * Deletes the file * with predefined path (current request uri) * * @return void */ public function delete() { if ($this->cacheFile && $this->cacheFile->isExists()) { $cacheDirectory = $this->cacheFile->getDirectory(); $fileSize = $this->cacheFile->getFileSize(); if (defined("BX_COMPOSITE_DEBUG")) { $backupName = $this->cacheFile->getPath() . ".delete." . microtime(true); if ($this->checkQuota()) { AddMessage2Log($backupName, "composite"); $backupFile = new Main\IO\File($backupName); $backupFile->putContents($this->cacheFile->getContents()); $this->writeStatistic(0, 0, 0, 0, $fileSize); } else { AddMessage2Log($backupName . "(quota exceeded)", "composite"); } } $this->cacheFile->delete(); //Try to cleanup directory $children = $cacheDirectory->getChildren(); if (empty($children)) { $cacheDirectory->delete(); } //Update total files size $this->writeStatistic(0, 0, 0, 0, -$fileSize); } }
private function reindexFile($siteId, $rootPath, $path, $maxFileSize = 0) { $pathAbs = IO\Path::combine($rootPath, $path); if (!UrlRewriter::checkPath($pathAbs)) { return 0; } $file = new IO\File($pathAbs); if ($maxFileSize > 0 && $file->getFileSize() > $maxFileSize * 1024) { return 0; } $fileSrc = $file->getContents(); if (!$fileSrc || $fileSrc == "") { return 0; } $arComponents = \PHPParser::parseScript($fileSrc); for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++) { $sef = is_array($arComponents[$i]["DATA"]["PARAMS"]) && $arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y"; Component\ParametersTable::add(array('SITE_ID' => $siteId, 'COMPONENT_NAME' => $arComponents[$i]["DATA"]["COMPONENT_NAME"], 'TEMPLATE_NAME' => $arComponents[$i]["DATA"]["TEMPLATE_NAME"], 'REAL_PATH' => $path, 'SEF_MODE' => $sef ? Component\ParametersTable::SEF_MODE : Component\ParametersTable::NOT_SEF_MODE, 'SEF_FOLDER' => $sef ? $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] : null, 'START_CHAR' => $arComponents[$i]["START"], 'END_CHAR' => $arComponents[$i]["END"], 'PARAMETERS' => serialize($arComponents[$i]["DATA"]["PARAMS"]))); if ($sef) { if (array_key_exists("SEF_RULE", $arComponents[$i]["DATA"]["PARAMS"])) { $ruleMaker = new UrlRewriterRuleMaker(); $ruleMaker->process($arComponents[$i]["DATA"]["PARAMS"]["SEF_RULE"]); $arFields = array("CONDITION" => $ruleMaker->getCondition(), "RULE" => $ruleMaker->getRule(), "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path, "SORT" => self::DEFAULT_SORT); } else { $arFields = array("CONDITION" => "#^" . $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] . "#", "RULE" => "", "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path, "SORT" => self::DEFAULT_SORT); } UrlRewriter::add($siteId, $arFields); } } return true; }
public function read(&$arAllVars, $baseDir, $initDir, $filename, $TTL) { $documentRoot = \Bitrix\Main\Application::getDocumentRoot(); $fn = IO\Path::combine($documentRoot, $baseDir, $initDir, $filename); $file = new IO\File($fn); if (!$file->isExists()) { return false; } $ser_content = ""; $dateexpire = 0; $datecreate = 0; $zeroDanger = false; $handle = null; if (is_array($arAllVars)) { $INCLUDE_FROM_CACHE = 'Y'; if (!(include IO\Path::convertLogicalToPhysical($fn))) { return false; } if ($zeroDanger) { $ser_content = str_replace("", "*", $ser_content); } } else { if (!$file instanceof IO\IFileStream) { return false; } $handle = $file->open("r"); if (!$handle) { return false; } $datecreate = fread($handle, 2); if ($datecreate == "BX") { $datecreate = fread($handle, 12); $dateexpire = fread($handle, 12); } else { $datecreate .= fread($handle, 10); } } /* We suppress warning here in order not to break the compression under Zend Server */ $this->read = $file->getFileSize(); if (intval($datecreate) < mktime() - $TTL) { return false; } if (is_array($arAllVars)) { $arAllVars = unserialize($ser_content); } else { $arAllVars = fread($handle, $this->read); fclose($handle); } return true; }