• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/lib/filehash.php
  • Класс: BitrixCloudsFileHashTable
  • Вызов: FileHashTable::syncList
static function syncList($bucketId, $path, array $files, $prevLastKey)
{
	$result = null;
	$bucketId = intval($bucketId);
	$connection = BitrixMainApplication::getConnection();
	$helper = $connection->getSqlHelper();

	$index = [];
	foreach ($files['file'] as $i => $filePath)
	{
		$index[$path . $filePath] = $i;
	}

	$filter = [
		'=BUCKET_ID' => $bucketId,
	];
	if ($prevLastKey)
	{
		$filter['>FILE_PATH'] = $path . $prevLastKey;
	}
	if ($files['last_key'])
	{
		$filter['<=FILE_PATH'] = $path . $files['last_key'];
	}
	$fileList = static::getList([
		'select' => ['ID', 'FILE_PATH', 'FILE_SIZE', 'FILE_HASH'],
		'filter' => $filter,
	]);
	while ($fileInfo = $fileList->fetch())
	{
		if (
			array_key_exists($fileInfo['FILE_PATH'], $index)
			&& ($files['file_size'][$index[$fileInfo['FILE_PATH']]] == $fileInfo['FILE_SIZE'])
			&& ($files['file_hash'][$index[$fileInfo['FILE_PATH']]] == $fileInfo['FILE_HASH'])
		)
		{
			unset($files['file'][$index[$fileInfo['FILE_PATH']]]);
		}
		else
		{
			$deleteResult = static::delete($fileInfo['ID']);
		}
	}

	$values = [];
	foreach ($files['file'] as $i => $file)
	{
		$fileSize = $files['file_size'][$i];
		$fileMtime = CCloudUtil::gmtTimeToDateTime($files['file_mtime'][$i]);
		$fileHash = $files['file_hash'][$i];
		$values [] = '('
			. $bucketId
			. ",'" . $helper->forSql($path . $file) . "'"
			. ',' . intval($fileSize)
			. ",'" . $fileMtime->format('Y-m-d h:i:s') . "'"
			. ",'" . $helper->forSql($fileHash) . "'"
			. ')'
		;
	}

	$insertSize = 1000;
	while ($values)
	{
		$sql = '
			INSERT INTO ' . static::getTableName() . '
			(BUCKET_ID, FILE_PATH, FILE_SIZE, FILE_MTIME, FILE_HASH)
			VALUES
			' . implode(",n", array_splice($values, 0, $insertSize)) . '
		';
		$result = $connection->query($sql);
	}

	return $result;
}