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  $notes = $noteDao->getByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId());
67  while ($note = $notes->next()) {
68  $noteDao->deleteById($note->getId());
69  }
70 
71  // Delete all signoffs related with this file.
72  $signoffDao = DAORegistry::getDAO('SignoffDAO'); /* @var $signoffDao SignoffDAO */
73  $signoffFactory = $signoffDao->getAllByAssocType(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId());
74  $signoffs = $signoffFactory->toArray();
75  $notificationMgr = new NotificationManager();
76 
77  foreach ($signoffs as $signoff) {
78  $signoffDao->deleteObject($signoff);
79 
80  // Delete for all users.
81  $notificationMgr->updateNotification(
82  $request,
83  array(NOTIFICATION_TYPE_AUDITOR_REQUEST, NOTIFICATION_TYPE_COPYEDIT_ASSIGNMENT),
84  null,
85  ASSOC_TYPE_SIGNOFF,
86  $signoff->getId()
87  );
88 
89  $notificationMgr->updateNotification(
90  $request,
91  array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF),
92  array($signoff->getUserId()),
93  ASSOC_TYPE_SUBMISSION,
94  $submission->getId()
95  );
96  }
97 
98  // Delete the submission file.
99  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
100 
101  // check to see if we need to remove review_round_file associations
102  if (!$stageAssignments->wasEmpty()) {
103  $submissionFileDao->deleteReviewRoundAssignment($submission->getId(), $stageId, $submissionFile->getFileId(), $submissionFile->getRevision());
104  }
105  $success = (boolean)$submissionFileDao->deleteRevisionById($submissionFile->getFileId(), $submissionFile->getRevision(), $submissionFile->getFileStage(), $submission->getId());
106 
107  if ($success) {
108  if ($submissionFile->getFileStage() == SUBMISSION_FILE_REVIEW_REVISION) {
109  $notificationMgr->updateNotification(
110  $request,
111  array(NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS, NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS),
112  array($submission->getUserId()),
113  ASSOC_TYPE_SUBMISSION,
114  $submission->getId()
115  );
116 
117  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
118  $lastReviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);
119  $notificationMgr->updateNotification(
120  $request,
121  array(NOTIFICATION_TYPE_ALL_REVISIONS_IN),
122  null,
123  ASSOC_TYPE_REVIEW_ROUND,
124  $lastReviewRound->getId()
125  );
126  }
127 
128  $this->indexSubmissionFiles($submission, $submissionFile);
129  $fileManager = $this->getFileManager($submission->getContextId(), $submission->getId());
130  $fileManager->deleteFile($submissionFile->getFileId(), $submissionFile->getRevision());
131 
132  $this->setupTemplate($request);
133  $user = $request->getUser();
134  if (!$request->getUserVar('suppressNotification')) NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedFile')));
135 
136  $this->logDeletionEvent($request, $submission, $submissionFile, $user);
137 
138  return DAO::getDataChangedEvent();
139  } else {
140  $json = new JSONMessage(false);
141  return $json->getString();
142  }
143  }
144 
151  function indexSubmissionFiles($submission, $submissionFile) {
152  assert(false);
153  }
154 
161  function getFileManager($contextId, $submissionId) {
162  import('lib.pkp.classes.file.SubmissionFileManager');
163  return new SubmissionFileManager($contextId, $submissionId);
164  }
165 
174  function logDeletionEvent($request, $submission, $submissionFile, $user) {
175  assert(false);
176  }
177 }
178 
179 ?>
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.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
Base request handler application class.
Definition: Handler.inc.php:19
getFileManager($contextId, $submissionId)
Class defining an AJAX API for file manipulation.
& getAuthorizedContextObject($assocType)
logDeletionEvent($request, $submission, $submissionFile, $user)