| Total Complexity | 112 |
| Total Lines | 991 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like DocumentController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DocumentController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | class DocumentController extends AbstractController |
||
| 39 | { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * documentRepository |
||
| 43 | * |
||
| 44 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
| 45 | * @inject |
||
| 46 | */ |
||
| 47 | protected $documentRepository = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * documentTypeRepository |
||
| 51 | * |
||
| 52 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
| 53 | * @inject |
||
| 54 | */ |
||
| 55 | protected $documentTypeRepository = null; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * inputOptionListRepository |
||
| 59 | * |
||
| 60 | * @var \EWW\Dpf\Domain\Repository\InputOptionListRepository |
||
| 61 | * @inject |
||
| 62 | */ |
||
| 63 | protected $inputOptionListRepository = null; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * persistence manager |
||
| 67 | * |
||
| 68 | * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
||
| 69 | * @inject |
||
| 70 | */ |
||
| 71 | protected $persistenceManager; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * editingLockService |
||
| 75 | * |
||
| 76 | * @var \EWW\Dpf\Services\Document\EditingLockService |
||
| 77 | * @inject |
||
| 78 | */ |
||
| 79 | protected $editingLockService = null; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * documentValidator |
||
| 83 | * |
||
| 84 | * @var \EWW\Dpf\Helper\DocumentValidator |
||
| 85 | * @inject |
||
| 86 | */ |
||
| 87 | protected $documentValidator; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * depositLicenseLogRepository |
||
| 91 | * |
||
| 92 | * @var \EWW\Dpf\Domain\Repository\DepositLicenseLogRepository |
||
| 93 | * @inject |
||
| 94 | */ |
||
| 95 | protected $depositLicenseLogRepository = null; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * workflow |
||
| 99 | * |
||
| 100 | * @var \EWW\Dpf\Domain\Workflow\DocumentWorkflow |
||
| 101 | */ |
||
| 102 | protected $workflow; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * documentTransferManager |
||
| 106 | * |
||
| 107 | * @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager |
||
| 108 | */ |
||
| 109 | protected $documentTransferManager; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * fedoraRepository |
||
| 113 | * |
||
| 114 | * @var \EWW\Dpf\Services\Transfer\FedoraRepository $fedoraRepository |
||
| 115 | */ |
||
| 116 | protected $fedoraRepository; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * fileRepository |
||
| 120 | * |
||
| 121 | * @var \EWW\Dpf\Domain\Repository\FileRepository |
||
| 122 | * @inject |
||
| 123 | */ |
||
| 124 | protected $fileRepository = null; |
||
| 125 | |||
| 126 | |||
| 127 | /** |
||
| 128 | * frontendUserRepository |
||
| 129 | * |
||
| 130 | * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository |
||
| 131 | * @inject |
||
| 132 | */ |
||
| 133 | protected $frontendUserRepository = null; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * documentManager |
||
| 137 | * |
||
| 138 | * @var \EWW\Dpf\Services\Document\DocumentManager |
||
| 139 | * @inject |
||
| 140 | */ |
||
| 141 | protected $documentManager = null; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * bookmarkRepository |
||
| 145 | * |
||
| 146 | * @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
||
| 147 | * @inject |
||
| 148 | */ |
||
| 149 | protected $bookmarkRepository = null; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * DocumentController constructor. |
||
| 153 | */ |
||
| 154 | public function __construct() |
||
| 155 | { |
||
| 156 | parent::__construct(); |
||
| 157 | |||
| 158 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); |
||
| 159 | $this->documentTransferManager = $objectManager->get(DocumentTransferManager::class); |
||
| 160 | $this->fedoraRepository = $objectManager->get(FedoraRepository::class); |
||
| 161 | $this->documentTransferManager->setRemoteRepository($this->fedoraRepository); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * action logout of the backoffice |
||
| 166 | * |
||
| 167 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 168 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 169 | */ |
||
| 170 | public function logoutAction() |
||
| 171 | { |
||
| 172 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
| 173 | $uri = $cObj->typolink_URL([ |
||
| 174 | 'parameter' => $this->settings['loginPage'], |
||
| 175 | //'linkAccessRestrictedPages' => 1, |
||
| 176 | 'forceAbsoluteUrl' => 1, |
||
| 177 | 'additionalParams' => GeneralUtility::implodeArrayForUrl(NULL, ['logintype'=>'logout']) |
||
| 178 | ]); |
||
| 179 | |||
| 180 | $this->redirectToUri($uri); |
||
| 181 | } |
||
| 182 | |||
| 183 | public function listSuggestionsAction() { |
||
| 184 | $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController()); |
||
| 185 | |||
| 186 | $documents = NULL; |
||
| 187 | $isWorkspace = $this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN; |
||
| 188 | |||
| 189 | if ( |
||
| 190 | $this->security->getUser()->getUserRole() == Security::ROLE_LIBRARIAN |
||
| 191 | ) { |
||
| 192 | $documents = $this->documentRepository->findAllDocumentSuggestions( |
||
| 193 | $this->security->getUser()->getUserRole(), |
||
| 194 | $this->security->getUser()->getUid() |
||
| 195 | ); |
||
| 196 | } |
||
| 197 | |||
| 198 | if ($this->request->hasArgument('message')) { |
||
| 199 | $this->view->assign('message', $this->request->getArgument('message')); |
||
| 200 | } |
||
| 201 | |||
| 202 | if ($this->request->hasArgument('errorFiles')) { |
||
| 203 | $this->view->assign('errorFiles', $this->request->getArgument('errorFiles')); |
||
| 204 | } |
||
| 205 | |||
| 206 | $this->view->assign('currentUser', $this->security->getUser()); |
||
| 207 | $this->view->assign('isWorkspace', $isWorkspace); |
||
| 208 | $this->view->assign('documents', $documents); |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param Document $document |
||
| 213 | * @param bool $acceptAll |
||
| 214 | */ |
||
| 215 | public function acceptSuggestionAction(\EWW\Dpf\Domain\Model\Document $document, bool $acceptAll = true) { |
||
| 216 | |||
| 217 | /** @var DocumentMapper $documentMapper */ |
||
| 218 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 219 | |||
| 220 | // Existing working copy? |
||
| 221 | /** @var \EWW\Dpf\Domain\Model\Document $originDocument */ |
||
| 222 | $linkedUid = $document->getLinkedUid(); |
||
| 223 | $originDocument = $this->documentRepository->findWorkingCopy($linkedUid); |
||
| 224 | |||
| 225 | if ($originDocument) { |
||
|
|
|||
| 226 | $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument); |
||
| 227 | } else { |
||
| 228 | // get remote document |
||
| 229 | $originDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid()); |
||
| 230 | $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument); |
||
| 231 | } |
||
| 232 | |||
| 233 | if ($acceptAll) { |
||
| 234 | // all changes are confirmed |
||
| 235 | // copy suggest to origin document |
||
| 236 | $originDocument->copy($document, true); |
||
| 237 | |||
| 238 | if ($document->getRemoteState() != DocumentWorkflow::REMOTE_STATE_NONE) { |
||
| 239 | if ($document->getLocalState() != DocumentWorkflow::LOCAL_STATE_IN_PROGRESS) { |
||
| 240 | $originDocument->setState( |
||
| 241 | DocumentWorkflow::constructState(DocumentWorkflow::LOCAL_STATE_IN_PROGRESS, |
||
| 242 | $document->getRemoteState()) |
||
| 243 | ); |
||
| 244 | $this->addFlashMessage( |
||
| 245 | LocalizationUtility::translate("message.suggestion_accepted.new_workingcopy_info", "dpf"), |
||
| 246 | '', |
||
| 247 | AbstractMessage::INFO |
||
| 248 | ); |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | if ($originDocument->getTransferStatus() == 'RESTORE') { |
||
| 253 | if ($originDocument->getObjectIdentifier()) { |
||
| 254 | $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE); |
||
| 255 | } else { |
||
| 256 | $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_NONE); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | // copy files from suggest document |
||
| 261 | foreach ($document->getFile() as $key => $file) { |
||
| 262 | $newFile = $this->objectManager->get(File::class); |
||
| 263 | $newFile->copy($file); |
||
| 264 | $newFile->setDocument($originDocument); |
||
| 265 | $this->fileRepository->add($newFile); |
||
| 266 | $originDocument->addFile($newFile); |
||
| 267 | |||
| 268 | } |
||
| 269 | |||
| 270 | $this->documentRepository->update($originDocument); |
||
| 271 | $this->documentRepository->remove($document); |
||
| 272 | |||
| 273 | // Notify assigned users |
||
| 274 | /** @var Notifier $notifier */ |
||
| 275 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 276 | |||
| 277 | $recipients = $this->documentManager->getUpdateNotificationRecipients($originDocument); |
||
| 278 | $notifier->sendMyPublicationUpdateNotification($originDocument, $recipients); |
||
| 279 | |||
| 280 | $recipients = $this->documentManager->getNewPublicationNotificationRecipients($originDocument); |
||
| 281 | $notifier->sendMyPublicationNewNotification($originDocument, $recipients); |
||
| 282 | |||
| 283 | $notifier->sendChangedDocumentNotification($originDocument); |
||
| 284 | |||
| 285 | $notifier->sendSuggestionAcceptNotification($originDocument); |
||
| 286 | |||
| 287 | // index the document |
||
| 288 | $this->signalSlotDispatcher->dispatch( |
||
| 289 | AbstractController::class, 'indexDocument', [$originDocument] |
||
| 290 | ); |
||
| 291 | |||
| 292 | // redirect to document |
||
| 293 | $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]); |
||
| 294 | } |
||
| 295 | |||
| 296 | $this->redirectToDocumentList(); |
||
| 297 | } |
||
| 298 | |||
| 299 | |||
| 300 | public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 301 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document); |
||
| 302 | |||
| 303 | /** @var DocumentMapper $documentMapper */ |
||
| 304 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 305 | |||
| 306 | $linkedUid = $document->getLinkedUid(); |
||
| 307 | $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid); |
||
| 308 | |||
| 309 | if ($linkedDocument) { |
||
| 310 | // Existing working copy |
||
| 311 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
| 312 | } else { |
||
| 313 | // No existing working copy, get remote document from fedora |
||
| 314 | $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid()); |
||
| 315 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
| 316 | } |
||
| 317 | |||
| 318 | $newDocumentForm = $documentMapper->getDocumentForm($document); |
||
| 319 | $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm); |
||
| 320 | |||
| 321 | //$usernameString = $this->security->getUser()->getUsername(); |
||
| 322 | $user = $this->frontendUserRepository->findOneByUid($document->getCreator()); |
||
| 323 | |||
| 324 | if ($user) { |
||
| 325 | $usernameString = $user->getUsername(); |
||
| 326 | } |
||
| 327 | |||
| 328 | $this->view->assign('documentCreator', $usernameString); |
||
| 329 | $this->view->assign('diff', $diff); |
||
| 330 | $this->view->assign('document', $document); |
||
| 331 | |||
| 332 | } |
||
| 333 | |||
| 334 | public function documentFormDiff($docForm1, $docForm2) { |
||
| 335 | $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []]; |
||
| 336 | |||
| 337 | // pages |
||
| 338 | foreach ($docForm1->getItems() as $keyPage => $valuePage) { |
||
| 339 | foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) { |
||
| 340 | |||
| 341 | // groups |
||
| 342 | foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) { |
||
| 343 | |||
| 344 | $checkFieldsForAdding = false; |
||
| 345 | $valueGroupCounter = count($valueGroup); |
||
| 346 | |||
| 347 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
| 348 | $checkFieldsForAdding = true; |
||
| 349 | } |
||
| 350 | |||
| 351 | foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) { |
||
| 352 | |||
| 353 | // fields |
||
| 354 | foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) { |
||
| 355 | foreach ($valueField as $keyRepeatField => $valueRepeatField) { |
||
| 356 | |||
| 357 | $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
| 358 | $valueFieldCounter = count($valueField); |
||
| 359 | |||
| 360 | // check if group or field is not existing |
||
| 361 | $notExisting = false; |
||
| 362 | try { |
||
| 363 | $flag = 'page'; |
||
| 364 | $value2 = $docForm2->getItems()[$keyPage]; |
||
| 365 | $flag = 'group'; |
||
| 366 | $value2 = $value2[$keyRepeatPage]; |
||
| 367 | $value2 = $value2->getItems()[$keyGroup]; |
||
| 368 | $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField]; |
||
| 369 | $flag = 'field'; |
||
| 370 | } catch (\Throwable $t) { |
||
| 371 | $notExisting = true; |
||
| 372 | } |
||
| 373 | |||
| 374 | $item = NULL; |
||
| 375 | if ($flag == 'group') { |
||
| 376 | $itemExisting = $valueRepeatGroup; |
||
| 377 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]; |
||
| 378 | } else if ($flag == 'field') { |
||
| 379 | $itemExisting = $valueRepeatField; |
||
| 380 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField]; |
||
| 381 | } |
||
| 382 | |||
| 383 | if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) { |
||
| 384 | // deleted |
||
| 385 | $returnArray['deleted'][] = $itemExisting; |
||
| 386 | |||
| 387 | } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue()) |
||
| 388 | && !empty($value2[$keyRepeatField]->getValue())) { |
||
| 389 | |||
| 390 | // changed |
||
| 391 | $returnArray['changed']['old'][] = $itemExisting; |
||
| 392 | $returnArray['changed']['new'][] = $itemNew; |
||
| 393 | $returnArray['changed']['groupDisplayName'] = $valueRepeatGroup->getDisplayName(); |
||
| 394 | } |
||
| 395 | |||
| 396 | if ($flag == 'group') { |
||
| 397 | break 2; |
||
| 398 | } |
||
| 399 | } |
||
| 400 | |||
| 401 | // check if new document form has more field items as the existing form |
||
| 402 | if ($valueFieldCounter < $fieldCounter && !$checkFieldsForAdding) { |
||
| 403 | // field added |
||
| 404 | for ($i = count($valueField); $i < $fieldCounter;$i++) { |
||
| 405 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i]; |
||
| 406 | |||
| 407 | } |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | // check if new document form has more group items as the existing form |
||
| 413 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
| 414 | // group added |
||
| 415 | $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
| 416 | for ($i = $valueGroupCounter; $i < $counter;$i++) { |
||
| 417 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i]; |
||
| 418 | } |
||
| 419 | } |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | } |
||
| 424 | |||
| 425 | return $returnArray; |
||
| 426 | |||
| 427 | } |
||
| 428 | |||
| 429 | public function removeControlCharacterFromString($string) { |
||
| 430 | return preg_replace('/\p{C}+/u', "", $string); |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * action discard |
||
| 435 | * |
||
| 436 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 437 | * @param integer $tstamp |
||
| 438 | * @param string $reason |
||
| 439 | * @return void |
||
| 440 | */ |
||
| 441 | public function discardAction(Document $document, $tstamp, $reason = NULL) |
||
| 442 | { |
||
| 443 | if (!$this->authorizationChecker->isGranted(DocumentVoter::DISCARD, $document)) { |
||
| 444 | if ( |
||
| 445 | $this->editingLockService->isLocked( |
||
| 446 | $document->getDocumentIdentifier(), |
||
| 447 | $this->security->getUser()->getUid() |
||
| 448 | ) |
||
| 449 | ) { |
||
| 450 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureBlocked'; |
||
| 451 | } else { |
||
| 452 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.accessDenied'; |
||
| 453 | } |
||
| 454 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 455 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 456 | return FALSE; |
||
| 457 | } |
||
| 458 | |||
| 459 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_DISCARD, $reason); |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * action postpone |
||
| 464 | * |
||
| 465 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 466 | * @param integer $tstamp |
||
| 467 | * @param string $reason |
||
| 468 | * @return void |
||
| 469 | */ |
||
| 470 | public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL) |
||
| 471 | { |
||
| 472 | if (!$this->authorizationChecker->isGranted(DocumentVoter::POSTPONE, $document)) { |
||
| 473 | if ( |
||
| 474 | $this->editingLockService->isLocked( |
||
| 475 | $document->getDocumentIdentifier(), |
||
| 476 | $this->security->getUser()->getUid() |
||
| 477 | ) |
||
| 478 | ) { |
||
| 479 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureBlocked'; |
||
| 480 | } else { |
||
| 481 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.accessDenied'; |
||
| 482 | } |
||
| 483 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 484 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 485 | return FALSE; |
||
| 486 | } |
||
| 487 | |||
| 488 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_POSTPONE, $reason); |
||
| 489 | |||
| 490 | } |
||
| 491 | |||
| 492 | |||
| 493 | /** |
||
| 494 | * action change document type |
||
| 495 | * |
||
| 496 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 497 | * @param int $documentTypeUid |
||
| 498 | * @return void |
||
| 499 | */ |
||
| 500 | public function changeDocumentTypeAction(\EWW\Dpf\Domain\Model\Document $document, $documentTypeUid = 0) |
||
| 501 | { |
||
| 502 | if (!$this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) { |
||
| 503 | if ( |
||
| 504 | $this->editingLockService->isLocked( |
||
| 505 | $document->getDocumentIdentifier(), |
||
| 506 | $this->security->getUser()->getUid() |
||
| 507 | ) |
||
| 508 | ) { |
||
| 509 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureBlocked'; |
||
| 510 | } else { |
||
| 511 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied'; |
||
| 512 | } |
||
| 513 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 514 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 515 | return FALSE; |
||
| 516 | } |
||
| 517 | |||
| 518 | |||
| 519 | $documentType = $this->documentTypeRepository->findByUid($documentTypeUid); |
||
| 520 | |||
| 521 | if ($documentType instanceof DocumentType) { |
||
| 522 | $document->setDocumentType($documentType); |
||
| 523 | |||
| 524 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 525 | $internalFormat->setDocumentType($documentType->getName()); |
||
| 526 | $document->setXmlData($internalFormat->getXml()); |
||
| 527 | |||
| 528 | $this->updateDocument($document, '', null); |
||
| 529 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 530 | } else { |
||
| 531 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failure'; |
||
| 532 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 533 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 534 | return FALSE; |
||
| 535 | } |
||
| 536 | } |
||
| 537 | |||
| 538 | |||
| 539 | /** |
||
| 540 | * action deleteLocallyAction |
||
| 541 | * |
||
| 542 | * @param Document $document |
||
| 543 | * @param integer $tstamp |
||
| 544 | * @return void |
||
| 545 | */ |
||
| 546 | public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
| 547 | { |
||
| 548 | if (empty($document->getObjectIdentifier()) || $document->isSuggestion()) { |
||
| 549 | $voterAttribute = DocumentVoter::DELETE_LOCALLY; |
||
| 550 | } else { |
||
| 551 | $voterAttribute = DocumentVoter::DELETE_WORKING_COPY; |
||
| 552 | } |
||
| 553 | |||
| 554 | if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) { |
||
| 555 | if ( |
||
| 556 | $this->editingLockService->isLocked( |
||
| 557 | $document->getDocumentIdentifier(), |
||
| 558 | $this->security->getUser()->getUid() |
||
| 559 | ) |
||
| 560 | ) { |
||
| 561 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked'; |
||
| 562 | } else { |
||
| 563 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied'; |
||
| 564 | } |
||
| 565 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 566 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 567 | return FALSE; |
||
| 568 | } |
||
| 569 | |||
| 570 | if ($tstamp === $document->getTstamp()) { |
||
| 571 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success'; |
||
| 572 | $this->flashMessage($document, $key, AbstractMessage::OK); |
||
| 573 | $this->documentRepository->remove($document); |
||
| 574 | |||
| 575 | if ($document->isWorkingCopy() || $document->isTemporaryCopy()) { |
||
| 576 | |||
| 577 | if ($document->isWorkingCopy()) { |
||
| 578 | if ($this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid())) { |
||
| 579 | $this->addFlashMessage( |
||
| 580 | LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '', |
||
| 581 | AbstractMessage::INFO |
||
| 582 | ); |
||
| 583 | } |
||
| 584 | } |
||
| 585 | |||
| 586 | $this->persistenceManager->persistAll(); |
||
| 587 | $document = $this->documentManager->read($document->getDocumentIdentifier()); |
||
| 588 | |||
| 589 | // index the document |
||
| 590 | $this->signalSlotDispatcher->dispatch( |
||
| 591 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 592 | 'indexDocument', [$document] |
||
| 593 | ); |
||
| 594 | |||
| 595 | $this->documentRepository->remove($document); |
||
| 596 | |||
| 597 | } elseif (!$document->isSuggestion()) { |
||
| 598 | $this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid()); |
||
| 599 | // delete document from index |
||
| 600 | $this->signalSlotDispatcher->dispatch( |
||
| 601 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 602 | 'deleteDocumentFromIndex', [$document->getDocumentIdentifier()] |
||
| 603 | ); |
||
| 604 | } |
||
| 605 | |||
| 606 | $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier()); |
||
| 607 | foreach ($suggestions as $suggestion) { |
||
| 608 | $this->documentRepository->remove($suggestion); |
||
| 609 | } |
||
| 610 | |||
| 611 | /** @var Notifier $notifier */ |
||
| 612 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 613 | $notifier->sendSuggestionDeclineNotification($document); |
||
| 614 | |||
| 615 | $this->redirectToDocumentList(); |
||
| 616 | } else { |
||
| 617 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion'; |
||
| 618 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 619 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 620 | } |
||
| 621 | } |
||
| 622 | |||
| 623 | |||
| 624 | /** |
||
| 625 | * @param Document $document |
||
| 626 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 627 | */ |
||
| 628 | public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document) |
||
| 674 | ); |
||
| 675 | |||
| 676 | } |
||
| 677 | |||
| 678 | /** |
||
| 679 | * releasePublishAction |
||
| 680 | * |
||
| 681 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 682 | * @param integer $tstamp |
||
| 683 | * @return void |
||
| 684 | */ |
||
| 685 | public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
| 686 | { |
||
| 687 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) { |
||
| 688 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied'; |
||
| 689 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 690 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 691 | return FALSE; |
||
| 692 | } |
||
| 693 | |||
| 694 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_PUBLISH, null); |
||
| 695 | |||
| 696 | } |
||
| 697 | |||
| 698 | |||
| 699 | /** |
||
| 700 | * releaseActivateAction |
||
| 701 | * |
||
| 702 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 703 | * @param integer $tstamp |
||
| 704 | * @return void |
||
| 705 | */ |
||
| 706 | public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
| 707 | { |
||
| 708 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) { |
||
| 709 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied'; |
||
| 710 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 711 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 712 | return FALSE; |
||
| 713 | } |
||
| 714 | |||
| 715 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE, null); |
||
| 716 | |||
| 717 | } |
||
| 718 | |||
| 719 | /** |
||
| 720 | * action register |
||
| 721 | * |
||
| 722 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 723 | * @return void |
||
| 724 | */ |
||
| 725 | public function registerAction(\EWW\Dpf\Domain\Model\Document $document) |
||
| 726 | { |
||
| 727 | if (!$this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) { |
||
| 728 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.accessDenied'; |
||
| 729 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 730 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 731 | } |
||
| 732 | |||
| 733 | if (!$this->documentValidator->validate($document, false)) { |
||
| 734 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.missingValues'; |
||
| 735 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 736 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 737 | } |
||
| 738 | |||
| 739 | $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER); |
||
| 740 | $this->documentRepository->update($document); |
||
| 741 | |||
| 742 | |||
| 743 | if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) { |
||
| 744 | $this->bookmarkRepository->addBookmark($document, $this->security->getUser()->getUid()); |
||
| 745 | } |
||
| 746 | |||
| 747 | // admin register notification |
||
| 748 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 749 | $notifier->sendRegisterNotification($document); |
||
| 750 | |||
| 751 | // index the document |
||
| 752 | $this->signalSlotDispatcher->dispatch(\EWW\Dpf\Controller\AbstractController::class, 'indexDocument', [$document]); |
||
| 753 | |||
| 754 | // document updated notification |
||
| 755 | $recipients = $this->documentManager->getUpdateNotificationRecipients($document); |
||
| 756 | $notifier->sendMyPublicationUpdateNotification($document, $recipients); |
||
| 757 | |||
| 758 | $recipients = $this->documentManager->getNewPublicationNotificationRecipients($document); |
||
| 759 | $notifier->sendMyPublicationNewNotification($document, $recipients); |
||
| 760 | |||
| 761 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.success'; |
||
| 762 | $this->flashMessage($document, $key, AbstractMessage::OK); |
||
| 763 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 764 | } |
||
| 765 | |||
| 766 | /** |
||
| 767 | * action showDetails |
||
| 768 | * |
||
| 769 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 770 | * @return void |
||
| 771 | */ |
||
| 772 | public function showDetailsAction(Document $document) |
||
| 773 | { |
||
| 774 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) { |
||
| 775 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied'; |
||
| 776 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 777 | $this->redirectToDocumentList(); |
||
| 778 | } |
||
| 779 | |||
| 780 | $this->editingLockService->lock( |
||
| 781 | ($document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid()), |
||
| 782 | $this->security->getUser()->getUid() |
||
| 783 | ); |
||
| 784 | |||
| 785 | $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']); |
||
| 786 | if ($postponeOptions) { |
||
| 787 | $this->view->assign('postponeOptions', $postponeOptions->getInputOptions()); |
||
| 788 | } |
||
| 789 | |||
| 790 | $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']); |
||
| 791 | if ($discardOptions) { |
||
| 792 | $this->view->assign('discardOptions', $discardOptions->getInputOptions()); |
||
| 793 | } |
||
| 794 | |||
| 795 | $mapper = $this->objectManager->get(DocumentMapper::class); |
||
| 796 | $documentForm = $mapper->getDocumentForm($document, false); |
||
| 797 | |||
| 798 | $documentTypes = [0 => '']; |
||
| 799 | foreach ($this->documentTypeRepository->getDocumentTypesAlphabetically() as $documentType) { |
||
| 800 | $documentTypes[$documentType->getUid()] = $documentType->getDisplayName(); |
||
| 801 | } |
||
| 802 | |||
| 803 | $this->view->assign('documentTypes', $documentTypes); |
||
| 804 | |||
| 805 | $this->view->assign('documentForm', $documentForm); |
||
| 806 | |||
| 807 | $this->view->assign('document', $document); |
||
| 808 | } |
||
| 809 | |||
| 810 | |||
| 811 | public function cancelListTaskAction() |
||
| 812 | { |
||
| 813 | $this->redirectToDocumentList(); |
||
| 814 | } |
||
| 815 | |||
| 816 | /** |
||
| 817 | * action suggest restore |
||
| 818 | * |
||
| 819 | * @param Document $document |
||
| 820 | * @return void |
||
| 821 | */ |
||
| 822 | public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 823 | |||
| 824 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) { |
||
| 825 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied'; |
||
| 826 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 827 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 828 | return FALSE; |
||
| 829 | } |
||
| 830 | |||
| 831 | $this->view->assign('document', $document); |
||
| 832 | } |
||
| 833 | |||
| 834 | /** |
||
| 835 | * @param Document $document |
||
| 836 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 837 | */ |
||
| 838 | public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 839 | |||
| 840 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document); |
||
| 841 | |||
| 842 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 843 | |||
| 844 | /* @var $newDocument \EWW\Dpf\Domain\Model\Document */ |
||
| 845 | $documentForm = $documentMapper->getDocumentForm($document); |
||
| 846 | |||
| 847 | $this->view->assign('suggestMod', true); |
||
| 848 | $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]); |
||
| 849 | } |
||
| 850 | |||
| 851 | |||
| 852 | /** |
||
| 853 | * initializeAction |
||
| 854 | */ |
||
| 855 | public function initializeAction() |
||
| 877 | } |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Redirect to the current document list. |
||
| 882 | * |
||
| 883 | * @param null $message |
||
| 884 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 885 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 886 | */ |
||
| 887 | protected function redirectToDocumentList($message = null) |
||
| 888 | { |
||
| 889 | list($action, $controller, $redirectUri) = $this->session->getStoredAction(); |
||
| 890 | |||
| 891 | if ($redirectUri) { |
||
| 892 | $this->redirectToUri($redirectUri); |
||
| 893 | } else { |
||
| 894 | $this->redirect($action, $controller); |
||
| 895 | } |
||
| 896 | } |
||
| 897 | |||
| 898 | /** |
||
| 899 | * Gets the storage PID of the current client |
||
| 900 | * |
||
| 901 | * @return mixed |
||
| 902 | */ |
||
| 903 | protected function getStoragePID() |
||
| 904 | { |
||
| 905 | return $this->settings['persistence']['classes']['EWW\Dpf\Domain\Model\Document']['newRecordStoragePid']; |
||
| 906 | } |
||
| 907 | |||
| 908 | /** |
||
| 909 | * |
||
| 910 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 911 | * @param string $key |
||
| 912 | * @param string $severity |
||
| 913 | * @param string $defaultMessage |
||
| 914 | */ |
||
| 915 | protected function flashMessage(\EWW\Dpf\Domain\Model\Document $document, $key, $severity, $defaultMessage = "") |
||
| 931 | ); |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Updates the document in combination with a state transition. |
||
| 936 | * |
||
| 937 | * @param Document $document |
||
| 938 | * @param $workflowTransition |
||
| 939 | * @param string $reason |
||
| 940 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 941 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 942 | */ |
||
| 943 | protected function updateDocument(\EWW\Dpf\Domain\Model\Document $document, $workflowTransition, $reason) |
||
| 1029 | } |
||
| 1030 | |||
| 1031 | } |
||
| 1032 | } |
||
| 1033 |