• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/failover.php
  • Класс: CCloudFailover
  • Вызов: CCloudFailover::syncAgent
static function syncAgent($bucketFrom, $bucketTo, $limit = 100)
{
	$bucketFrom = intval($bucketFrom);
	$bucketTo = intval($bucketTo);
	$limit = intval($limit);

	if (static::lock())
	{
		$bucket = new CCloudStorageBucket($bucketFrom, false);
		if ($bucket->Init())
		{
			$etime = time() + COption::GetOptionInt("clouds", "sync_agent_time");
			do
			{
				$lastJob = BitrixCloudsCopyQueueTable::getList(array(
					"select" => array("SOURCE_FILE_PATH"),
					"filter" => array(
						"=OP" => BitrixCloudsCopyQueueTable::OP_SYNC,
						"=SOURCE_BUCKET_ID" => $bucketFrom,
						"=TARGET_BUCKET_ID" => $bucketTo,
					),
					"order"  => array("ID" => "DESC"),
					"limit"  => 1
				))->fetch();
				$lastKey = $lastJob? ltrim($lastJob["SOURCE_FILE_PATH"], '/'): '';

				$files = $bucket->ListFiles("/", true, $limit, $lastKey);
				if ($files === false || empty($files["file"]))
				{
					return "";
				}

				foreach ($files['file'] as $fileName)
				{
					BitrixCloudsCopyQueueTable::add(array(
						"TIMESTAMP_X" => new BitrixMainTypeDateTime(),
						"OP" => BitrixCloudsCopyQueueTable::OP_SYNC,
						"SOURCE_BUCKET_ID" => $bucketFrom,
						"SOURCE_FILE_PATH" => "/".$fileName,
						"TARGET_BUCKET_ID" => $bucketTo,
						"TARGET_FILE_PATH" => "/".$fileName,
					));
				}
			}
			while (time() < $etime);
		}
	}
	static::unlock();

	return "CCloudFailover::syncAgent($bucketFrom, $bucketTo, $limit);";
}