Exemplo n.º 1
0
 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();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        echo bitrix_sessid_get() . "\n";
    }
} elseif (!check_bitrix_sessid()) {
    echo "failure\n", GetMessage("CC_BCIH_ERROR_SOURCE_CHECK");
} elseif (!$USER->IsAuthorized()) {
    echo "failure\n", GetMessage("CC_BCIH_ERROR_AUTHORIZE");
} elseif (!$bUSER_HAVE_ACCESS) {
    echo "failure\n", GetMessage("CC_BCIH_PERMISSION_DENIED");
} elseif (!CModule::IncludeModule('highloadblock')) {
    echo "failure\n", GetMessage("CC_BCIH_ERROR_MODULE");
} elseif ($_GET["mode"] == "init") {
    if ($arParams["USE_TEMP_DIR"] === "Y") {
        $DIR_NAME = CTempFile::GetDirectoryName(6, "1c_highloadblock");
    } else {
        //Cleanup previous import files
        $directory = new \Bitrix\Main\IO\Directory($DIR_NAME);
        if ($directory->isExists()) {
            $directory->delete();
        }
    }
    CheckDirPath($DIR_NAME);
    if (!is_dir($DIR_NAME)) {
        echo "failure\n", GetMessage("CC_BCIH_ERROR_INIT");
    } else {
        $_SESSION["BX_HL_IMPORT"] = array("zip" => $arParams["USE_ZIP"] && function_exists("zip_open"), "TEMP_DIR" => $arParams["USE_TEMP_DIR"] === "Y" ? $DIR_NAME : "", "NS" => array("XMLPOS" => "", "SESSID" => md5($_REQUEST["sessid"])));
        echo "zip=" . ($_SESSION["BX_HL_IMPORT"]["zip"] ? "yes" : "no") . "\n";
        echo "file_limit=" . $arParams["FILE_SIZE_LIMIT"];
    }
} elseif ($_GET["mode"] == "file" && $ABS_FILE_NAME) {
    //Read http data
    if (function_exists("file_get_contents")) {
Exemplo n.º 3
0
 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()) {
         $dir_name = \Bitrix\Main\IO\Path::convertRelativeToAbsolute($ar["RELATIVE_PATH"]);
         $dir = new \Bitrix\Main\IO\Directory($dir_name);
         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"]) . "'");
         }
     }
 }
Exemplo n.º 4
0
 protected function sendDataSftp()
 {
     $directory = new \Bitrix\Main\IO\Directory($this->path . "/zip");
     if (!$directory->isExists()) {
         throw new SystemException("Directory" . $this->path . "/zip does not exist! " . __METHOD__);
     }
     $filesToSend = $directory->getChildren();
     if (empty($filesToSend)) {
         return false;
     }
     $sftp = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftp($this->siteId);
     $sftp->connect();
     for ($i = 0; $i < count($filesToSend); $i++) {
         $directoryEntry = $filesToSend[$i];
         $localPath = $directoryEntry->getPath();
         if (!$directoryEntry instanceof \Bitrix\Main\IO\File || GetFileExtension($localPath) != "zip") {
             continue;
         }
         $remote = $this->remotePath . "/" . $directoryEntry->getName();
         while (!$this->checkOuterConditions($sftp)) {
             if ($this->timer !== null && !$this->timer->check(15)) {
                 return false;
             }
             sleep(10);
         }
         if ($sftp->uploadFile($localPath, $remote)) {
             $directoryEntry->delete();
             ResultsTable::add(array("FILENAME" => $directoryEntry->getName(), "FEED_TYPE" => $this->feedType, "UPLOAD_TIME" => DateTime::createFromTimestamp(time())));
             Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_SFTPQUEUE_SEND", $remote, "File sent successfully.", $this->siteId);
         }
     }
     return true;
 }
Exemplo n.º 5
0
    protected static function getHddsUtilization($hostname)
    {
        $dir = new \Bitrix\Main\IO\Directory(static::$rrdPath . "/" . $hostname);
        if (!$dir->isExists()) {
            return array();
        }
        $arChildren = $dir->getChildren();
        $result = array();
        foreach ($arChildren as $child) {
            if (!$child->isFile()) {
                continue;
            }
            $name = $child->getName();
            $pos1 = strpos($name, "-diskstats_utilization-");
            $pos2 = strpos($name, "-util-");
            if ($pos1 !== false && $pos2 !== false) {
                $pos1 += 23;
                //strlen("-diskstats_utilization-")
                $dev = substr($name, $pos1, $pos2 - $pos1);
                $result[$dev] = array("NAME" => $dev . " " . Loc::getMessage("SCALE_MONITORING_HDDACT_PARAMS"), "TYPE" => "ARRAY", "ITEMS" => array(array("OPTIONS" => array("DEF:r=" . static::$rrdPath . "/" . $hostname . "/" . $hostname . "-diskstats_throughput-" . $dev . "-rdbytes-g.rrd:42:AVERAGE:start=now-600;end=now", "DEF:w=" . static::$rrdPath . "/" . $hostname . "/" . $hostname . "-diskstats_throughput-" . $dev . "-wrbytes-g.rrd:42:AVERAGE:start=now-600;end=now", "VDEF:vr=r,TOTAL", "VDEF:vw=w,TOTAL", "PRINT:vr:%1.2lf", "PRINT:vw:%1.2lf"), "DATA_FUNC" => '
								$result = false;
								if(isset($data["calcpr"][0]) && isset($data["calcpr"][1]))
								{
									$result = \\Bitrix\\Scale\\Monitoring::formatSize($data["calcpr"][0]/600).
										"&nbsp;/&nbsp;".
										\\Bitrix\\Scale\\Monitoring::formatSize($data["calcpr"][1]/600)."&nbsp;' . Loc::getMessage("SCALE_MONITORING_NET_SEC") . '";
								}
								return $result;'), array("RRD" => $hostname . "-diskstats_utilization-" . $dev . "-util-g.rrd", "CF" => "LAST", "FORMAT" => "%2.2lf", "TYPE" => "LOADBAR")));
            }
        }
        return $result;
    }
Exemplo n.º 6
0
			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) //no more than 5 days old
									&& $match[1] < date("Y-m-d") //not today or future
								)
								{
									//Preserve the file
									$emptyDirectory = false;
								}
								else
								{