• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/volume/module/calendar.php
  • Класс: BitrixDiskVolumeModuleCalendar
  • Вызов: Calendar::measure
public function measure(array $collectData = []): self
{
	if (!$this->isMeasureAvailable())
	{
		$this->addError(new BitrixMainError('', self::ERROR_MEASURE_UNAVAILABLE));
		return $this;
	}

	$connection = BitrixMainApplication::getConnection();
	$indicatorType = $connection->getSqlHelper()->forSql(static::className());
	$ownerId = (string)$this->getOwner();

	$attachedEntityList = $this->getAttachedEntityList();
	$attachedEntitySql = '';
	if (count($attachedEntityList) > 0)
	{
		foreach ($attachedEntityList as $attachedEntity)
		{
			if ($attachedEntitySql != '') $attachedEntitySql .= ', ';
			$attachedEntitySql .= "'".$connection->getSqlHelper()->forSql($attachedEntity)."'";
		}
	}

	// Scan User fields specific to module
	$entityUserFieldSource = $this->prepareUserFieldSourceSql(null, [CUserTypeFile::USER_TYPE_ID]);
	if ($entityUserFieldSource != '')
	{
		$entityUserFieldSource = " UNION {$entityUserFieldSource} ";
	}

	// Forum comments attachments
	$attachedForumCommentsSql = '';
	if (BitrixMainModuleManager::isModuleInstalled('forum') && BitrixMainLoader::includeModule('socialnetwork'))
	{
		$forumMetaData = CSocNetLogTools::getForumCommentMetaData('lists_new_element');
		$eventTypeXML = $forumMetaData[0];

		$attachedForumCommentsSql = "
			UNION
			(
				SELECT
					SUM(ver.SIZE) as FILE_SIZE,
					COUNT(ver.FILE_ID) as FILE_COUNT,
					SUM(ver.SIZE) as DISK_SIZE,
					COUNT(DISTINCT files.ID) as DISK_COUNT,
					COUNT(ver.ID) as VERSION_COUNT
				FROM
					b_disk_version ver
					INNER JOIN b_disk_object files
						ON files.ID  = ver.OBJECT_ID
						AND files.TYPE = '".DiskInternalsObjectTable::TYPE_FILE."'
						AND files.ID = files.REAL_OBJECT_ID
					INNER JOIN 
					(
						SELECT 
							attached.OBJECT_ID as OBJECT_ID
						FROM 
							b_disk_attached_object attached
							INNER JOIN b_forum_message message 
								ON message.ID = attached.ENTITY_ID
						WHERE
							attached.ENTITY_TYPE = '". $connection->getSqlHelper()->forSql(DiskUfForumMessageConnector::className()). "'
							AND substring_index(message.XML_ID,'_', 1) = '{$eventTypeXML}'
						GROUP BY 
							attached.OBJECT_ID
						ORDER BY NULL
					) attach_connect
						ON attach_connect.OBJECT_ID = files.ID
			)
		";
	}

	$querySql = "
		SELECT 
			'{$indicatorType}' as INDICATOR_TYPE,
			{$ownerId} as OWNER_ID,
			". $connection->getSqlHelper()->getCurrentDateTimeFunction(). " as CREATE_TIME,
			SUM(src.FILE_SIZE) as FILE_SIZE,
			SUM(src.FILE_COUNT) as FILE_COUNT,
			SUM(src.DISK_SIZE) as DISK_SIZE,
			SUM(src.DISK_COUNT) as DISK_COUNT,
			SUM(src.VERSION_COUNT) as VERSION_COUNT
		FROM 
		(
			(
				SELECT 
					SUM(ver.SIZE) as FILE_SIZE,
					COUNT(ver.FILE_ID) as FILE_COUNT,
					SUM(ver.SIZE) as DISK_SIZE,
					COUNT(DISTINCT files.ID) as DISK_COUNT,
					COUNT(ver.ID) as VERSION_COUNT
				FROM 
					b_disk_version ver 
					INNER JOIN b_disk_object files
						ON files.ID  = ver.OBJECT_ID
						AND files.TYPE = '".ObjectTable::TYPE_FILE."'
						AND files.ID = files.REAL_OBJECT_ID
					INNER JOIN 
					(
						SELECT 
							attached.OBJECT_ID as OBJECT_ID
						FROM 
							b_disk_attached_object attached
							INNER JOIN b_forum_message message 
								ON message.ID = attached.ENTITY_ID
						WHERE
							attached.ENTITY_TYPE IN($attachedEntitySql)
						GROUP BY 
							attached.OBJECT_ID
						ORDER BY NULL
					) attach_connect
						ON attach_connect.OBJECT_ID = files.ID
			)
			{$attachedForumCommentsSql}
			{$entityUserFieldSource}
		) src
	";

	$columnList = VolumeQueryHelper::prepareInsert(
		[
			'INDICATOR_TYPE',
			'OWNER_ID',
			'CREATE_TIME',
			'FILE_SIZE',
			'FILE_COUNT',
			'DISK_SIZE',
			'DISK_COUNT',
			'VERSION_COUNT',
		],
		$this->getSelect()
	);

	$tableName = VolumeTable::getTableName();

	$connection->queryExecute("INSERT INTO {$tableName} ({$columnList}) {$querySql}");

	return $this;
}