public function UnInstallFiles() { $files = array('js' => '/js/' . $this->MODULE_ID, 'img' => '/images/' . $this->MODULE_ID, 'request' => '/tools/' . $this->MODULE_ID); $rootDir = Application::getDocumentRoot() . '/' . ltrim(Application::getPersonalRoot(), '/'); foreach ($files as $file) { Directory::deleteDirectory($rootDir . $file); } }
/** * 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; }
public static function getCurrentTemplateId($siteId) { $cacheFlags = Config\Configuration::getValue("cache_flags"); $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0; $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION"; $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates"); if ($ttl === false) { $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($ttl, "b_site_template")) { $arSiteTemplateBySite = $managedCache->get("b_site_template"); } else { $arSiteTemplateBySite = array(); $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $arSiteTemplateBySite[$record['SITE_ID']][] = $record; } $managedCache->set("b_site_template", $arSiteTemplateBySite); } if (is_array($arSiteTemplateBySite[$siteId])) { foreach ($arSiteTemplateBySite[$siteId] as $record) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } } return ".default"; }
public function cleanUpDirectory($directoryName) { //Cleanup previous import files $directory = new \Bitrix\Main\IO\Directory($directoryName); if ($directory->isExists()) { if (defined("BX_CATALOG_IMPORT_1C_PRESERVE")) { $i = 0; while (\Bitrix\Main\IO\Directory::isDirectoryExists($directory->getPath() . $i)) { $i++; } $directory->rename($directory->getPath() . $i); } else { foreach ($directory->getChildren() as $directoryEntry) { $match = array(); if ($directoryEntry->isDirectory() && $directoryEntry->getName() === "Reports") { $emptyDirectory = true; $reportsDirectory = new \Bitrix\Main\IO\Directory($directoryEntry->getPath()); foreach ($reportsDirectory->getChildren() as $reportsEntry) { $match = array(); if (preg_match("/(\\d\\d\\d\\d-\\d\\d-\\d\\d)\\./", $reportsEntry->getName(), $match)) { if ($match[1] >= date("Y-m-d", time() - 5 * 24 * 3600) && $match[1] < date("Y-m-d")) { //Preserve the file $emptyDirectory = false; } else { $reportsEntry->delete(); } } else { $reportsEntry->delete(); } } if ($emptyDirectory) { $directoryEntry->delete(); } } else { $directoryEntry->delete(); } } } } }
public function clearLogFile() { $logDir = $this->getLogFileDir(); if (!Main\IO\Directory::isDirectoryExists($logDir)) { Main\IO\Directory::createDirectory($logDir); } $logFile = $this->getLogFilePath(); Main\IO\File::putFileContents($logFile, ''); }
/** * Checks if the configuration is already exists * * @param $folder * @param $appCode - application code * * @return bool * * @see ConfigTable::getSupportedPlatforms for details on availible platforms */ public static function copyFromTemplate($folder, $appCode) { $appFolderPath = Application::getDocumentRoot() . "/" . $folder . "/"; $templatePath = Application::getDocumentRoot() . "/bitrix/modules/mobileapp/templates_app/simple/"; $fileList = array("config.php", ".mobile_menu.php", "settings.php", "index.php", "menu.php"); if (!Directory::isDirectoryExists($appFolderPath)) { for ($i = 0; $i < count($fileList); $i++) { File::putFileContents($appFolderPath . $fileList[$i], str_replace(array("#folder#", "#code#"), array($folder, $appCode), File::getFileContents($templatePath . $fileList[$i]))); } } }
protected static function deleteDirectory($path) { if (\Bitrix\Main\IO\Directory::isDirectoryExists($path)) { \Bitrix\Main\IO\Directory::deleteDirectory($path); } }
protected static function cleanWorkDirectory() { $dir = $_SERVER['DOCUMENT_ROOT'] . self::LOCAL_PATH . self::LOCAL_SETS_PATH; IO\Directory::deleteDirectory($dir); IO\Directory::createDirectory($dir); }
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(); } }
elseif ($_GET["mode"]=="init") { if ($arParams["USE_TEMP_DIR"] === "Y") { $DIR_NAME = CTempFile::GetDirectoryName(6, "1c_catalog"); } else { //Cleanup previous import files $directory = new \Bitrix\Main\IO\Directory($DIR_NAME); if ($directory->isExists()) { if (defined("BX_CATALOG_IMPORT_1C_PRESERVE")) { $i = 0; while (\Bitrix\Main\IO\Directory::isDirectoryExists($directory->getPath().$i)) $i++; $directory->rename($directory->getPath().$i); } else { foreach ($directory->getChildren() as $directoryEntry) { $match = array(); if ($directoryEntry->isDirectory() && $directoryEntry->getName() === "Reports") { $emptyDirectory = true; $reportsDirectory = new \Bitrix\Main\IO\Directory($directoryEntry->getPath()); foreach ($reportsDirectory->getChildren() as $reportsEntry) { $match = array();
/** * @return Collector[] */ public function getNotAppliedCollectors() { $result = AppliedChangesLogTable::getList(array('select' => array('GROUP_LABEL'), 'group' => array('GROUP_LABEL'))); $usesGroups = array_map(function ($row) { return $row['GROUP_LABEL']; }, $result->fetchAll()); $dir = new Directory($this->_getFixFilesDir()); $collectors = array(); $files = array(); foreach ($dir->getChildren() as $file) { if ($file->isDirectory()) { continue; } if (in_array($file->getName(), $usesGroups)) { continue; } $files[$file->getName()] = $file; } ksort($files); foreach ($files as $file) { $collectors[] = Collector::createByFile($file->getPath(), $this); } return $collectors; }
protected function getClasses() { if ($this->rootNamespace == false) { throw new Dispatcher\Exception('Root namespace incorrect'); // paranoid disorder } $dir = dirname(__FILE__) . static::DIRECTORY_TO_CALLABLE; $result = array(); if (Directory::isDirectoryExists($dir)) { $index = array(); static::walkDirectory($dir, $index, ''); if (is_array($index['FILE'])) { foreach ($index['FILE'] as $fileName) { $fileName = str_replace($dir, '', $fileName); $fileName = explode('/', $fileName); if (is_array($fileName)) { $query = array(); foreach ($fileName as $part) { if ((string) $part !== '') { $query[] = preg_replace('#\\.php$#', '', $part); } } } $result[] = array('ENTITY' => implode('.', $query), 'CLASS' => $this->rootNamespace . '\\' . implode('\\', array_map('ucfirst', $query))); } } } return $result; }
/** * @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()); } } } }
/** * @return bool */ function UnInstallFiles() { \Bitrix\Main\IO\Directory::deleteDirectory($_SERVER["DOCUMENT_ROOT"] . '/bitrix/components/adelshin/'); if (\Bitrix\Main\IO\Directory::isDirectoryExists($path = $this->GetPath() . '/admin')) { // удаляем административные файлы DeleteDirFiles($_SERVER["DOCUMENT_ROOT"] . $this->GetPath() . '/install/admin/', $_SERVER["DOCUMENT_ROOT"] . '/bitrix/admin'); if ($dir = opendir($path)) { while (false !== ($item = readdir($dir))) { if (in_array($item, $this->exclusionAdminFiles)) { continue; } \Bitrix\Main\IO\File::deleteFile($_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin/' . $this->MODULE_ID . '_' . $item); } closedir($dir); } } return true; }
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"]) . "'"); } } }
/** * Downloads and saves a file. * * @param string $url URI to download * @param string $filePath Absolute file path * @return bool */ public function download($url, $filePath) { $dir = IO\Path::getDirectory($filePath); IO\Directory::createDirectory($dir); $file = new IO\File($filePath); $handler = $file->open("w+"); if ($handler !== false) { $this->setOutputStream($handler); $res = $this->query(self::HTTP_GET, $url); fclose($handler); return $res; } return false; }
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; }
public function getRemoteTypeGroups() { if (!$this->useCache || !isset($this->data['settings']['remote']['typeGroups'])) { $localPath = \CTempFile::GetDirectoryName(100); static::downloadFile(self::REMOTE_TYPE_GROUP_FILE, self::LOCAL_TYPE_GROUP_FILE, false, $localPath); $csv = new CSVReader(); $res = $csv->ReadBlock($localPath . self::LOCAL_TYPE_GROUP_FILE); $result = array(); foreach ($res as $line) { $result[$line['CODE']] = explode(':', $line['TYPES']); } $this->data['settings']['remote']['typeGroups'] = $result; if (\Bitrix\Main\IO\File::isFileExists($localPath . self::LOCAL_TYPE_GROUP_FILE)) { try { \Bitrix\Main\IO\File::deleteFile($localPath . self::LOCAL_TYPE_GROUP_FILE); \Bitrix\Main\IO\Directory::deleteDirectory($localPath); } catch (\Exception $e) { } } } return $this->data['settings']['remote']['typeGroups']; }