/** * * @return null|string */ protected function getFileSrcToPublish() { if ($this->isSpecificVersion()) { $fileId = $this->version->getFileId(); } else { $fileId = $this->file->getFileId(); } $fileArray = \CFile::makeFileArray($fileId); if (!is_array($fileArray)) { return null; } return $fileArray['tmp_name']; }
/** * Restores file from the version. * * The method is similar with (@see Bitrix\Disk\File::addVersion()). * * @param Version $version Version which need to restore. * @param int $createdBy Id of user. * @return bool */ public function restoreFromVersion(Version $version, $createdBy) { $this->errorCollection->clear(); if ($version->getObjectId() != $this->id) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_COULD_NOT_RESTORE_FROM_ANOTHER_OBJECT'), self::ERROR_COULD_NOT_RESTORE_FROM_OBJECT))); return false; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $forkFileId = \CFile::copyFile($version->getFileId(), true); if (!$forkFileId) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_COULD_NOT_COPY_FILE'), self::ERROR_COULD_NOT_COPY_FILE))); return false; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ if ($this->addVersion(\CFile::getFileArray($forkFileId), $createdBy, true) === null) { return false; } return true; }