/** * @param FileData $fileData * @return null|EditSession * @throws \Bitrix\Main\NotImplementedException */ protected function addFileEditSessionByCurrentUser(FileData $fileData) { $data = array('OBJECT_ID' => $this->file->getId(), 'USER_ID' => $this->getUser()->getId(), 'OWNER_ID' => $this->getUser()->getId(), 'SERVICE' => $this->documentHandler->getCode(), 'SERVICE_FILE_ID' => $fileData->getId(), 'SERVICE_FILE_LINK' => $fileData->getLinkInService()); if ($this->isSpecificVersion()) { $data['VERSION_ID'] = $this->version->getId(); $data['IS_EXCLUSIVE'] = 1; } return EditSession::add($data, $this->errorCollection); }
protected function processActionDownloadVersion() { $this->version = $this->file->getVersion($this->versionId); if (!$this->version) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOWNLOAD_CONTROLLER_ERROR_COULD_NOT_FIND_VERSION'), self::ERROR_COULD_NOT_FIND_VERSION))); $this->sendJsonErrorResponse(); } $fileData = $this->version->getFile(); \CFile::viewByUser($fileData, array("force_download" => false, 'cache_time' => 0, 'attachment_name' => $this->file->getName())); }
protected function initializeVersion($versionId) { $this->version = Version::loadById($versionId, array('OBJECT.STORAGE')); if (!$this->version) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_FILE))); $this->sendJsonResponse(array('status' => self::STATUS_NOT_FOUND)); } $this->file = $this->version->getObject(); if (!$this->file) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_VERSION'), self::ERROR_COULD_NOT_FIND_VERSION))); $this->sendJsonResponse(array('status' => self::STATUS_NOT_FOUND)); } }
/** * @param $id * @return Version|null */ protected static function getVersionById($id) { if (!isset(static::$loadedVersions[$id])) { static::$loadedVersions[$id] = Version::loadById($id, array('OBJECT.STORAGE')); } return static::$loadedVersions[$id]; }
/** * Returns the list attributes which is connected with another models. * @return array */ public static function getMapReferenceAttributes() { return array('OBJECT' => File::className(), 'VERSION' => Version::className()); }
/** * Gets data attributes by version to viewer. * @param Version $version Target version. * @param array $additionalParams Additional parameters 'canUpdate', 'showStorage'. * @return string */ public static function getAttributesByVersion(Version $version, array $additionalParams = array()) { $object = $version->getObject(); $objectId = $object->getId(); $urlManager = Driver::getInstance()->getUrlManager(); if (DocumentHandler::isEditable($version->getExtension())) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($version->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowVersionByService($objectId, $version->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($version->getExtension()) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" '; } elseif (Viewer::isViewable($object->getExtension())) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($version->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowVersionByService($objectId, $version->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($version->getCreateTime()) . '" '; } elseif (TypeFile::isImage($object)) { $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($object->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" '; } else { $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($object->getName()) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($version->getCreateUser() ? $version->getCreateUser()->getFormattedName() : '') . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($version->getCreateTime()) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" '; } $dataAttributesForViewer .= " data-bx-version=\"\"" . " data-bx-history=\"\"" . " data-bx-historyPage=\"\""; if (!empty($additionalParams['canUpdate'])) { $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlForStartEditVersion($objectId, $version->getId(), 'gdrive') . '" '; } if (!empty($additionalParams['showStorage'])) { $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" '; } return $dataAttributesForViewer; }
/** * Returns the list attributes which is connected with another models. * @return array */ public static function getMapReferenceAttributes() { return array('CREATE_USER' => array('class' => User::className(), 'select' => User::getFieldsForSelect()), 'FILE' => array('orm_alias' => 'OBJECT', 'class' => File::className()), 'VERSION' => Version::className()); }
public static function getMapReferenceAttributes() { return array('OBJECT' => BaseObject::className(), 'VERSION' => Version::className(), 'TMP_FILE' => TmpFile::className(), 'USER' => array('class' => User::className(), 'select' => User::getFieldsForSelect())); }
/** * Gets url to download version of file. * @param Version $version Version of file. * @return string */ public function getUrlForDownloadVersion(Version $version) { return $this->getUrlDownloadController('downloadVersion', array('fileId' => $version->getObjectId(), 'versionId' => $version->getId())); }
/** * @return array */ public static function getMapReferenceAttributes() { $userClassName = User::className(); $fields = User::getFieldsForSelect(); return array('OBJECT' => File::className(), 'VERSION' => Version::className(), 'USER' => array('class' => $userClassName, 'select' => $fields), 'OWNER' => array('class' => $userClassName, 'select' => $fields)); }
/** * 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; }
/** * Deletes file and all connected data and entities (@see Sharing, @see Rights, etc). * @param int $deletedBy Id of user. * @return bool * @throws \Bitrix\Main\ArgumentNullException */ public function delete($deletedBy) { $this->errorCollection->clear(); $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } foreach ($this->getSharingsAsReal() as $sharing) { $sharing->delete($deletedBy); } //with status unreplied, declined (not approved) $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id)); if (!$success) { return false; } foreach ($this->getAttachedObjects() as $attached) { $attached->delete(); } unset($attached); if (Loader::includeModule('bizproc')) { BizProcDocument::deleteWorkflowsFile($this->id); } SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id)); $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } $versionQuery = Version::getList(array('filter' => array('OBJECT_ID' => $this->id))); while ($versionData = $versionQuery->fetch()) { $version = Version::buildFromArray($versionData); $version->setAttributes(array('OBJECT' => $this)); $version->delete(); } unset($version, $versionQuery); $success = VersionTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } DeletedLog::addFile($this, $deletedBy, $this->errorCollection); \CFile::delete($this->fileId); $deleteResult = FileTable::delete($this->id); if (!$deleteResult->isSuccess()) { return false; } Driver::getInstance()->getIndexManager()->dropIndex($this); if (!$this->isLink()) { //todo potential - very hard operation. foreach (File::getModelList(array('filter' => array('REAL_OBJECT_ID' => $this->id, '!=REAL_OBJECT_ID' => $this->id))) as $link) { $link->delete($deletedBy); } unset($link); } $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy)); $event->send(); return true; }
private function processGridActions($gridId) { $postAction = 'action_button_' . $gridId; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST[$postAction]) && check_bitrix_sessid()) { if ($_POST[$postAction] == 'delete') { if (empty($_POST['ID'])) { return; } if (!$this->file->canDelete($this->file->getStorage()->getCurrentUserSecurityContext()) || !$this->file->canRestore($this->file->getStorage()->getCurrentUserSecurityContext())) { return; } foreach ($_POST['ID'] as $targetId) { /** @var Version $version */ $version = Version::loadById($targetId); if (!$version) { continue; } $version->delete(); } } } }