/** * 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); }
/** * 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; }