Пример #1
0
 /**
  * Creates filestructure for information exchange via sftp.
  * @return bool
  */
 public static function createFeedFileStructure()
 {
     $sftpDir = self::getSftpPath();
     $directory = new Directory($sftpDir);
     if (!$directory->isExists()) {
         $directory->create();
     }
     foreach (array("product", "inventory", "image", "order-ack", "shipment") as $feedType) {
         $feedDir = new Directory($sftpDir . "/" . $feedType);
         if (!$feedDir->isExists()) {
             $feedDir->create();
         }
         foreach (array("xml", "tmp", "zip") as $stage) {
             $stageDir = new Directory($sftpDir . "/" . $feedType . "/" . $stage);
             if (!$stageDir->isExists()) {
                 $stageDir->create();
             }
         }
     }
     return true;
 }
Пример #2
0
 private static function recursiveReindex($rootPath, $path, $arSites, $maxExecutionTime = 0, &$ns)
 {
     $pathAbs = IO\Path::combine($rootPath, $path);
     $dir = new IO\Directory($pathAbs);
     if (!$dir->isExists()) {
         return 0;
     }
     $siteId = "";
     foreach ($arSites as $site) {
         if (substr($pathAbs . "/", 0, strlen($site["path"] . "/")) == $site["path"] . "/") {
             $siteId = $site["site_id"];
             break;
         }
     }
     if (empty($siteId)) {
         return 0;
     }
     $arChildren = $dir->getChildren();
     foreach ($arChildren as $child) {
         if ($child->isDirectory()) {
             if ($child->isSystem()) {
                 continue;
             }
             //this is not first step and we had stopped here, so go on to reindex
             if ($maxExecutionTime <= 0 || strlen($ns["FLG"]) <= 0 || strlen($ns["FLG"]) > 0 && substr($ns["ID"] . "/", 0, strlen($child->getPath() . "/")) == $child->getPath() . "/") {
                 if (UrlRewriter::recursiveReindex($rootPath, substr($child->getPath(), strlen($rootPath)), $arSites, $maxExecutionTime, $ns) === false) {
                     return false;
                 }
             } else {
                 continue;
             }
         } else {
             //not the first step and we found last file from previos one
             if ($maxExecutionTime > 0 && strlen($ns["FLG"]) > 0 && $ns["ID"] == $child->getPath()) {
                 $ns["FLG"] = "";
             } elseif (empty($ns["FLG"])) {
                 $ID = UrlRewriter::reindexFile($siteId, $rootPath, substr($child->getPath(), strlen($rootPath)), $ns["max_file_size"]);
                 if ($ID) {
                     $ns["CNT"] = intval($ns["CNT"]) + 1;
                 }
             }
             if ($maxExecutionTime > 0 && getmicrotime() - START_EXEC_TIME > $maxExecutionTime) {
                 $ns["FLG"] = "Y";
                 $ns["ID"] = $child->getPath();
                 return false;
             }
         }
     }
     return true;
 }
Пример #3
0
 public function clean($baseDir, $initDir = false, $filename = false)
 {
     if (strlen($filename)) {
         $documentRoot = \Bitrix\Main\Application::getDocumentRoot();
         $fn = IO\Path::combine($documentRoot, $baseDir, $initDir, $filename);
         $file = new IO\File($fn);
         //This checks for Zend Server CE in order to supress warnings
         if (function_exists('accelerator_reset')) {
             try {
                 $file->markWritable();
                 if ($file->delete()) {
                     \Bitrix\Main\Application::resetAccelerator();
                     return true;
                 }
             } catch (\Exception $ex) {
             }
         } else {
             if ($file->isExists()) {
                 $file->markWritable();
                 if ($file->delete()) {
                     \Bitrix\Main\Application::resetAccelerator();
                     return true;
                 }
             }
         }
         return false;
     } else {
         static $bAgentAdded = false;
         $bDelayedDelete = false;
         $source = IO\Path::combine($baseDir, $initDir);
         $sourceDir = new IO\Directory(IO\Path::convertRelativeToAbsolute($source));
         if ($sourceDir->isExists()) {
             $target = $source . ".~";
             for ($i = 0; $i < 9; $i++) {
                 $suffix = rand(0, 999999);
                 $targetDir = new IO\Directory(IO\Path::convertRelativeToAbsolute($target . $suffix));
                 if (!$targetDir->isExists()) {
                     $con = \Bitrix\Main\Application::getDbConnection();
                     $res = $con->queryExecute("INSERT INTO b_cache_tag (SITE_ID, CACHE_SALT, RELATIVE_PATH, TAG)\n\t\t\t\t\t\t\tVALUES ('*', '*', '" . $con->getSqlHelper()->forSql($target . $suffix) . "', '*')");
                     if ($res) {
                         if ($sourceDir->rename($targetDir->getPath())) {
                             $bDelayedDelete = true;
                         }
                     }
                     break;
                 }
             }
         }
         if ($bDelayedDelete) {
             if (!$bAgentAdded) {
                 $bAgentAdded = true;
                 /* TODO: јгенты */
                 $rsAgents = \CAgent::getList(array("ID" => "DESC"), array("NAME" => "CacheEngineFiles::delayedDelete(%"));
                 if (!$rsAgents->fetch()) {
                     $res = \CAgent::addAgent("CacheEngineFiles::delayedDelete();", "main", "Y", 1);
                 }
             }
         } else {
             $sourceDir->delete();
         }
         \Bitrix\Main\Application::resetAccelerator();
     }
 }
