CCrmExternalSaleImport::AddMessage2Log

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmExternalSaleImport
  4. AddMessage2Log
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_external_sale_import.php
  • Класс: \CCrmExternalSaleImport
  • Вызов: CCrmExternalSaleImport::AddMessage2Log
function AddMessage2Log($text)
{
	if (!defined("CRM_ERROR_LOG") || !CRM_ERROR_LOG)
		return;

	$text = trim($text);
	if (empty($text))
		return;

	$maxLogSize = 10000;
	$readSize = 2048;
	$logFile = $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/crm_import.log";
	$logFileTmp = $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/crm_import1.log";

	$oldAbortStatus = ignore_user_abort(true);

	if (file_exists($logFile))
	{
		$logSize = @filesize($logFile);
		$logSize = intval($logSize);

		if ($logSize > $maxLogSize)
		{
			if (!($fp = @fopen($logFile, "rb")))
			{
				ignore_user_abort($oldAbortStatus);
				return;
			}

			if (!($fp1 = @fopen($logFileTmp, "wb")))
			{
				ignore_user_abort($oldAbortStatus);
				return;
			}

			$iSeekLen = intval($logSize - $maxLogSize / 2.0);
			fseek($fp, $iSeekLen);

			do
			{
				$data = fread($fp, $readSize);
				if ($data == '')
					break;

				@fwrite($fp1, $data);
			}
			while(true);

			@fclose($fp);
			@fclose($fp1);

			@copy($logFileTmp, $logFile);
			@unlink($logFileTmp);
		}
		clearstatcache();
	}

	if ($fp = @fopen($logFile, "ab+"))
	{
		if (flock($fp, LOCK_EX))
		{
			@fwrite($fp, date("Y-m-d H:i:s").": ".$text."\n");
			@fflush($fp);
			@flock($fp, LOCK_UN);
			@fclose($fp);
		}
	}
	ignore_user_abort($oldAbortStatus);
}

Добавить комментарий