- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/bitrix24disk/legacy/diskstorage.php
- Класс: BitrixDiskBitrix24DiskLegacyDiskStorage
- Вызов: DiskStorage::updateFile
public function updateFile($name, $targetElementId, TmpFile $tmpFile, array $data = array())
{
$this->addShutdownTask(function() use($tmpFile){
$tmpFile->delete();
});
/** @var File $file */
$file = File::loadById($targetElementId);
if(!$file)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154)));
return false;
}
if(!$file->canUpdate($this->storage->getSecurityContext($this->userId)))
{
throw new AccessDeniedException;
}
/** @var array $fileArray */
if($tmpFile->isCloud() && $tmpFile->getContentType())
{
$fileId = CFile::saveFile(array(
'name' => $tmpFile->getFilename(),
'tmp_name' => $tmpFile->getAbsolutePath(),
'type' => $tmpFile->getContentType(),
'width' => $tmpFile->getWidth(),
'height' => $tmpFile->getHeight(),
'MODULE_ID' => Driver::INTERNAL_MODULE_ID,
), Driver::INTERNAL_MODULE_ID, true, true);
$fileArray = CFile::getFileArray($fileId);
if(!$fileArray)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " getFileArray", 1115541)));
return false;
}
if(!empty($data['originalTimestamp']))
{
$fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
}
if($file->addVersion($fileArray, $this->getUser()->getId()))
{
$file->changeEtag($tmpFile->getToken());
$this->loadTree();
$response = $this->formatFileToResponse($file);
Driver::getInstance()->sendEvent($this->userId, 'fileUploaded', $response);
return $response;
}
elseif($file->getErrorByCode($file::ERROR_EXCLUSIVE_LOCK))
{
$forkedFile = $this->processWithLockedFile($file, $fileArray, $fileId);
if($forkedFile)
{
$this->errorCollection->clear();
$this->errorCollection[] = new Error(
'Created a new file.',
self::ERROR_CREATE_FORK_FILE,
$forkedFile
);
}
}
else
{
CFile::delete($fileId);
}
}
else
{
$fileArray = CFile::makeFileArray($tmpFile->getAbsolutePath());
if(!$fileArray)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155)));
return false;
}
if(!empty($data['originalTimestamp']))
{
$fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
}
if($file->uploadVersion($fileArray, $this->getUser()->getId()))
{
$file->changeEtag($tmpFile->getToken());
$this->loadTree();
$response = $this->formatFileToResponse($file);
Driver::getInstance()->sendEvent($this->userId, 'fileUploaded', $response);
return $response;
}
elseif($file->getErrorByCode($file::ERROR_EXCLUSIVE_LOCK))
{
$forkedFile = $this->processWithLockedFile($file, $fileArray);
if($forkedFile)
{
$this->errorCollection->clear();
$this->errorCollection[] = new Error(
'Created a new file.',
self::ERROR_CREATE_FORK_FILE,
$forkedFile
);
}
}
}
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156)));
$this->errorCollection->add($file->getErrors());
return false;
}