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
 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.º 3
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.º 4
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.º 5
0
			{
				$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
								{
									$reportsEntry->delete();