Inheritance: extends FileManager
 /**
  * Save the new library file
  * @param $userId int The current user ID (for validation purposes)
  */
 function execute($userId)
 {
     // Fetch the temporary file storing the uploaded library file
     $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
     $temporaryFile =& $temporaryFileDao->getTemporaryFile($this->getData('temporaryFileId'), $userId);
     $libraryFileDao =& DAORegistry::getDAO('LibraryFileDAO');
     $libraryFileManager = new LibraryFileManager($this->pressId);
     // Convert the temporary file to a library file and store
     $libraryFile =& $libraryFileManager->copyFromTemporaryFile($temporaryFile);
     assert($libraryFile);
     $libraryFile->setPressId($this->pressId);
     $libraryFile->setName($this->getData('libraryFileName'), null);
     // Localized
     $libraryFile->setType($this->fileType);
     $libraryFileDao->insertObject($libraryFile);
     // Clean up the temporary file
     import('classes.file.TemporaryFileManager');
     $temporaryFileManager = new TemporaryFileManager();
     $temporaryFileManager->deleteFile($this->getData('temporaryFileId'), $userId);
 }
Example #2
0
 /**
  * Save the new library file.
  * @param $userId int The current user ID (for validation purposes).
  * @return $fileId int The new library file id.
  */
 function execute($userId)
 {
     // Fetch the temporary file storing the uploaded library file
     $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
     $temporaryFile = $temporaryFileDao->getTemporaryFile($this->getData('temporaryFileId'), $userId);
     $libraryFileDao = DAORegistry::getDAO('LibraryFileDAO');
     $libraryFileManager = new LibraryFileManager($this->contextId);
     // Convert the temporary file to a library file and store
     $libraryFile = $libraryFileManager->copyFromTemporaryFile($temporaryFile, $this->getData('fileType'));
     assert(isset($libraryFile));
     $libraryFile->setContextId($this->contextId);
     $libraryFile->setName($this->getData('libraryFileName'), null);
     // Localized
     $libraryFile->setType($this->getData('fileType'));
     $fileId = $libraryFileDao->insertObject($libraryFile);
     // Clean up the temporary file
     import('lib.pkp.classes.file.TemporaryFileManager');
     $temporaryFileManager = new TemporaryFileManager();
     $temporaryFileManager->deleteFile($this->getData('temporaryFileId'), $userId);
     return $fileId;
 }
 /**
  * Delete a file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function deleteFile($args, $request)
 {
     $fileId = isset($args['fileId']) ? $args['fileId'] : null;
     $router = $request->getRouter();
     $context = $router->getContext($request);
     if ($fileId) {
         $libraryFileManager = new LibraryFileManager($context->getId());
         $libraryFileManager->deleteFile($fileId);
         return DAO::getDataChangedEvent();
     }
     $json = new JSONMessage(false);
     return $json->getString();
 }
Example #4
0
 /**
  * Download a library file.
  * @param $args array
  * @param $request Request
  */
 function downloadLibraryFile($args, $request)
 {
     import('classes.file.LibraryFileManager');
     $context = $request->getContext();
     $libraryFileManager = new LibraryFileManager($context->getId());
     $libraryFileDao = DAORegistry::getDAO('LibraryFileDAO');
     $libraryFile = $libraryFileDao->getById($request->getUserVar('libraryFileId'));
     if ($libraryFile) {
         // If this file has a submission ID, ensure that the current
         // user has access to that submission.
         if ($libraryFile->getSubmissionId()) {
             $allowedAccess = false;
             // Managers are always allowed access.
             $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
             if (array_intersect($userRoles, array(ROLE_ID_MANAGER))) {
                 $allowedAccess = true;
             }
             // Check for specific assignments.
             $user = $request->getUser();
             $userStageAssignmentDao = DAORegistry::getDAO('UserStageAssignmentDAO');
             $assignedUsers = $userStageAssignmentDao->getUsersBySubmissionAndStageId($libraryFile->getSubmissionId(), WORKFLOW_STAGE_ID_SUBMISSION);
             if (!$assignedUsers->wasEmpty()) {
                 while ($assignedUser = $assignedUsers->next()) {
                     if ($assignedUser->getId() == $user->getId()) {
                         $allowedAccess = true;
                         break;
                     }
                 }
             }
         } else {
             $allowedAccess = true;
             // this is a Context submission document, default to access policy.
         }
         if ($allowedAccess) {
             $filePath = $libraryFileManager->getBasePath() . $libraryFile->getOriginalFileName();
             $libraryFileManager->downloadFile($filePath);
         } else {
             fatalError('Unauthorized access to library file.');
         }
     }
 }
 /**
  * Category rows only have one cell and one label.  This is it.
  * return string
  */
 function getCategoryLabel()
 {
     $context = $this->getContext();
     $libraryFileManager = new LibraryFileManager($context->getId());
     return __($libraryFileManager->getTitleKeyFromType($this->getData()));
 }
 /**
  * Delete a file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function deleteFile($args, &$request)
 {
     $fileId = isset($args['fileId']) ? $args['fileId'] : null;
     $router =& $request->getRouter();
     $press =& $router->getContext($request);
     if ($fileId) {
         import('classes.file.LibraryFileManager');
         $libraryFileManager = new LibraryFileManager($press->getId());
         $libraryFileManager->deleteFile($fileId);
         return DAO::getDataChangedEvent($fileId);
     }
     $json = new JSON(false);
     return $json->getString();
 }
Example #7
0
 /**
  * Upload library file
  * @param $args array
  * @param $request PKPRequest
  */
 function uploadFile($args, &$request)
 {
     $router =& $request->getRouter();
     $context =& $router->getContext($request);
     import('classes.file.LibraryFileManager');
     $libraryFileManager = new LibraryFileManager($context->getId());
     if ($libraryFileManager->uploadedFileExists('libraryFile')) {
         return $libraryFileManager->handleUpload($this->fileType, 'libraryFile', $this->fileId);
     }
 }
 /**
  * Delete a file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function deleteFile($args, &$request)
 {
     $fileId = isset($args['rowId']) ? $args['rowId'] : null;
     $router =& $request->getRouter();
     $press =& $router->getContext($request);
     if ($fileId) {
         import('classes.file.LibraryFileManager');
         $libraryFileManager = new LibraryFileManager($press->getId());
         $libraryFileManager->deleteFile($fileId);
         $json = new JSON('true');
     } else {
         $json = new JSON('false');
     }
     return $json->getString();
 }