Пример #4
0
 /**
  * @param string $lang This variable is the value language.
  * @param bool $systemProcesses Installing the system processes.
  * @param string $path This variable is the path to the file to get the data.
  * @param array $fileData Array for loading the data.
  * @throws Main\ArgumentNullException
  * @throws Main\IO\FileNotFoundException
  */
 public static function loadDataProcesses($lang, $systemProcesses = true, &$fileData, $path = null)
 {
     if (empty($lang)) {
         throw new Main\ArgumentNullException("lang");
     }
     if (!empty($path)) {
         $path = $path . "/";
     } else {
         if ($systemProcesses) {
             $path = Main\Loader::getDocumentRoot() . static::PATH . $lang . "/";
         } else {
             $path = Main\Loader::getDocumentRoot() . static::PATH_USER_PROCESSES . $lang . "/";
         }
     }
     $dir = new Main\IO\Directory($path);
     if ($dir->isExists()) {
         $children = $dir->getChildren();
         foreach ($children as $key => $child) {
             /** @var Main\IO\File $child */
             if ($child->isFile() && $child->getExtension() == "prc") {
                 $data = self::getDataProcess($path . $child->getName());
                 $fileData[$data['CODE']]['FILE_NAME'] = $child->getName();
                 $fileData[$data['CODE']]['FILE_PATH'] = str_replace(Main\Loader::getDocumentRoot(), '', $child->getPath());
                 $fileData[$data['CODE']]['NAME'] = $data['NAME'];
                 $fileData[$data['CODE']]['DESCRIPTION'] = $data['DESCRIPTION'];
                 $fileData[$data['CODE']]['CODE'] = $data['CODE'];
                 $fileData[$data['CODE']]['IBLOCK_TYPE_ID'] = $data['IBLOCK_TYPE_ID'];
                 $fileData[$data['CODE']]['DIRECTORY_NAME'] = $child->getDirectory()->getName();
             } elseif ($child->isDirectory()) {
                 self::loadDataProcesses($lang, $systemProcesses, $fileData, $child->getPath());
             }
         }
     }
 }
 protected function deleteOneDir($etime = 0)
 {
     $bDeleteFromQueue = false;
     $con = \Bitrix\Main\Application::getDbConnection();
     $rs = $con->query("SELECT * from b_cache_tag WHERE TAG='*'", 0, 1);
     if ($ar = $rs->fetch()) {
         $dirName = IO\Path::convertRelativeToAbsolute($ar["RELATIVE_PATH"]);
         $dir = new IO\Directory($dirName);
         if ($dir->isExists()) {
             $arChildren = $dir->getChildren();
             $Counter = 0;
             foreach ($arChildren as $child) {
                 $child->delete();
                 $Counter++;
                 if (time() > $etime) {
                     break;
                 }
             }
             if ($Counter == 0) {
                 $dir->delete();
                 $bDeleteFromQueue = true;
             }
         } else {
             $bDeleteFromQueue = true;
         }
         if ($bDeleteFromQueue) {
             $con->queryExecute("DELETE FROM b_cache_tag\n\t\t\t\t\tWHERE SITE_ID = '" . $con->getSqlHelper()->forSql($ar["SITE_ID"]) . "'\n\t\t\t\t\tAND CACHE_SALT = '" . $con->getSqlHelper()->forSql($ar["CACHE_SALT"]) . "'\n\t\t\t\t\tAND RELATIVE_PATH = '" . $con->getSqlHelper()->forSql($ar["RELATIVE_PATH"]) . "'");
         }
     }
 }