• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/file.php
  • Класс: BitrixDiskFile
  • Вызов: File::updateContent
public function updateContent(array $file, $updatedBy)
{
	$this->errorCollection->clear();

	static::checkRequiredInputParams($file, array(
		'ID', 'FILE_SIZE'
	));

	$objectLock = null;
	if(Configuration::isEnabledObjectLock())
	{
		$objectLock = $this->getLock();
		if($objectLock && $objectLock->isExclusive() && !$objectLock->canUnlock($updatedBy))
		{
			$this->errorCollection[] = new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_EXCLUSIVE_LOCK'), self::ERROR_EXCLUSIVE_LOCK);
			return false;
		}
	}

	//todo inc in DB by expression
	$updateData = array(
		'GLOBAL_CONTENT_VERSION' => (int)$this->getGlobalContentVersion() + 1,
		'FILE_ID' => $file['ID'],
		'ETAG' => empty($file['ETAG'])? $this->generateEtag() : $file['ETAG'], //each time we update etag field. It is random string
		'SIZE' => $file['FILE_SIZE'],
		'UPDATE_TIME' => empty($file['UPDATE_TIME'])? new DateTime() : $file['UPDATE_TIME'],
		'UPDATED_BY' => $updatedBy,
	);

	$this->prevFileId = $this->fileId;
	$success = $this->update($updateData);

	if(!$success)
	{
		$this->prevFileId = null;
		return false;
	}

	$this->changeParentUpdateTime(new DateTime(), $updatedBy);

	if ($objectLock instanceof ObjectLock && Configuration::shouldAutoUnlockObjectOnSave())
	{
		$this->unlock($updatedBy);
	}

	$this->updateLinksAttributes(array(
		'ETAG' => $this->getEtag(),
		'GLOBAL_CONTENT_VERSION' => $this->getGlobalContentVersion(),
		'SIZE' => $file['FILE_SIZE'],
		'UPDATE_TIME' => $this->getUpdateTime(),
		'SYNC_UPDATE_TIME' => $this->getSyncUpdateTime(),
		'UPDATED_BY' => $updatedBy,
	));
	$this->updateRelated();

	$driver = Driver::getInstance();
	if ($this->getStorage()->isUseInternalRights())
	{
		$driver->getRecentlyUsedManager()->push(
			$updatedBy,
			$this
		);
	}

	if ($this->getGlobalContentVersion() <= 1)
	{
		//initial full index
		$driver->getIndexManager()->indexFile($this);
	}
	else
	{
		//just update content
		$driver->getIndexManager()->updateFileContent($this);
	}

	$objectEvent = $this->makeObjectEvent(
		'contentUpdated',
		[
			'object' => [
				'id' => (int)$this->getId(),
				'name' => $this->getName(),
				'updatedBy' => (int)$this->getUpdatedBy(),
			],
			'updatedBy' => [
				'infoToken' => UserInfoToken::generateTimeLimitedToken($this->getUpdatedBy(), $this->getId()),
			]
		]
	);
	$objectEvent->sendToObjectChannel();

	//todo little hack...We don't synchronize file in folder with uploaded files. And we have not to send notify by pull
	if($this->parent === null || $this->parent && $this->parent->getCode() !== Folder::CODE_FOR_UPLOADED_FILES)
	{
		$driver->sendChangeStatusToSubscribers($this, 'quick');

		$updatedBy = $this->getUpdatedBy();
		if($updatedBy)
		{
			$driver->sendEvent($updatedBy, 'live', array(
				'objectId' => $this->getId(),
				'action' => 'commit',
				'contentVersion' => (int)$this->getGlobalContentVersion(),
				'size' => (int)$this->getSize(),
				'formatSize' => (string)CFile::formatSize($this->getSize()),
			));
		}
	}

	return true;
}