| Total Complexity | 113 |
| Total Lines | 1017 |
| 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() |
||
| 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() |
||
| 181 | } |
||
| 182 | |||
| 183 | public function listSuggestionsAction() { |
||
| 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 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
| 270 | $originDocument->setAuthors($mods->getPersons()); |
||
| 271 | $this->documentRepository->update($originDocument); |
||
| 272 | $this->documentRepository->remove($document); |
||
| 273 | |||
| 274 | // Notify assigned users |
||
| 275 | /** @var Notifier $notifier */ |
||
| 276 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 277 | |||
| 278 | $recipients = $this->documentManager->getUpdateNotificationRecipients($originDocument); |
||
| 279 | $notifier->sendMyPublicationUpdateNotification($originDocument, $recipients); |
||
| 280 | |||
| 281 | $recipients = $this->documentManager->getNewPublicationNotificationRecipients($originDocument); |
||
| 282 | $notifier->sendMyPublicationNewNotification($originDocument, $recipients); |
||
| 283 | |||
| 284 | $notifier->sendChangedDocumentNotification($originDocument); |
||
| 285 | |||
| 286 | $notifier->sendSuggestionAcceptNotification($originDocument); |
||
| 287 | |||
| 288 | // index the document |
||
| 289 | $this->signalSlotDispatcher->dispatch( |
||
| 290 | AbstractController::class, 'indexDocument', [$originDocument] |
||
| 291 | ); |
||
| 292 | |||
| 293 | // redirect to document |
||
| 294 | $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]); |
||
| 295 | } |
||
| 296 | |||
| 297 | $this->redirectToDocumentList(); |
||
| 298 | } |
||
| 299 | |||
| 300 | |||
| 301 | public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 302 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document); |
||
| 303 | |||
| 304 | /** @var DocumentMapper $documentMapper */ |
||
| 305 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 306 | |||
| 307 | $linkedUid = $document->getLinkedUid(); |
||
| 308 | $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid); |
||
| 309 | |||
| 310 | if ($linkedDocument) { |
||
| 311 | // Existing working copy |
||
| 312 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
| 313 | } else { |
||
| 314 | // No existing working copy, get remote document from fedora |
||
| 315 | $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid()); |
||
| 316 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
| 317 | } |
||
| 318 | |||
| 319 | $newDocumentForm = $documentMapper->getDocumentForm($document); |
||
| 320 | $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm); |
||
| 321 | |||
| 322 | //$usernameString = $this->security->getUser()->getUsername(); |
||
| 323 | $user = $this->frontendUserRepository->findOneByUid($document->getCreator()); |
||
| 324 | |||
| 325 | if ($user) { |
||
| 326 | $usernameString = $user->getUsername(); |
||
| 327 | } |
||
| 328 | |||
| 329 | $this->view->assign('documentCreator', $usernameString); |
||
| 330 | $this->view->assign('diff', $diff); |
||
| 331 | $this->view->assign('document', $document); |
||
| 332 | |||
| 333 | } |
||
| 334 | |||
| 335 | public function documentFormDiff($docForm1, $docForm2) { |
||
| 336 | $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []]; |
||
| 337 | |||
| 338 | // pages |
||
| 339 | foreach ($docForm1->getItems() as $keyPage => $valuePage) { |
||
| 340 | foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) { |
||
| 341 | |||
| 342 | // groups |
||
| 343 | foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) { |
||
| 344 | |||
| 345 | $checkFieldsForAdding = false; |
||
| 346 | $valueGroupCounter = count($valueGroup); |
||
| 347 | |||
| 348 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
| 349 | $checkFieldsForAdding = true; |
||
| 350 | } |
||
| 351 | |||
| 352 | foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) { |
||
| 353 | |||
| 354 | // fields |
||
| 355 | foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) { |
||
| 356 | foreach ($valueField as $keyRepeatField => $valueRepeatField) { |
||
| 357 | |||
| 358 | $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
| 359 | $valueFieldCounter = count($valueField); |
||
| 360 | |||
| 361 | // check if group or field is not existing |
||
| 362 | $notExisting = false; |
||
| 363 | try { |
||
| 364 | $flag = 'page'; |
||
| 365 | $value2 = $docForm2->getItems()[$keyPage]; |
||
| 366 | $flag = 'group'; |
||
| 367 | $value2 = $value2[$keyRepeatPage]; |
||
| 368 | $value2 = $value2->getItems()[$keyGroup]; |
||
| 369 | $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField]; |
||
| 370 | $flag = 'field'; |
||
| 371 | } catch (\Throwable $t) { |
||
| 372 | $notExisting = true; |
||
| 373 | } |
||
| 374 | |||
| 375 | $item = NULL; |
||
| 376 | if ($flag == 'group') { |
||
| 377 | $itemExisting = $valueRepeatGroup; |
||
| 378 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]; |
||
| 379 | } else if ($flag == 'field') { |
||
| 380 | $itemExisting = $valueRepeatField; |
||
| 381 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField]; |
||
| 382 | } |
||
| 383 | |||
| 384 | if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) { |
||
| 385 | // deleted |
||
| 386 | $returnArray['deleted'][] = $itemExisting; |
||
| 387 | |||
| 388 | } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue()) |
||
| 389 | && !empty($value2[$keyRepeatField]->getValue())) { |
||
| 390 | |||
| 391 | // changed |
||
| 392 | $returnArray['changed']['old'][] = $itemExisting; |
||
| 393 | $returnArray['changed']['new'][] = $itemNew; |
||
| 394 | $returnArray['changed']['groupDisplayName'] = $valueRepeatGroup->getDisplayName(); |
||
| 395 | } |
||
| 396 | |||
| 397 | if ($flag == 'group') { |
||
| 398 | break 2; |
||
| 399 | } |
||
| 400 | } |
||
| 401 | |||
| 402 | // check if new document form has more field items as the existing form |
||
| 403 | if ($valueFieldCounter < $fieldCounter && !$checkFieldsForAdding) { |
||
| 404 | // field added |
||
| 405 | for ($i = count($valueField); $i < $fieldCounter;$i++) { |
||
| 406 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i]; |
||
| 407 | |||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | } |
||
| 412 | |||
| 413 | // check if new document form has more group items as the existing form |
||
| 414 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
| 415 | // group added |
||
| 416 | $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
| 417 | for ($i = $valueGroupCounter; $i < $counter;$i++) { |
||
| 418 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i]; |
||
| 419 | } |
||
| 420 | } |
||
| 421 | } |
||
| 422 | } |
||
| 423 | |||
| 424 | } |
||
| 425 | |||
| 426 | return $returnArray; |
||
| 427 | |||
| 428 | } |
||
| 429 | |||
| 430 | public function removeControlCharacterFromString($string) { |
||
| 431 | return preg_replace('/\p{C}+/u', "", $string); |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * action discard |
||
| 436 | * |
||
| 437 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 438 | * @param integer $tstamp |
||
| 439 | * @param string $reason |
||
| 440 | * @return void |
||
| 441 | */ |
||
| 442 | public function discardAction(Document $document, $tstamp, $reason = NULL) |
||
| 443 | { |
||
| 444 | if (!$this->authorizationChecker->isGranted(DocumentVoter::DISCARD, $document)) { |
||
| 445 | if ( |
||
| 446 | $this->editingLockService->isLocked( |
||
| 447 | $document->getDocumentIdentifier(), |
||
| 448 | $this->security->getUser()->getUid() |
||
| 449 | ) |
||
| 450 | ) { |
||
| 451 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureBlocked'; |
||
| 452 | } else { |
||
| 453 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.accessDenied'; |
||
| 454 | } |
||
| 455 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 456 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 457 | return FALSE; |
||
| 458 | } |
||
| 459 | |||
| 460 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_DISCARD, $reason); |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * action postpone |
||
| 465 | * |
||
| 466 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 467 | * @param integer $tstamp |
||
| 468 | * @param string $reason |
||
| 469 | * @return void |
||
| 470 | */ |
||
| 471 | public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL) |
||
| 472 | { |
||
| 473 | if (!$this->authorizationChecker->isGranted(DocumentVoter::POSTPONE, $document)) { |
||
| 474 | if ( |
||
| 475 | $this->editingLockService->isLocked( |
||
| 476 | $document->getDocumentIdentifier(), |
||
| 477 | $this->security->getUser()->getUid() |
||
| 478 | ) |
||
| 479 | ) { |
||
| 480 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureBlocked'; |
||
| 481 | } else { |
||
| 482 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.accessDenied'; |
||
| 483 | } |
||
| 484 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 485 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 486 | return FALSE; |
||
| 487 | } |
||
| 488 | |||
| 489 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_POSTPONE, $reason); |
||
| 490 | |||
| 491 | } |
||
| 492 | |||
| 493 | |||
| 494 | /** |
||
| 495 | * action change document type |
||
| 496 | * |
||
| 497 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 498 | * @param int $documentTypeUid |
||
| 499 | * @return void |
||
| 500 | */ |
||
| 501 | public function changeDocumentTypeAction(\EWW\Dpf\Domain\Model\Document $document, $documentTypeUid = 0) |
||
| 502 | { |
||
| 503 | if (!$this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) { |
||
| 504 | if ( |
||
| 505 | $this->editingLockService->isLocked( |
||
| 506 | $document->getDocumentIdentifier(), |
||
| 507 | $this->security->getUser()->getUid() |
||
| 508 | ) |
||
| 509 | ) { |
||
| 510 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureBlocked'; |
||
| 511 | } else { |
||
| 512 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied'; |
||
| 513 | } |
||
| 514 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 515 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 516 | return FALSE; |
||
| 517 | } |
||
| 518 | |||
| 519 | |||
| 520 | $documentType = $this->documentTypeRepository->findByUid($documentTypeUid); |
||
| 521 | |||
| 522 | if ($documentType instanceof DocumentType) { |
||
| 523 | $document->setDocumentType($documentType); |
||
| 524 | |||
| 525 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 526 | $internalFormat->setDocumentType($documentType->getName()); |
||
| 527 | $document->setXmlData($internalFormat->getXml()); |
||
| 528 | |||
| 529 | $this->updateDocument($document, '', null); |
||
| 530 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 531 | } else { |
||
| 532 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failure'; |
||
| 533 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 534 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 535 | return FALSE; |
||
| 536 | } |
||
| 537 | } |
||
| 538 | |||
| 539 | /** |
||
| 540 | * action deleteLocallySuggestionAction |
||
| 541 | * |
||
| 542 | * @param Document $document |
||
| 543 | * @param integer $tstamp |
||
| 544 | * @param string $reason |
||
| 545 | * @return void |
||
| 546 | */ |
||
| 547 | public function deleteLocallySuggestionAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "") |
||
| 548 | { |
||
| 549 | $this->redirect( |
||
| 550 | 'deleteLocally', |
||
| 551 | 'Document', |
||
| 552 | null, |
||
| 553 | [ |
||
| 554 | 'document' => $document, |
||
| 555 | 'tstamp' => $tstamp, |
||
| 556 | 'reason' => $reason |
||
| 557 | ] |
||
| 558 | ); |
||
| 559 | } |
||
| 560 | |||
| 561 | |||
| 562 | /** |
||
| 563 | * action deleteLocallyAction |
||
| 564 | * |
||
| 565 | * @param Document $document |
||
| 566 | * @param integer $tstamp |
||
| 567 | * @param string $reason |
||
| 568 | * @return void |
||
| 569 | */ |
||
| 570 | public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "") |
||
| 571 | { |
||
| 572 | if (empty($document->getObjectIdentifier()) || $document->isSuggestion()) { |
||
| 573 | $voterAttribute = DocumentVoter::DELETE_LOCALLY; |
||
| 574 | } else { |
||
| 575 | $voterAttribute = DocumentVoter::DELETE_WORKING_COPY; |
||
| 576 | } |
||
| 577 | |||
| 578 | if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) { |
||
| 579 | if ( |
||
| 580 | $this->editingLockService->isLocked( |
||
| 581 | $document->getDocumentIdentifier(), |
||
| 582 | $this->security->getUser()->getUid() |
||
| 583 | ) |
||
| 584 | ) { |
||
| 585 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked'; |
||
| 586 | } else { |
||
| 587 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied'; |
||
| 588 | } |
||
| 589 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 590 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 591 | return FALSE; |
||
| 592 | } |
||
| 593 | |||
| 594 | if ($tstamp === $document->getTstamp()) { |
||
| 595 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success'; |
||
| 596 | $this->flashMessage($document, $key, AbstractMessage::OK); |
||
| 597 | $this->documentRepository->remove($document); |
||
| 598 | |||
| 599 | if ($document->isWorkingCopy() || $document->isTemporaryCopy()) { |
||
| 600 | |||
| 601 | if ($document->isWorkingCopy()) { |
||
| 602 | if ($this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid())) { |
||
| 603 | $this->addFlashMessage( |
||
| 604 | LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '', |
||
| 605 | AbstractMessage::INFO |
||
| 606 | ); |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | $this->persistenceManager->persistAll(); |
||
| 611 | $document = $this->documentManager->read($document->getDocumentIdentifier()); |
||
| 612 | |||
| 613 | // index the document |
||
| 614 | $this->signalSlotDispatcher->dispatch( |
||
| 615 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 616 | 'indexDocument', [$document] |
||
| 617 | ); |
||
| 618 | |||
| 619 | $this->documentRepository->remove($document); |
||
| 620 | |||
| 621 | } elseif (!$document->isSuggestion()) { |
||
| 622 | $this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid()); |
||
| 623 | // delete document from index |
||
| 624 | $this->signalSlotDispatcher->dispatch( |
||
| 625 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 626 | 'deleteDocumentFromIndex', [$document->getDocumentIdentifier()] |
||
| 627 | ); |
||
| 628 | } |
||
| 629 | |||
| 630 | $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier()); |
||
| 631 | foreach ($suggestions as $suggestion) { |
||
| 632 | $this->documentRepository->remove($suggestion); |
||
| 633 | } |
||
| 634 | |||
| 635 | /** @var Notifier $notifier */ |
||
| 636 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 637 | $notifier->sendSuggestionDeclineNotification($document, $reason); |
||
| 638 | |||
| 639 | $this->redirectToDocumentList(); |
||
| 640 | } else { |
||
| 641 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion'; |
||
| 642 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 643 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 644 | } |
||
| 645 | } |
||
| 646 | |||
| 647 | |||
| 648 | /** |
||
| 649 | * @param Document $document |
||
| 650 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 651 | */ |
||
| 652 | public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document) |
||
| 698 | ); |
||
| 699 | |||
| 700 | } |
||
| 701 | |||
| 702 | /** |
||
| 703 | * releasePublishAction |
||
| 704 | * |
||
| 705 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 706 | * @param integer $tstamp |
||
| 707 | * @return void |
||
| 708 | */ |
||
| 709 | public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
| 710 | { |
||
| 711 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) { |
||
| 712 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied'; |
||
| 713 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 714 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 715 | return FALSE; |
||
| 716 | } |
||
| 717 | |||
| 718 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_PUBLISH, null); |
||
| 719 | |||
| 720 | /** @var Notifier $notifier */ |
||
| 721 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 722 | $notifier->sendReleasePublishNotification($document); |
||
| 723 | } |
||
| 724 | |||
| 725 | /** |
||
| 726 | * releaseActivateAction |
||
| 727 | * |
||
| 728 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 729 | * @param integer $tstamp |
||
| 730 | * @return void |
||
| 731 | */ |
||
| 732 | public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
| 733 | { |
||
| 734 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) { |
||
| 735 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied'; |
||
| 736 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 737 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 738 | return FALSE; |
||
| 739 | } |
||
| 740 | |||
| 741 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE, null); |
||
| 742 | |||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * action register |
||
| 747 | * |
||
| 748 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 749 | * @return void |
||
| 750 | */ |
||
| 751 | public function registerAction(\EWW\Dpf\Domain\Model\Document $document) |
||
| 752 | { |
||
| 753 | if (!$this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) { |
||
| 754 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.accessDenied'; |
||
| 755 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 756 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 757 | } |
||
| 758 | |||
| 759 | if (!$this->documentValidator->validate($document, false)) { |
||
| 760 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.missingValues'; |
||
| 761 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 762 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 763 | } |
||
| 764 | |||
| 765 | $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER); |
||
| 766 | $this->documentRepository->update($document); |
||
| 767 | |||
| 768 | |||
| 769 | if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) { |
||
| 770 | $this->bookmarkRepository->addBookmark($document, $this->security->getUser()->getUid()); |
||
| 771 | } |
||
| 772 | |||
| 773 | // admin register notification |
||
| 774 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 775 | $notifier->sendRegisterNotification($document); |
||
| 776 | |||
| 777 | // index the document |
||
| 778 | $this->signalSlotDispatcher->dispatch(\EWW\Dpf\Controller\AbstractController::class, 'indexDocument', [$document]); |
||
| 779 | |||
| 780 | // document updated notification |
||
| 781 | $recipients = $this->documentManager->getUpdateNotificationRecipients($document); |
||
| 782 | $notifier->sendMyPublicationUpdateNotification($document, $recipients); |
||
| 783 | |||
| 784 | $recipients = $this->documentManager->getNewPublicationNotificationRecipients($document); |
||
| 785 | $notifier->sendMyPublicationNewNotification($document, $recipients); |
||
| 786 | |||
| 787 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.success'; |
||
| 788 | $this->flashMessage($document, $key, AbstractMessage::OK); |
||
| 789 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 790 | } |
||
| 791 | |||
| 792 | /** |
||
| 793 | * action showDetails |
||
| 794 | * |
||
| 795 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 796 | * @return void |
||
| 797 | */ |
||
| 798 | public function showDetailsAction(Document $document) |
||
| 799 | { |
||
| 800 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) { |
||
| 801 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied'; |
||
| 802 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 803 | $this->redirectToDocumentList(); |
||
| 804 | } |
||
| 805 | |||
| 806 | $this->editingLockService->lock( |
||
| 807 | ($document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid()), |
||
| 808 | $this->security->getUser()->getUid() |
||
| 809 | ); |
||
| 810 | |||
| 811 | $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']); |
||
| 812 | if ($postponeOptions) { |
||
| 813 | $this->view->assign('postponeOptions', $postponeOptions->getInputOptions()); |
||
| 814 | } |
||
| 815 | |||
| 816 | $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']); |
||
| 817 | if ($discardOptions) { |
||
| 818 | $this->view->assign('discardOptions', $discardOptions->getInputOptions()); |
||
| 819 | } |
||
| 820 | |||
| 821 | $mapper = $this->objectManager->get(DocumentMapper::class); |
||
| 822 | $documentForm = $mapper->getDocumentForm($document, false); |
||
| 823 | |||
| 824 | $documentTypes = [0 => '']; |
||
| 825 | foreach ($this->documentTypeRepository->getDocumentTypesAlphabetically() as $documentType) { |
||
| 826 | $documentTypes[$documentType->getUid()] = $documentType->getDisplayName(); |
||
| 827 | } |
||
| 828 | |||
| 829 | $this->view->assign('documentTypes', $documentTypes); |
||
| 830 | |||
| 831 | $this->view->assign('documentForm', $documentForm); |
||
| 832 | |||
| 833 | $this->view->assign('document', $document); |
||
| 834 | } |
||
| 835 | |||
| 836 | |||
| 837 | public function cancelListTaskAction() |
||
| 838 | { |
||
| 839 | $this->redirectToDocumentList(); |
||
| 840 | } |
||
| 841 | |||
| 842 | /** |
||
| 843 | * action suggest restore |
||
| 844 | * |
||
| 845 | * @param Document $document |
||
| 846 | * @return void |
||
| 847 | */ |
||
| 848 | public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 849 | |||
| 850 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) { |
||
| 851 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied'; |
||
| 852 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
| 853 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 854 | return FALSE; |
||
| 855 | } |
||
| 856 | |||
| 857 | $this->view->assign('document', $document); |
||
| 858 | } |
||
| 859 | |||
| 860 | /** |
||
| 861 | * @param Document $document |
||
| 862 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 863 | */ |
||
| 864 | public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 865 | |||
| 866 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document); |
||
| 867 | |||
| 868 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 869 | |||
| 870 | /* @var $newDocument \EWW\Dpf\Domain\Model\Document */ |
||
| 871 | $documentForm = $documentMapper->getDocumentForm($document); |
||
| 872 | |||
| 873 | $this->view->assign('suggestMod', true); |
||
| 874 | $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]); |
||
| 875 | } |
||
| 876 | |||
| 877 | |||
| 878 | /** |
||
| 879 | * initializeAction |
||
| 880 | */ |
||
| 881 | public function initializeAction() |
||
| 903 | } |
||
| 904 | } |
||
| 905 | |||
| 906 | /** |
||
| 907 | * Redirect to the current document list. |
||
| 908 | * |
||
| 909 | * @param null $message |
||
| 910 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 911 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 912 | */ |
||
| 913 | protected function redirectToDocumentList($message = null) |
||
| 914 | { |
||
| 915 | list($action, $controller, $redirectUri) = $this->session->getStoredAction(); |
||
| 916 | |||
| 917 | if ($redirectUri) { |
||
| 918 | $this->redirectToUri($redirectUri); |
||
| 919 | } else { |
||
| 920 | $this->redirect($action, $controller); |
||
| 921 | } |
||
| 922 | } |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Gets the storage PID of the current client |
||
| 926 | * |
||
| 927 | * @return mixed |
||
| 928 | */ |
||
| 929 | protected function getStoragePID() |
||
| 930 | { |
||
| 931 | return $this->settings['persistence']['classes']['EWW\Dpf\Domain\Model\Document']['newRecordStoragePid']; |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * |
||
| 936 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 937 | * @param string $key |
||
| 938 | * @param string $severity |
||
| 939 | * @param string $defaultMessage |
||
| 940 | */ |
||
| 941 | protected function flashMessage(\EWW\Dpf\Domain\Model\Document $document, $key, $severity, $defaultMessage = "") |
||
| 957 | ); |
||
| 958 | } |
||
| 959 | |||
| 960 | /** |
||
| 961 | * Updates the document in combination with a state transition. |
||
| 962 | * |
||
| 963 | * @param Document $document |
||
| 964 | * @param $workflowTransition |
||
| 965 | * @param string $reason |
||
| 966 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 967 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 968 | */ |
||
| 969 | protected function updateDocument(\EWW\Dpf\Domain\Model\Document $document, $workflowTransition, $reason) |
||
| 1055 | } |
||
| 1056 | |||
| 1057 | } |
||
| 1058 | } |
||
| 1059 |