00001 <?php
00002
00015
00016 import('classes.handler.Handler');
00017 import('lib.pkp.classes.core.JSONMessage');
00018
00019 class ManageFileApiHandler extends Handler {
00020
00024 function ManageFileApiHandler() {
00025 parent::Handler();
00026 $this->addRoleAssignment(
00027 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT, ROLE_ID_REVIEWER, ROLE_ID_AUTHOR),
00028 array('deleteFile')
00029 );
00030 }
00031
00032
00033
00034
00035
00036 function authorize(&$request, $args, $roleAssignments) {
00037 import('classes.security.authorization.OmpMonographFileAccessPolicy');
00038 $this->addPolicy(new OmpMonographFileAccessPolicy($request, $args, $roleAssignments, MONOGRAPH_FILE_ACCESS_MODIFY));
00039
00040 return parent::authorize($request, $args, $roleAssignments);
00041 }
00042
00043
00044
00045
00052 function deleteFile($args, &$request) {
00053 $monographFile =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH_FILE);
00054 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00055 $stageId =& $request->getUserVar('stageId');
00056 if ($stageId) {
00057
00058 $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00059 $user =& $request->getUser();
00060 $stageAssignments =& $stageAssignmentDao->getBySubmissionAndStageId($monograph->getId(), $stageId, null, $user->getUserId());
00061 }
00062
00063 assert($monographFile && $monograph);
00064
00065 $noteDao =& DAORegistry::getDAO('NoteDAO');
00066 $notes =& $noteDao->getByAssoc(ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileId());
00067 while ($note =& $notes->next()) {
00068 $noteDao->deleteById($note->getId());
00069 unset($note);
00070 }
00071
00072
00073 $signoffDao = DAORegistry::getDAO('SignoffDAO');
00074 $signoffFactory =& $signoffDao->getAllByAssocType(ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileId());
00075 $signoffs = $signoffFactory->toArray();
00076
00077 foreach ($signoffs as $signoff) {
00078 $signoffDao->deleteObject($signoff);
00079
00080
00081 $notificationMgr = new NotificationManager();
00082 $notificationMgr->updateAuditorRequestNotification($signoff, $request, true);
00083
00084
00085 $notificationMgr->updateSignoffNotification($signoff, $request);
00086
00087
00088 $notificationMgr->deleteCopyeditRequestNotification($signoff, $request);
00089 }
00090
00091
00092 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00093
00094
00095
00096 if (!$stageAssignments->wasEmpty()) {
00097 $submissionFileDao->deleteReviewRoundAssignment($monograph->getId(), $stageId, $monographFile->getFileId(), $monographFile->getRevision());
00098 }
00099 $success = (boolean)$submissionFileDao->deleteRevisionById($monographFile->getFileId(), $monographFile->getRevision(), $monographFile->getFileStage(), $monograph->getId());
00100
00101 if ($success) {
00102
00103 if ($monographFile->getFileStage() == MONOGRAPH_FILE_PROOF) {
00104 if ($monograph->getDatePublished()) {
00105 import('classes.search.MonographSearchIndex');
00106 MonographSearchIndex::indexMonographFiles($monograph);
00107 }
00108 }
00109 import('classes.file.MonographFileManager');
00110 $monographFileManager = new MonographFileManager($monograph->getPressId(), $monograph->getId());
00111 $monographFileManager->deleteFile($monographFile->getFileId(), $monographFile->getRevision());
00112 $this->setupTemplate();
00113 $user =& $request->getUser();
00114 NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedFile')));
00115
00116
00117 import('classes.log.MonographFileLog');
00118 import('classes.log.MonographFileEventLogEntry');
00119
00120 if ($monographFile->getRevision() > 1) {
00121 MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_REVISION_DELETE, 'submission.event.revisionDeleted', array('fileStage' => $monographFile->getFileStage(), 'sourceFileId' => $monographFile->getSourceFileId(), 'fileId' => $monographFile->getFileId(), 'fileRevision' => $monographFile->getRevision(), 'originalFileName' => $monographFile->getOriginalFileName(), 'submissionId' => $monograph->getId(), 'username' => $user->getUsername()));
00122 } else {
00123 MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_DELETE, 'submission.event.fileDeleted', array('fileStage' => $monographFile->getFileStage(), 'sourceFileId' => $monographFile->getSourceFileId(), 'fileId' => $monographFile->getFileId(), 'fileRevision' => $monographFile->getRevision(), 'originalFileName' => $monographFile->getOriginalFileName(), 'submissionId' => $monograph->getId(), 'username' => $user->getUsername()));
00124 }
00125
00126 if ($monographFile->getRevision() == 1 && $monographFile->getSourceFileId() == null) {
00127 import('classes.log.MonographLog');
00128 import('classes.log.MonographEventLogEntry');
00129 MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_LAST_REVISION_DELETED, 'submission.event.lastRevisionDeleted', array('title' => $monographFile->getOriginalFileName(), 'submissionId' => $monograph->getId(), 'username' => $user->getUsername()));
00130 }
00131
00132 return DAO::getDataChangedEvent();
00133 } else {
00134 $json = new JSONMessage(false);
00135 return $json->getString();
00136 }
00137 }
00138 }
00139
00140 ?>