Copy a temporary file to a submission file.
public temporaryFileToSubmissionFile ( $temporaryFile, $fileStage, $uploaderUserId, $uploaderUserGroupId, $revisedFileId, $genreId, $assocType, $assocId ) : integer | ||
$temporaryFile | SubmissionFile | |
$fileStage | integer | |
$assocType | integer | |
$assocId | integer | |
리턴 | integer | the file ID (false if upload failed) |
/** * @see Form::execute() * @param $request Request * @return MonographFile if successful, otherwise null */ function execute($request) { // Retrieve the signoff we're working with. $signoffDao = DAORegistry::getDAO('SubmissionFileSignoffDAO'); $signoff = $signoffDao->getById($this->getData('signoffId')); assert(is_a($signoff, 'Signoff')); // Insert the note, if existing content and/or file. $temporaryFileId = $this->getData('temporaryFileId'); if ($temporaryFileId || $this->getData('newNote')) { $user = $request->getUser(); $noteDao = DAORegistry::getDAO('NoteDAO'); $note = $noteDao->newDataObject(); $note->setUserId($user->getId()); $note->setContents($this->getData('newNote')); $note->setAssocType(ASSOC_TYPE_SIGNOFF); $note->setAssocId($signoff->getId()); $noteId = $noteDao->insertObject($note); $note->setId($noteId); // Upload the file, if any, and associate it with the note. if ($temporaryFileId) { // Fetch the temporary file storing the uploaded library file $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); // Upload the file. // Bring in the SUBMISSION_FILE_* constants import('classes.monograph.MonographFile'); $press = $request->getPress(); import('lib.pkp.classes.file.SubmissionFileManager'); $monographFileManager = new SubmissionFileManager($press->getId(), $this->getMonographId()); $signoffFileId = $monographFileManager->temporaryFileToSubmissionFile($temporaryFile, SUBMISSION_FILE_NOTE, $signoff->getUserId(), $signoff->getUserGroupId(), $signoff->getAssocId(), null, ASSOC_TYPE_NOTE, $noteId); // FIXME: Currently the code allows for a signoff to be // added many times (if the option is presented in the // form). Need to delete previous files uploaded to this // signoff. Partially due to #6799. // Mark ALL the signoffs for this user as completed with this file upload. if ($signoffFileId) { $signoff->setFileId($signoffFileId); $signoff->setFileRevision(1); } } // Now mark the signoff as completed (we have a note with content // or a file or both). $signoff->setDateCompleted(Core::getCurrentDate()); $signoffDao->updateObject($signoff); $notificationMgr = new NotificationManager(); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_AUDITOR_REQUEST), array($signoff->getUserId()), ASSOC_TYPE_SIGNOFF, $signoff->getId()); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF), array($signoff->getUserId()), ASSOC_TYPE_SUBMISSION, $this->getMonographId()); // log the event. import('lib.pkp.classes.log.SubmissionFileLog'); import('lib.pkp.classes.log.SubmissionFileEventLogEntry'); // constants $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); $monographFile = $submissionFileDao->getLatestRevision($signoff->getFileId()); if (isset($monographFile)) { SubmissionFileLog::logEvent($request, $monographFile, SUBMISSION_LOG_FILE_AUDIT_UPLOAD, 'submission.event.fileAuditUploaded', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername())); } return $signoff->getId(); } }
function execute($request, $userRoles) { $user = $request->getUser(); // Retrieve the signoff we're working with. $signoffDao = DAORegistry::getDAO('SubmissionFileSignoffDAO'); $signoff = $signoffDao->getById($this->getData('signoffId')); assert(is_a($signoff, 'Signoff')); // Insert the note, if existing content and/or file. $temporaryFileId = $this->getData('temporaryFileId'); if ($temporaryFileId || $this->getData('newNote')) { $noteDao = DAORegistry::getDAO('NoteDAO'); $note = $noteDao->newDataObject(); $note->setUserId($user->getId()); $note->setContents($this->getData('newNote')); $note->setAssocType(ASSOC_TYPE_SIGNOFF); $note->setAssocId($signoff->getId()); $noteId = $noteDao->insertObject($note); $note->setId($noteId); // Upload the file, if any, and associate it with the note. if ($temporaryFileId) { // Fetch the temporary file storing the uploaded library file $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $temporaryFile =& $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); // Upload the file. // Bring in the SUBMISSION_FILE_* constants import('lib.pkp.classes.submission.SubmissionFile'); $context = $request->getContext(); import('lib.pkp.classes.file.SubmissionFileManager'); $submissionFileManager = new SubmissionFileManager($context->getId(), $this->_submissionId); // Get the submission file that is associated with the signoff. $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /** @var $submissionFileDao SubmissionFileDAO */ $signoffFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId()); assert(is_a($signoffFile, 'SubmissionFile')); $noteFileId = $submissionFileManager->temporaryFileToSubmissionFile($temporaryFile, SUBMISSION_FILE_NOTE, $signoff->getUserId(), $signoff->getUserGroupId(), null, $signoffFile->getGenreId(), ASSOC_TYPE_NOTE, $noteId); } if ($user->getId() == $signoff->getUserId() && !$signoff->getDateCompleted()) { // Considered as a signoff response. // Mark the signoff as completed (we have a note with content // or a file or both). $signoff->setDateCompleted(Core::getCurrentDate()); $signoffDao->updateObject($signoff); $notificationMgr = new NotificationManager(); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_AUDITOR_REQUEST), array($signoff->getUserId()), ASSOC_TYPE_SIGNOFF, $signoff->getId()); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF), array($signoff->getUserId()), ASSOC_TYPE_SUBMISSION, $this->_submissionId); // Define the success trivial notification locale key. $successLocaleKey = 'notification.uploadedResponse'; // log the event. import('lib.pkp.classes.log.SubmissionFileLog'); import('lib.pkp.classes.log.SubmissionFileEventLogEntry'); // constants $submissionDao = Application::getSubmissionDAO(); $submission = $submissionDao->getById($this->_submissionId); $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); $submissionFile = $submissionFileDao->getLatestRevision($signoff->getFileId()); if (isset($submissionFile)) { SubmissionFileLog::logEvent($request, $submissionFile, SUBMISSION_LOG_FILE_AUDIT_UPLOAD, 'submission.event.fileAuditUploaded', array('file' => $submissionFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername())); } } else { // Common note addition. if ($user->getId() !== $signoff->getUserId() && array_intersect($userRoles, array(ROLE_ID_MANAGER, ROLE_ID_ASSISTANT, ROLE_ID_SUB_EDITOR))) { // If the current user is a context/series/sub editor or assistant, open the signoff again. if ($signoff->getDateCompleted()) { $signoff->setDateCompleted(null); $signoffDao->updateObject($signoff); $notificationMgr = new NotificationManager(); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_AUDITOR_REQUEST), array($signoff->getUserId()), ASSOC_TYPE_SIGNOFF, $signoff->getId()); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF), array($signoff->getUserId()), ASSOC_TYPE_SUBMISSION, $this->_submissionId); } } $successLocaleKey = 'notification.addedNote'; } NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __($successLocaleKey))); return $signoff->getId(); } }
/** * Save the email in the submission email log. */ function log($request = null) { import('classes.log.SubmissionEmailLogEntry'); $entry = new SubmissionEmailLogEntry(); $submission = $this->submission; // Event data $entry->setEventType($this->logEventType); $entry->setAssocType(ASSOC_TYPE_SUBMISSION); $entry->setAssocId($submission->getId()); $entry->setDateSent(Core::getCurrentDate()); // User data if ($request) { $user = $request->getUser(); $entry->setSenderId($user == null ? 0 : $user->getId()); $entry->setIPAddress($request->getRemoteAddr()); } else { // No user supplied -- this is e.g. a cron-automated email $entry->setSenderId(0); } // Email data $entry->setSubject($this->getSubject()); $entry->setBody($this->getBody()); $entry->setFrom($this->getFromString(false)); $entry->setRecipients($this->getRecipientString()); $entry->setCcs($this->getCcString()); $entry->setBccs($this->getBccString()); // Add log entry $logDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); $logEntryId = $logDao->insertObject($entry); // Add attachments import('lib.pkp.classes.file.SubmissionFileManager'); $submissionFileManager = new SubmissionFileManager($submission->getContextId(), $submission->getId()); foreach ($this->getAttachmentFiles() as $attachment) { $submissionFileManager->temporaryFileToSubmissionFile($attachment, SUBMISSION_FILE_ATTACHMENT, ASSOC_TYPE_SUBMISSION_EMAIL_LOG_ENTRY, $logEntryId); } }