| Total Complexity | 84 |
| Total Lines | 835 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like WorkspaceController 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 WorkspaceController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class WorkspaceController extends AbstractController |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * FrontendUserRepository |
||
| 34 | * |
||
| 35 | * @var TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository |
||
|
|
|||
| 36 | * @inject |
||
| 37 | */ |
||
| 38 | protected $frontendUserRepository; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * documentRepository |
||
| 42 | * |
||
| 43 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
| 44 | * @inject |
||
| 45 | */ |
||
| 46 | protected $documentRepository = null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * documentTypeRepository |
||
| 50 | * |
||
| 51 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
| 52 | * @inject |
||
| 53 | */ |
||
| 54 | protected $documentTypeRepository = null; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * bookmarkRepository |
||
| 58 | * |
||
| 59 | * @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
||
| 60 | * @inject |
||
| 61 | */ |
||
| 62 | protected $bookmarkRepository = null; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * elasticSearch |
||
| 66 | * |
||
| 67 | * @var \EWW\Dpf\Services\ElasticSearch\ElasticSearch |
||
| 68 | * @inject |
||
| 69 | */ |
||
| 70 | protected $elasticSearch = null; |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * queryBuilder |
||
| 75 | * |
||
| 76 | * @var \EWW\Dpf\Services\ElasticSearch\QueryBuilder |
||
| 77 | * @inject |
||
| 78 | */ |
||
| 79 | protected $queryBuilder = null; |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * documentManager |
||
| 84 | * |
||
| 85 | * @var \EWW\Dpf\Services\Document\DocumentManager |
||
| 86 | * @inject |
||
| 87 | */ |
||
| 88 | protected $documentManager = null; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * documentValidator |
||
| 92 | * |
||
| 93 | * @var \EWW\Dpf\Helper\DocumentValidator |
||
| 94 | * @inject |
||
| 95 | */ |
||
| 96 | protected $documentValidator; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * editingLockService |
||
| 100 | * |
||
| 101 | * @var \EWW\Dpf\Services\Document\EditingLockService |
||
| 102 | * @inject |
||
| 103 | */ |
||
| 104 | protected $editingLockService = null; |
||
| 105 | |||
| 106 | |||
| 107 | /** |
||
| 108 | * metadataGroupRepository |
||
| 109 | * |
||
| 110 | * @var \EWW\Dpf\Domain\Repository\MetadataGroupRepository |
||
| 111 | * @inject |
||
| 112 | */ |
||
| 113 | protected $metadataGroupRepository; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * fisDataService |
||
| 117 | * |
||
| 118 | * @var \EWW\Dpf\Services\FeUser\FisDataService |
||
| 119 | * @inject |
||
| 120 | */ |
||
| 121 | protected $fisDataService = null; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * list |
||
| 125 | * |
||
| 126 | * @param int $from |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | protected function list($from = 0) |
||
| 130 | { |
||
| 131 | $bookmarkIdentifiers = []; |
||
| 132 | foreach ($this->bookmarkRepository->findByFeUserUid($this->security->getUser()->getUid()) as $bookmark) { |
||
| 133 | $bookmarkIdentifiers[] = $bookmark->getDocumentIdentifier(); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** @var SearchSessionData $workspaceSessionData */ |
||
| 137 | $workspaceSessionData = $this->session->getWorkspaceData(); |
||
| 138 | $filters = $workspaceSessionData->getFilters(); |
||
| 139 | $excludeFilters = $workspaceSessionData->getExcludeFilters(); |
||
| 140 | $sortField = $workspaceSessionData->getSortField(); |
||
| 141 | $sortOrder = $workspaceSessionData->getSortOrder(); |
||
| 142 | |||
| 143 | if ($this->security->getUser()->getUserRole() == Security::ROLE_LIBRARIAN) { |
||
| 144 | $query = $this->getWorkspaceQuery($from, $bookmarkIdentifiers, |
||
| 145 | $filters, $excludeFilters, $sortField, $sortOrder); |
||
| 146 | } elseif ($this->security->getUser()->getUserRole() == Security::ROLE_RESEARCHER) { |
||
| 147 | $query = $this->getMyPublicationsQuery($from, $bookmarkIdentifiers, |
||
| 148 | $filters, $excludeFilters, $sortField, $sortOrder); |
||
| 149 | } |
||
| 150 | |||
| 151 | try { |
||
| 152 | $results = $this->elasticSearch->search($query, 'object'); |
||
| 153 | } catch (\Exception $e) { |
||
| 154 | $workspaceSessionData->clearSort(); |
||
| 155 | $workspaceSessionData->clearFilters(); |
||
| 156 | $this->session->setWorkspaceData($workspaceSessionData); |
||
| 157 | $this->addFlashMessage( |
||
| 158 | "Error while buildig the list!", '', AbstractMessage::ERROR |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($this->request->hasArgument('message')) { |
||
| 163 | $this->view->assign('message', $this->request->getArgument('message')); |
||
| 164 | } |
||
| 165 | |||
| 166 | if ($this->request->hasArgument('errorFiles')) { |
||
| 167 | $this->view->assign('errorFiles', $this->request->getArgument('errorFiles')); |
||
| 168 | } |
||
| 169 | |||
| 170 | if ($filters && $results['hits']['total']['value'] < 1) { |
||
| 171 | $workspaceSessionData->clearSort(); |
||
| 172 | $workspaceSessionData->clearFilters(); |
||
| 173 | $this->session->setWorkspaceData($workspaceSessionData); |
||
| 174 | list($redirectAction, $redirectController) = $this->session->getStoredAction(); |
||
| 175 | $this->redirect( |
||
| 176 | $redirectAction, $redirectController, null, |
||
| 177 | array('message' => [], 'checkedDocumentIdentifiers' => []) |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | |||
| 181 | $this->view->assign('documentCount', $results['hits']['total']['value']); |
||
| 182 | $this->view->assign('documents', $results['hits']['hits']); |
||
| 183 | $this->view->assign('pages', range(1, $results['hits']['total']['value'])); |
||
| 184 | $this->view->assign('itemsPerPage', $this->itemsPerPage()); |
||
| 185 | $this->view->assign('aggregations', $results['aggregations']); |
||
| 186 | $this->view->assign('filters', $filters); |
||
| 187 | $this->view->assign('isHideDiscarded', array_key_exists('aliasState', $excludeFilters)); |
||
| 188 | $this->view->assign('isBookmarksOnly', array_key_exists('bookmarks', $excludeFilters)); |
||
| 189 | $this->view->assign('bookmarkIdentifiers', $bookmarkIdentifiers); |
||
| 190 | |||
| 191 | if ($this->fisDataService->getPersonData($this->security->getUser()->getFisPersId())) { |
||
| 192 | $this->view->assign('currentFisPersId', $this->security->getUser()->getFisPersId()); |
||
| 193 | } |
||
| 194 | |||
| 195 | $personGroup = $this->metadataGroupRepository->findPersonGroup(); |
||
| 196 | $this->view->assign('personGroup', $personGroup->getUid()); |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Lists documents of the workspace |
||
| 201 | * |
||
| 202 | * @param array $checkedDocumentIdentifiers |
||
| 203 | * |
||
| 204 | * @return void |
||
| 205 | */ |
||
| 206 | protected function listWorkspaceAction($checkedDocumentIdentifiers = []) |
||
| 207 | { |
||
| 208 | $args = $this->request->getArguments(); |
||
| 209 | if ($args['refresh']) { |
||
| 210 | $workspaceSessionData = $this->session->getWorkspaceData(); |
||
| 211 | $workspaceSessionData->clearSort(); |
||
| 212 | $workspaceSessionData->clearFilters(); |
||
| 213 | |||
| 214 | $this->session->setWorkspaceData($workspaceSessionData); |
||
| 215 | } |
||
| 216 | |||
| 217 | if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) { |
||
| 218 | $this->view->assign('isWorkspace', true); |
||
| 219 | } elseif ($this->security->getUser()->getUserRole() === Security::ROLE_RESEARCHER) { |
||
| 220 | $this->view->assign('isWorkspace', false); |
||
| 221 | } else { |
||
| 222 | $message = LocalizationUtility::translate( |
||
| 223 | 'manager.workspace.accessDenied', 'dpf' |
||
| 224 | ); |
||
| 225 | $this->addFlashMessage($message, '', AbstractMessage::ERROR); |
||
| 226 | } |
||
| 227 | |||
| 228 | $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController(), |
||
| 229 | $this->uriBuilder->getRequest()->getRequestUri() |
||
| 230 | ); |
||
| 231 | |||
| 232 | $currentPage = null; |
||
| 233 | $pagination = $this->getParametersSafely('@widget_0'); |
||
| 234 | if ($pagination) { |
||
| 235 | $checkedDocumentIdentifiers = []; |
||
| 236 | $currentPage = $pagination['currentPage']; |
||
| 237 | } else { |
||
| 238 | $currentPage = 1; |
||
| 239 | } |
||
| 240 | |||
| 241 | $this->list((empty($currentPage)? 0 : ($currentPage-1) * $this->itemsPerPage())); |
||
| 242 | |||
| 243 | $this->view->assign('currentPage', $currentPage); |
||
| 244 | $this->view->assign('workspaceListAction', $this->getCurrentAction()); |
||
| 245 | $this->view->assign('checkedDocumentIdentifiers', $checkedDocumentIdentifiers); |
||
| 246 | } |
||
| 247 | |||
| 248 | |||
| 249 | /** |
||
| 250 | * Batch operations action. |
||
| 251 | * @param array $listData |
||
| 252 | */ |
||
| 253 | public function batchAction($listData) |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Batch operation, register documents. |
||
| 262 | * @param array $listData |
||
| 263 | * @throws \EWW\Dpf\Exceptions\DocumentMaxSizeErrorException |
||
| 264 | */ |
||
| 265 | public function batchRegisterAction($listData) |
||
| 266 | { |
||
| 267 | $successful = []; |
||
| 268 | $checkedDocumentIdentifiers = []; |
||
| 269 | |||
| 270 | if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) { |
||
| 271 | $checkedDocumentIdentifiers = $listData['documentIdentifiers']; |
||
| 272 | foreach ($listData['documentIdentifiers'] as $documentIdentifier) { |
||
| 273 | |||
| 274 | $this->editingLockService->lock( |
||
| 275 | $documentIdentifier, $this->security->getUser()->getUid() |
||
| 276 | ); |
||
| 277 | |||
| 278 | if (is_numeric($documentIdentifier)) { |
||
| 279 | $document = $this->documentManager->read($documentIdentifier); |
||
| 280 | |||
| 281 | if ($this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) { |
||
| 282 | |||
| 283 | if ($this->documentValidator->validate($document)) { |
||
| 284 | |||
| 285 | if ( |
||
| 286 | $this->documentManager->update( |
||
| 287 | $document, |
||
| 288 | DocumentWorkflow::TRANSITION_REGISTER |
||
| 289 | ) |
||
| 290 | ) { |
||
| 291 | $this->bookmarkRepository->addBookmark( |
||
| 292 | $document, |
||
| 293 | $this->security->getUser()->getUid() |
||
| 294 | ); |
||
| 295 | |||
| 296 | $successful[] = $documentIdentifier; |
||
| 297 | |||
| 298 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 299 | $notifier->sendRegisterNotification($document); |
||
| 300 | |||
| 301 | // index the document |
||
| 302 | $this->signalSlotDispatcher->dispatch( |
||
| 303 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 304 | 'indexDocument', [$document] |
||
| 305 | ); |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } |
||
| 309 | } |
||
| 310 | } |
||
| 311 | |||
| 312 | |||
| 313 | if (sizeof($successful) == 1) { |
||
| 314 | $locallangKey = 'manager.workspace.batchAction.register.success.singular'; |
||
| 315 | } else { |
||
| 316 | $locallangKey = 'manager.workspace.batchAction.register.success.plural'; |
||
| 317 | } |
||
| 318 | |||
| 319 | $message = LocalizationUtility::translate( |
||
| 320 | $locallangKey, |
||
| 321 | 'dpf', |
||
| 322 | [sizeof($successful), sizeof($listData['documentIdentifiers'])] |
||
| 323 | ); |
||
| 324 | |||
| 325 | |||
| 326 | $this->addFlashMessage( |
||
| 327 | $message, '', |
||
| 328 | (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING) |
||
| 329 | ); |
||
| 330 | |||
| 331 | } else { |
||
| 332 | $message = LocalizationUtility::translate( |
||
| 333 | 'manager.workspace.batchAction.failure', |
||
| 334 | 'dpf'); |
||
| 335 | $this->addFlashMessage($message, '', AbstractMessage::ERROR); |
||
| 336 | } |
||
| 337 | |||
| 338 | list($redirectAction, $redirectController) = $this->session->getStoredAction(); |
||
| 339 | $this->redirect( |
||
| 340 | $redirectAction, $redirectController, null, |
||
| 341 | array('message' => $message, 'checkedDocumentIdentifiers' => $checkedDocumentIdentifiers)); |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Batch operation, set documents to "In progress". |
||
| 346 | * @param array $listData |
||
| 347 | */ |
||
| 348 | public function batchSetInProgressAction($listData) |
||
| 349 | { |
||
| 350 | $successful = []; |
||
| 351 | $checkedDocumentIdentifiers = []; |
||
| 352 | |||
| 353 | if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) { |
||
| 354 | $checkedDocumentIdentifiers = $listData['documentIdentifiers']; |
||
| 355 | foreach ($listData['documentIdentifiers'] as $documentIdentifier) { |
||
| 356 | |||
| 357 | $this->editingLockService->lock( |
||
| 358 | $documentIdentifier, $this->security->getUser()->getUid() |
||
| 359 | ); |
||
| 360 | |||
| 361 | $document = $this->documentManager->read($documentIdentifier); |
||
| 362 | |||
| 363 | if ($this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) { |
||
| 364 | |||
| 365 | $document->setTemporary(false); |
||
| 366 | |||
| 367 | if ( |
||
| 368 | $this->documentManager->update( |
||
| 369 | $document, |
||
| 370 | DocumentWorkflow::TRANSITION_IN_PROGRESS |
||
| 371 | ) |
||
| 372 | ) { |
||
| 373 | $successful[] = $documentIdentifier; |
||
| 374 | |||
| 375 | // index the document |
||
| 376 | $this->signalSlotDispatcher->dispatch( |
||
| 377 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 378 | 'indexDocument', [$document] |
||
| 379 | ); |
||
| 380 | } |
||
| 381 | } |
||
| 382 | } |
||
| 383 | |||
| 384 | if (sizeof($successful) == 1) { |
||
| 385 | $locallangKey = 'manager.workspace.batchAction.setInProgress.success.singular'; |
||
| 386 | } else { |
||
| 387 | $locallangKey = 'manager.workspace.batchAction.setInProgress.success.plural'; |
||
| 388 | } |
||
| 389 | |||
| 390 | $message = LocalizationUtility::translate( |
||
| 391 | $locallangKey, |
||
| 392 | 'dpf', |
||
| 393 | [sizeof($successful), sizeof($listData['documentIdentifiers'])] |
||
| 394 | ); |
||
| 395 | |||
| 396 | $this->addFlashMessage( |
||
| 397 | $message, '', |
||
| 398 | (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING) |
||
| 399 | ); |
||
| 400 | |||
| 401 | } else { |
||
| 402 | $message = LocalizationUtility::translate( |
||
| 403 | 'manager.workspace.batchAction.failure', |
||
| 404 | 'dpf'); |
||
| 405 | $this->addFlashMessage($message, '', AbstractMessage::ERROR); |
||
| 406 | } |
||
| 407 | |||
| 408 | list($redirectAction, $redirectController) = $this->session->getStoredAction(); |
||
| 409 | $this->redirect( |
||
| 410 | $redirectAction, $redirectController, null, |
||
| 411 | array('message' => $message, 'checkedDocumentIdentifiers' => $checkedDocumentIdentifiers)); |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Batch operation, remove documents. |
||
| 416 | * @param array $listData |
||
| 417 | */ |
||
| 418 | public function batchRemoveAction($listData) |
||
| 419 | { |
||
| 420 | $successful = []; |
||
| 421 | $checkedDocumentIdentifiers = []; |
||
| 422 | |||
| 423 | if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) { |
||
| 424 | $checkedDocumentIdentifiers = $listData['documentIdentifiers']; |
||
| 425 | foreach ($listData['documentIdentifiers'] as $documentIdentifier) { |
||
| 426 | $feUserUid = $this->security->getUser()->getUid(); |
||
| 427 | $bookmark = $this->bookmarkRepository->findBookmark($feUserUid, $documentIdentifier); |
||
| 428 | if ($bookmark instanceof Bookmark) { |
||
| 429 | $this->bookmarkRepository->remove($bookmark); |
||
| 430 | $successful[] = $documentIdentifier; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | |||
| 435 | if (sizeof($successful) == 1) { |
||
| 436 | $locallangKey = 'manager.workspace.batchAction.remove.success.singular'; |
||
| 437 | } else { |
||
| 438 | $locallangKey = 'manager.workspace.batchAction.remove.success.plural'; |
||
| 439 | } |
||
| 440 | |||
| 441 | $message = LocalizationUtility::translate( |
||
| 442 | $locallangKey, |
||
| 443 | 'dpf', |
||
| 444 | [sizeof($successful), sizeof($listData['documentIdentifiers'])] |
||
| 445 | ); |
||
| 446 | $this->addFlashMessage( |
||
| 447 | $message, '', |
||
| 448 | (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING) |
||
| 449 | ); |
||
| 450 | } else { |
||
| 451 | $message = LocalizationUtility::translate( |
||
| 452 | 'manager.workspace.batchAction.failure', |
||
| 453 | 'dpf'); |
||
| 454 | $this->addFlashMessage($message, '', AbstractMessage::ERROR); |
||
| 455 | } |
||
| 456 | |||
| 457 | list($redirectAction, $redirectController) = $this->session->getStoredAction(); |
||
| 458 | $this->redirect( |
||
| 459 | $redirectAction, $redirectController, null, |
||
| 460 | array('message' => $message, 'checkedDocumentIdentifiers' => $checkedDocumentIdentifiers)); |
||
| 461 | } |
||
| 462 | |||
| 463 | |||
| 464 | /** |
||
| 465 | * Batch operation, release documents. |
||
| 466 | * @param array $listData |
||
| 467 | */ |
||
| 468 | public function batchReleaseValidatedAction($listData) |
||
| 469 | { |
||
| 470 | $this->batchRelease($listData, true); |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Batch operation, release as unvalidated documents. |
||
| 475 | * @param array $listData |
||
| 476 | */ |
||
| 477 | public function batchReleaseUnvalidatedAction($listData) |
||
| 478 | { |
||
| 479 | $this->batchRelease($listData, false); |
||
| 480 | } |
||
| 481 | |||
| 482 | |||
| 483 | |||
| 484 | |||
| 485 | /** |
||
| 486 | * Batch operation, release documents. |
||
| 487 | * @param array $listData |
||
| 488 | * @param bool $validated |
||
| 489 | */ |
||
| 490 | protected function batchRelease($listData, $validated) |
||
| 491 | { |
||
| 492 | $successful = []; |
||
| 493 | $checkedDocumentIdentifiers = []; |
||
| 494 | |||
| 495 | if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) { |
||
| 496 | $checkedDocumentIdentifiers = $listData['documentIdentifiers']; |
||
| 497 | foreach ($listData['documentIdentifiers'] as $documentIdentifier) { |
||
| 498 | |||
| 499 | $this->editingLockService->lock( |
||
| 500 | $documentIdentifier, $this->security->getUser()->getUid() |
||
| 501 | ); |
||
| 502 | |||
| 503 | $document = $this->documentManager->read($documentIdentifier); |
||
| 504 | |||
| 505 | switch ($document->getState()) { |
||
| 506 | case DocumentWorkflow::STATE_REGISTERED_NONE: |
||
| 507 | case DocumentWorkflow::STATE_DISCARDED_NONE: |
||
| 508 | case DocumentWorkflow::STATE_POSTPONED_NONE: |
||
| 509 | $documentVoterAttribute = DocumentVoter::RELEASE_PUBLISH; |
||
| 510 | $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_PUBLISH; |
||
| 511 | break; |
||
| 512 | |||
| 513 | case DocumentWorkflow::STATE_NONE_DELETED: |
||
| 514 | case DocumentWorkflow::STATE_NONE_INACTIVE: |
||
| 515 | case DocumentWorkflow::STATE_IN_PROGRESS_DELETED: |
||
| 516 | case DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE: |
||
| 517 | case DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE: |
||
| 518 | $documentVoterAttribute = DocumentVoter::RELEASE_ACTIVATE; |
||
| 519 | $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE; |
||
| 520 | break; |
||
| 521 | default: |
||
| 522 | $documentVoterAttribute = null; |
||
| 523 | $documentWorkflowTransition = null; |
||
| 524 | break; |
||
| 525 | } |
||
| 526 | |||
| 527 | if ($this->authorizationChecker->isGranted($documentVoterAttribute, $document)) { |
||
| 528 | |||
| 529 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 530 | $internalFormat->setValidation($validated); |
||
| 531 | $document->setXmlData($internalFormat->getXml()); |
||
| 532 | |||
| 533 | if ($this->documentManager->update($document, $documentWorkflowTransition)) { |
||
| 534 | $successful[] = $documentIdentifier; |
||
| 535 | |||
| 536 | $this->bookmarkRepository->removeBookmark( |
||
| 537 | $document, $this->security->getUser()->getUid() |
||
| 538 | ); |
||
| 539 | |||
| 540 | //$notifier = $this->objectManager->get(Notifier::class); |
||
| 541 | //$notifier->sendRegisterNotification($document); |
||
| 542 | } |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | if (sizeof($successful) == 1) { |
||
| 547 | $locallangKey = 'manager.workspace.batchAction.release.success.singular'; |
||
| 548 | } else { |
||
| 549 | $locallangKey = 'manager.workspace.batchAction.release.success.plural'; |
||
| 550 | } |
||
| 551 | |||
| 552 | $message = LocalizationUtility::translate( |
||
| 553 | $locallangKey, |
||
| 554 | 'dpf', |
||
| 555 | [sizeof($successful), sizeof($listData['documentIdentifiers'])] |
||
| 556 | ); |
||
| 557 | $this->addFlashMessage( |
||
| 558 | $message, '', |
||
| 559 | (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING) |
||
| 560 | ); |
||
| 561 | |||
| 562 | if (sizeof($successful) === 1 ) { |
||
| 563 | $this->addFlashMessage( |
||
| 564 | "1 ".LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), |
||
| 565 | '', |
||
| 566 | AbstractMessage::INFO |
||
| 567 | ); |
||
| 568 | } |
||
| 569 | |||
| 570 | if (sizeof($successful) > 1 ) { |
||
| 571 | $this->addFlashMessage( |
||
| 572 | LocalizationUtility::translate( |
||
| 573 | "manager.workspace.bookmarkRemoved.plural", "dpf", [sizeof($successful)] |
||
| 574 | ), |
||
| 575 | '', |
||
| 576 | AbstractMessage::INFO |
||
| 577 | ); |
||
| 578 | } |
||
| 579 | |||
| 580 | } else { |
||
| 581 | $message = LocalizationUtility::translate( |
||
| 582 | 'manager.workspace.batchAction.failure', |
||
| 583 | 'dpf'); |
||
| 584 | $this->addFlashMessage($message, '', AbstractMessage::ERROR); |
||
| 585 | } |
||
| 586 | |||
| 587 | list($redirectAction, $redirectController) = $this->session->getStoredAction(); |
||
| 588 | $this->redirect( |
||
| 589 | $redirectAction, $redirectController, null, |
||
| 590 | array('message' => $message, 'checkedDocumentIdentifiers' => $checkedDocumentIdentifiers)); |
||
| 591 | |||
| 592 | } |
||
| 593 | |||
| 594 | /** |
||
| 595 | * get list view data for the workspace |
||
| 596 | * |
||
| 597 | * @param int $from |
||
| 598 | * @param array $bookmarkIdentifiers |
||
| 599 | * @param array $filters |
||
| 600 | * @param array $excludeFilters |
||
| 601 | * @param string $sortField |
||
| 602 | * @param string $sortOrder |
||
| 603 | * |
||
| 604 | * @return array |
||
| 605 | */ |
||
| 606 | protected function getWorkspaceQuery( |
||
| 607 | $from = 0, $bookmarkIdentifiers = [], $filters = [], $excludeFilters = [], $sortField = null, $sortOrder = null |
||
| 608 | ) |
||
| 609 | { |
||
| 610 | $workspaceFilter = [ |
||
| 611 | 'bool' => [ |
||
| 612 | 'must' => [ |
||
| 613 | [ |
||
| 614 | 'bool' => [ |
||
| 615 | 'must' => [ |
||
| 616 | [ |
||
| 617 | 'term' => [ |
||
| 618 | 'creator' => $this->security->getUser()->getUid() |
||
| 619 | ] |
||
| 620 | ], |
||
| 621 | [ |
||
| 622 | 'bool' => [ |
||
| 623 | 'should' => [ |
||
| 624 | [ |
||
| 625 | 'term' => [ |
||
| 626 | 'state' => DocumentWorkflow::STATE_NEW_NONE |
||
| 627 | ] |
||
| 628 | ] |
||
| 629 | ] |
||
| 630 | ] |
||
| 631 | ] |
||
| 632 | ] |
||
| 633 | ] |
||
| 634 | ] |
||
| 635 | ] |
||
| 636 | ] |
||
| 637 | ]; |
||
| 638 | |||
| 639 | return $this->queryBuilder->buildQuery( |
||
| 640 | $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters, |
||
| 641 | $excludeFilters, $sortField, $sortOrder |
||
| 642 | ); |
||
| 643 | } |
||
| 644 | |||
| 645 | |||
| 646 | /** |
||
| 647 | * get list view data for the my publications list. |
||
| 648 | * |
||
| 649 | * @param int $from |
||
| 650 | * @param array $bookmarkIdentifiers |
||
| 651 | * @param array $filters |
||
| 652 | * @param array $excludeFilters |
||
| 653 | * @param string $sortField |
||
| 654 | * @param string $sortOrder |
||
| 655 | * |
||
| 656 | * @return array |
||
| 657 | */ |
||
| 658 | protected function getMyPublicationsQuery( |
||
| 708 | ); |
||
| 709 | } |
||
| 710 | |||
| 711 | |||
| 712 | /** |
||
| 713 | * A temporary solution to initialize the index. |
||
| 714 | * |
||
| 715 | * @param int $start |
||
| 716 | * @param int $stop |
||
| 717 | * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
||
| 718 | */ |
||
| 719 | public function initIndexAction($start = 1, $stop = 100) |
||
| 720 | { |
||
| 721 | /** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */ |
||
| 722 | $signalSlotDispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class); |
||
| 723 | |||
| 724 | /** @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager */ |
||
| 725 | $documentTransferManager = $this->objectManager->get(\EWW\Dpf\Services\Transfer\DocumentTransferManager::class); |
||
| 726 | |||
| 727 | $fedoraRepository = $this->objectManager->get(\EWW\Dpf\Services\Transfer\FedoraRepository::class); |
||
| 728 | $documentTransferManager->setRemoteRepository($fedoraRepository); |
||
| 729 | |||
| 730 | for ($i = $start; $i < $stop; $i++) { |
||
| 731 | try { |
||
| 732 | $document = $documentTransferManager->retrieve('qucosa:' . $i); |
||
| 733 | |||
| 734 | if ($document instanceof Document) { |
||
| 735 | $state = $document->getState(); |
||
| 736 | $document->setState( |
||
| 737 | str_replace( |
||
| 738 | DocumentWorkflow::LOCAL_STATE_IN_PROGRESS, |
||
| 739 | DocumentWorkflow::LOCAL_STATE_NONE, |
||
| 740 | $state |
||
| 741 | ) |
||
| 742 | ); |
||
| 743 | |||
| 744 | // index the document |
||
| 745 | $signalSlotDispatcher->dispatch( |
||
| 746 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 747 | 'indexDocument', [$document] |
||
| 748 | ); |
||
| 749 | |||
| 750 | $this->documentRepository->remove($document); |
||
| 751 | } |
||
| 752 | } catch (\EWW\Dpf\Exceptions\RetrieveDocumentErrorException $e) { |
||
| 753 | // Nothing to be done. |
||
| 754 | } |
||
| 755 | } |
||
| 756 | |||
| 757 | foreach ($this->documentRepository->findAll() as $document) { |
||
| 758 | |||
| 759 | $creationDate = $document->getCreationDate(); |
||
| 760 | if (empty($creationDate) && $document->getObjectIdentifier()) { |
||
| 761 | $creationDate = $document->getCreationDate(); |
||
| 762 | } |
||
| 763 | $document->setCreationDate($creationDate); |
||
| 764 | $this->documentRepository->update($document); |
||
| 765 | |||
| 766 | if (!$document->isTemporary() && !$document->isSuggestion()) { |
||
| 767 | // index the document |
||
| 768 | $signalSlotDispatcher->dispatch( |
||
| 769 | \EWW\Dpf\Controller\AbstractController::class, |
||
| 770 | 'indexDocument', [$document] |
||
| 771 | ); |
||
| 772 | } |
||
| 773 | } |
||
| 774 | |||
| 775 | } |
||
| 776 | |||
| 777 | |||
| 778 | /** |
||
| 779 | * Action editDocument |
||
| 780 | * |
||
| 781 | * @param string $documentIdentifier |
||
| 782 | * @param string $activeGroup |
||
| 783 | * @param int $activeGroupIndex |
||
| 784 | * @return void |
||
| 785 | */ |
||
| 786 | public function editDocumentAction($documentIdentifier, $activeGroup = '', $activeGroupIndex = 0) |
||
| 847 | } |
||
| 848 | |||
| 849 | } |
||
| 850 | |||
| 851 | |||
| 852 | /** |
||
| 853 | * Returns the number of items to be shown per page. |
||
| 854 | * |
||
| 855 | * @return int |
||
| 856 | */ |
||
| 857 | protected function itemsPerPage() |
||
| 865 | } |
||
| 866 | |||
| 867 | } |
||
| 868 |