Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
PKPManageFileApiHandler.inc.php
1 <?php
2 
16 // Import the base handler.
17 import('classes.handler.Handler');
18 import('lib.pkp.classes.core.JSONMessage');
19 
21 
26  parent::Handler();
27  $this->addRoleAssignment(
28  array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT, ROLE_ID_REVIEWER, ROLE_ID_AUTHOR),
29  array('deleteFile')
30  );
31  }
32 
33  //
34  // Implement methods from PKPHandler
35  //
36  function authorize($request, &$args, $roleAssignments) {
37  import('classes.security.authorization.SubmissionFileAccessPolicy');
38  $this->addPolicy(new SubmissionFileAccessPolicy($request, $args, $roleAssignments, SUBMISSION_FILE_ACCESS_MODIFY));
39 
40  return parent::authorize($request, $args, $roleAssignments);
41  }
42 
43  //
44  // Public handler methods
45  //
52  function deleteFile($args, $request) {
53  $submissionFile = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILE);
54  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
55  $stageId = $request->getUserVar('stageId');
56  if ($stageId) {
57  // validate the stage id.
58  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
59  $user = $request->getUser();
60  $stageAssignments = $stageAssignmentDao->getBySubmissionAndStageId($submission->getId(), $stageId, null, $user->getId());
61  }
62 
63  assert($submissionFile && $submission); // Should have been validated already
64 
65  $noteDao = DAORegistry::getDAO('NoteDAO');
66  $noteDao->deleteByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId());
67 
68  // Delete all signoffs related with this file.
69  $signoffDao = DAORegistry::getDAO('SignoffDAO'); /* @var $signoffDao SignoffDAO */
70  $signoffFactory = $signoffDao->getAllByAssocType(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId());
71  $signoffs = $signoffFactory->toArray();
72  $notificationMgr = new NotificationManager();
73 
74  foreach ($signoffs as $signoff) {
75  $signoffDao->deleteObject($signoff);
76 
77  // Delete for all users.
78  $notificationMgr->updateNotification(
79  $request,
80  array(NOTIFICATION_TYPE_AUDITOR_REQUEST, NOTIFICATION_TYPE_COPYEDIT_ASSIGNMENT),
81  null,
82  ASSOC_TYPE_SIGNOFF,
83  $signoff->getId()
84  );
85 
86  $notificationMgr->updateNotification(
87  $request,
88  array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF),
89  array($signoff->getUserId()),
90  ASSOC_TYPE_SUBMISSION,
91  $submission->getId()
92  );
93  }
94 
95  // Delete the submission file.
96  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
97 
98  // check to see if we need to remove review_round_file associations
99  if (!$stageAssignments->wasEmpty()) {
100  $submissionFileDao->deleteReviewRoundAssignment($submission->getId(), $stageId, $submissionFile->getFileId(), $submissionFile->getRevision());
101  }
102  $success = (boolean)$submissionFileDao->deleteRevisionById($submissionFile->getFileId(), $submissionFile->getRevision(), $submissionFile->getFileStage(), $submission->getId());
103 
104  if ($success) {
105  if ($submissionFile->getFileStage() == SUBMISSION_FILE_REVIEW_REVISION) {
106  $notificationMgr->updateNotification(
107  $request,
108  array(NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS, NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS),
109  array($submission->getUserId()),
110  ASSOC_TYPE_SUBMISSION,
111  $submission->getId()
112  );
113 
114  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
115  $lastReviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);
116  $notificationMgr->updateNotification(
117  $request,
118  array(NOTIFICATION_TYPE_ALL_REVISIONS_IN),
119  null,
120  ASSOC_TYPE_REVIEW_ROUND,
121  $lastReviewRound->getId()
122  );
123  }
124 
125  $this->indexSubmissionFiles($submission, $submissionFile);
126  $fileManager = $this->getFileManager($submission->getContextId(), $submission->getId());
127  $fileManager->deleteFile($submissionFile->getFileId(), $submissionFile->getRevision());
128 
129  $this->setupTemplate($request);
130  $user = $request->getUser();
131  if (!$request->getUserVar('suppressNotification')) NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedFile')));
132 
133  $this->logDeletionEvent($request, $submission, $submissionFile, $user);
134 
135  return DAO::getDataChangedEvent();
136  } else {
137  $json = new JSONMessage(false);
138  return $json->getString();
139  }
140  }
141 
148  function indexSubmissionFiles($submission, $submissionFile) {
149  assert(false);
150  }
151 
158  function getFileManager($contextId, $submissionId) {
159  import('lib.pkp.classes.file.SubmissionFileManager');
160  return new SubmissionFileManager($contextId, $submissionId);
161  }
162 
171  function logDeletionEvent($request, $submission, $submissionFile, $user) {
172  assert(false);
173  }
174 }
175 
176 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
indexSubmissionFiles($submission, $submissionFile)
Class to control (write) access to submissions and (read) access to submission details in OJS...
setupTemplate($request)
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
Base request handler application class.
Definition: Handler.inc.php:19
getFileManager($contextId, $submissionId)
Class defining an AJAX API for file manipulation.
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:632
& getAuthorizedContextObject($assocType)
logDeletionEvent($request, $submission, $submissionFile, $user)