/** * @param $name * @param $targetElementId * @param CWebDavTmpFile $tmpFile * @return array|boolean */ public function updateFile($name, $targetElementId, CWebDavTmpFile $tmpFile) { /** @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->getCurrentUserSecurityContext())) { throw new CWebDavAccessDeniedException(); } $fileArray = CFile::MakeFileArray($tmpFile->getAbsolutePath()); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155))); return false; } if ($file->uploadVersion($fileArray, $this->getUser()->getId())) { $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156))); $this->errorCollection->add($file->getErrors()); return false; }
/** * @param $name * @param $targetElementId * @param CWebDavTmpFile $tmpFile * @throws CWebDavAccessDeniedException * @throws WebDavStorageBreakDownException * @return bool|array */ public function updateFile($name, $targetElementId, CWebDavTmpFile $tmpFile) { $this->init(); $name = $this->getWebDav()->correctName($name); if (!$this->checkRights('update', array('name' => $name, 'targetElementId' => $targetElementId))) { throw new CWebDavAccessDeniedException(); } $options = array('new' => false, 'FILE_NAME' => $name, 'ELEMENT_ID' => $targetElementId, 'arUserGroups' => $this->getWebDav()->USER['GROUPS'], 'TMP_FILE' => $tmpFile->getAbsolutePath(), 'WIDTH' => $tmpFile->width, 'HEIGHT' => $tmpFile->height); $this->getDb()->startTransaction(); if (!$this->getWebDav()->put_commit($options)) { $this->getDb()->rollback(); $tmpFile->delete(); return false; } $this->getDb()->commit(); $tmpFile->delete(); if (!empty($options['ELEMENT_ID'])) { $file = $this->getFile(null, array('id' => $options['ELEMENT_ID']), true); if ($file) { return $file; } } throw new WebDavStorageBreakDownException('bd updateFile'); }