| Total Complexity | 84 |
| Total Lines | 713 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 0 |
Complex classes like Notifier 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 Notifier, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class Notifier |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * clientRepository |
||
| 30 | * |
||
| 31 | * @var \EWW\Dpf\Domain\Repository\ClientRepository |
||
| 32 | * @inject |
||
| 33 | */ |
||
| 34 | protected $clientRepository = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * documentTypeRepository |
||
| 38 | * |
||
| 39 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
| 40 | * @inject |
||
| 41 | */ |
||
| 42 | protected $documentTypeRepository = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * depositLicenseRepository |
||
| 46 | * |
||
| 47 | * @var \EWW\Dpf\Domain\Repository\DepositLicenseRepository |
||
| 48 | * @inject |
||
| 49 | */ |
||
| 50 | protected $depositLicenseRepository = null; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * security |
||
| 54 | * |
||
| 55 | * @var \EWW\Dpf\Security\Security |
||
| 56 | * @inject |
||
| 57 | */ |
||
| 58 | protected $security = null; |
||
| 59 | |||
| 60 | public function sendAdminNewSuggestionNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 61 | try { |
||
| 62 | /** @var $client \EWW\Dpf\Domain\Model\Client */ |
||
| 63 | $client = $this->clientRepository->findAll()->current(); |
||
| 64 | $clientAdminEmail = $client->getAdminEmail(); |
||
| 65 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
|
|
|||
| 66 | |||
| 67 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 68 | |||
| 69 | // Notify client admin |
||
| 70 | if ($clientAdminEmail) { |
||
| 71 | $subject = $client->getAdminNewSuggestionSubject(); |
||
| 72 | $body = $client->getAdminNewSuggestionBody(); |
||
| 73 | $mailType = 'text/html'; |
||
| 74 | |||
| 75 | if (empty($subject)) { |
||
| 76 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newSuggestion.admin.subject', 'dpf'); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (empty($body)) { |
||
| 80 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newSuggestion.admin.body', 'dpf'); |
||
| 81 | $mailType = 'text/plain'; |
||
| 82 | } |
||
| 83 | |||
| 84 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
| 85 | |||
| 86 | } |
||
| 87 | |||
| 88 | } catch (\Exception $e) { |
||
| 89 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 90 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 91 | |||
| 92 | $logger->log( |
||
| 93 | LogLevel::ERROR, "sendAdminNewSuggestionNotification failed", |
||
| 94 | array( |
||
| 95 | 'document' => $document |
||
| 96 | ) |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | |||
| 102 | public function sendAdminEmbargoExpiredNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 103 | try { |
||
| 104 | /** @var $client \EWW\Dpf\Domain\Model\Client */ |
||
| 105 | $client = $this->clientRepository->findAll()->current(); |
||
| 106 | $clientAdminEmail = $client->getAdminEmail(); |
||
| 107 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 108 | |||
| 109 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 110 | |||
| 111 | // Notify client admin |
||
| 112 | if ($clientAdminEmail) { |
||
| 113 | $subject = $client->getAdminEmbargoSubject(); |
||
| 114 | $body = $client->getAdminEmbargoBody(); |
||
| 115 | $mailType = 'text/html'; |
||
| 116 | |||
| 117 | if (empty($subject)) { |
||
| 118 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.embargoExpired.admin.subject', 'dpf'); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (empty($body)) { |
||
| 122 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.embargoExpired.admin.body', 'dpf'); |
||
| 123 | $mailType = 'text/plain'; |
||
| 124 | } |
||
| 125 | |||
| 126 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
| 127 | |||
| 128 | } |
||
| 129 | |||
| 130 | } catch (\Exception $e) { |
||
| 131 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 132 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 133 | |||
| 134 | $logger->log( |
||
| 135 | LogLevel::ERROR, "sendAdminEmbargoExpiredNotification failed", |
||
| 136 | array( |
||
| 137 | 'document' => $document |
||
| 138 | ) |
||
| 139 | ); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getMailMarkerArray(Document $document, $client, $documentType, $reason = "") { |
||
| 144 | |||
| 145 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); |
||
| 146 | |||
| 147 | /** @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager */ |
||
| 148 | $configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface'); |
||
| 149 | $settings = $configurationManager->getConfiguration( |
||
| 150 | \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT, |
||
| 151 | 'dpf', |
||
| 152 | 'backoffice' |
||
| 153 | ); |
||
| 154 | |||
| 155 | $args['###CLIENT###'] = $client->getClient(); |
||
| 156 | $args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
||
| 157 | |||
| 158 | $args['###DOCUMENT_IDENTIFIER###'] = $document->getObjectIdentifier(); |
||
| 159 | |||
| 160 | if ($documentType) { |
||
| 161 | $args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
||
| 162 | } else { |
||
| 163 | $args['###DOCUMENT_TYPE###'] = ''; |
||
| 164 | } |
||
| 165 | |||
| 166 | $args['###TITLE###'] = $document->getTitle(); |
||
| 167 | |||
| 168 | $author = array_shift($document->getAuthors()); |
||
| 169 | $args['###AUTHOR###'] = $author['name']; |
||
| 170 | |||
| 171 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 172 | $args['###SUBMITTER_NAME###'] = $internalFormat->getSubmitterName(); |
||
| 173 | $args['###SUBMITTER_EMAIL###'] = $internalFormat->getSubmitterEmail(); |
||
| 174 | $args['###SUBMITTER_NOTICE###'] = $internalFormat->getSubmitterNotice(); |
||
| 175 | |||
| 176 | $args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
||
| 177 | $args['###URN###'] = $internalFormat->getQucosaUrn(); |
||
| 178 | $args['###URL###'] = 'http://nbn-resolving.de/' . $internalFormat->getQucosaUrn(); |
||
| 179 | |||
| 180 | $args['###REASON###'] = $reason; |
||
| 181 | |||
| 182 | $host = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); |
||
| 183 | $backofficePageId = $settings['plugin.']['tx_dpf.']['settings.']['backofficePluginPage']; |
||
| 184 | |||
| 185 | /** @var \EWW\Dpf\Domain\Model\DepositLicense $depositLicense */ |
||
| 186 | $depositLicense = $this->depositLicenseRepository->findOneByUri($document->getDepositLicense()); |
||
| 187 | if ($depositLicense instanceof \EWW\Dpf\Domain\Model\DepositLicense) { |
||
| 188 | $args['###LICENSE_URI###'] = $depositLicense->getUri(); |
||
| 189 | $args['###LICENSE_TEXT###'] = $depositLicense->getText(); |
||
| 190 | } |
||
| 191 | |||
| 192 | $args['###LICENSE_USERNAME###'] = $this->security->getUser()->getUsername(); |
||
| 193 | |||
| 194 | if ($document->isSuggestion()) { |
||
| 195 | $detailUrl = '<a href="' . $host . '/index.php?id=' . $backofficePageId; |
||
| 196 | $detailUrl .= '&tx_dpf_backoffice[document]=' . $document->getUid(); |
||
| 197 | $detailUrl .= '&tx_dpf_backoffice[action]=showSuggestionDetails'; |
||
| 198 | $detailUrl .= '&tx_dpf_backoffice[controller]=Document">Link zum Änderungsvorschlag</a>'; |
||
| 199 | } else { |
||
| 200 | $documentIdentifier = $document->getProcessNumber(); |
||
| 201 | if (empty($documentIdentifier)) { |
||
| 202 | $documentIdentifier = $document->getDocumentIdentifier(); |
||
| 203 | } |
||
| 204 | $detailUrl = '<a href="' . $host . '/index.php?id=' . $backofficePageId; |
||
| 205 | $detailUrl .= '&tx_dpf_backoffice[document]=' . $documentIdentifier; |
||
| 206 | $detailUrl .= '&tx_dpf_backoffice[action]=showDetails'; |
||
| 207 | $detailUrl .= '&tx_dpf_backoffice[controller]=Document">Link zum Dokument</a>'; |
||
| 208 | } |
||
| 209 | |||
| 210 | $args['###DETAIL_URL###'] = $detailUrl; |
||
| 211 | |||
| 212 | $args['###HAS_FILES###'] = 'Metadata only'; |
||
| 213 | |||
| 214 | if ($document->getFileData()) { |
||
| 215 | $args['###HAS_FILES###'] = 'Attachment'; |
||
| 216 | $fileList = []; |
||
| 217 | foreach ($document->getFile() as $file) { |
||
| 218 | if (!$file->isFileGroupDeleted()) { |
||
| 219 | $fileList[] = $file->getTitle(); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | $args['###FILE_LIST###'] .= implode(", ", $fileList); |
||
| 223 | } |
||
| 224 | |||
| 225 | return $args; |
||
| 226 | } |
||
| 227 | |||
| 228 | public function sendSuggestionAcceptNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 229 | |||
| 230 | try { |
||
| 231 | /** @var Client $client */ |
||
| 232 | $client = $this->clientRepository->findAll()->current(); |
||
| 233 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 234 | |||
| 235 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 236 | |||
| 237 | // Active messaging: Suggestion accept |
||
| 238 | if ($client->getActiveMessagingSuggestionAcceptUrl()) { |
||
| 239 | if ($slub->getFisId()) { |
||
| 240 | $request = Request::post($client->getActiveMessagingSuggestionAcceptUrl()); |
||
| 241 | if ($body = $client->getActiveMessagingSuggestionAcceptUrlBody()) { |
||
| 242 | $request->body($this->replaceMarkers($body, $args)); |
||
| 243 | } |
||
| 244 | $request->send(); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | } catch (\Exception $e) { |
||
| 249 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 250 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 251 | |||
| 252 | $logger->log( |
||
| 253 | LogLevel::ERROR, "sendSuggestionAcceptNotification failed", |
||
| 254 | array( |
||
| 255 | 'document' => $document |
||
| 256 | ) |
||
| 257 | ); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param Document $document |
||
| 263 | * @param string $reason |
||
| 264 | */ |
||
| 265 | public function sendSuggestionDeclineNotification(\EWW\Dpf\Domain\Model\Document $document, $reason = "") { |
||
| 293 | ) |
||
| 294 | ); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | public function sendChangedDocumentNotification(\EWW\Dpf\Domain\Model\Document $document, $addedFisIdOnly = false) { |
||
| 329 | ) |
||
| 330 | ); |
||
| 331 | } |
||
| 332 | } |
||
| 333 | |||
| 334 | |||
| 335 | public function sendReleasePublishNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
| 336 | { |
||
| 337 | try { |
||
| 338 | /** @var Client $client */ |
||
| 339 | $client = $this->clientRepository->findAll()->current(); |
||
| 340 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
| 341 | /** @var \EWW\Dpf\Helper\Slub $slub */ |
||
| 342 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
| 343 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 344 | |||
| 345 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
| 346 | |||
| 347 | // Active messaging: New document (Release publish) |
||
| 348 | if ($client->getActiveMessagingNewDocumentUrl()) { |
||
| 349 | $fisId = $slub->getFisId(); |
||
| 350 | if (empty($fisId)) { |
||
| 351 | $request = Request::post($client->getActiveMessagingNewDocumentUrl()); |
||
| 352 | if ($body = $client->getActiveMessagingNewDocumentUrlBody()) { |
||
| 353 | $request->body($this->replaceMarkers($body, $args)); |
||
| 354 | } |
||
| 355 | $request->send(); |
||
| 356 | } |
||
| 357 | } |
||
| 358 | |||
| 359 | } catch (\Exception $e) { |
||
| 360 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 361 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 362 | |||
| 363 | $logger->log( |
||
| 364 | LogLevel::ERROR, "sendReleasePublishNotification failed", |
||
| 365 | array( |
||
| 366 | 'document' => $document |
||
| 367 | ) |
||
| 368 | ); |
||
| 369 | } |
||
| 370 | } |
||
| 371 | |||
| 372 | |||
| 373 | public function sendNewDocumentNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
| 374 | { |
||
| 375 | |||
| 376 | try { |
||
| 377 | /** @var Client $client */ |
||
| 378 | $client = $this->clientRepository->findAll()->current(); |
||
| 379 | $clientAdminEmail = $client->getAdminEmail(); |
||
| 380 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 381 | $submitterEmail = $internalFormat->getSubmitterEmail(); |
||
| 382 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 383 | $authors = $document->getAuthors(); |
||
| 384 | |||
| 385 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 386 | |||
| 387 | // Notify client admin |
||
| 388 | if ($clientAdminEmail) { |
||
| 389 | $subject = $client->getAdminNewDocumentNotificationSubject(); |
||
| 390 | $body = $client->getAdminNewDocumentNotificationBody(); |
||
| 391 | $mailType = 'text/html'; |
||
| 392 | |||
| 393 | if (empty($subject)) { |
||
| 394 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.subject', 'dpf'); |
||
| 395 | } |
||
| 396 | |||
| 397 | if (empty($body)) { |
||
| 398 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.body', 'dpf'); |
||
| 399 | $mailType = 'text/plain'; |
||
| 400 | } |
||
| 401 | |||
| 402 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
| 403 | |||
| 404 | } |
||
| 405 | |||
| 406 | |||
| 407 | // Notify submitter |
||
| 408 | if ($submitterEmail) { |
||
| 409 | $subject = $client->getSubmitterNewDocumentNotificationSubject(); |
||
| 410 | $body = $client->getSubmitterNewDocumentNotificationBody(); |
||
| 411 | $mailType = 'text/html'; |
||
| 412 | |||
| 413 | if (empty($subject)) { |
||
| 414 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.subject', 'dpf'); |
||
| 415 | } |
||
| 416 | |||
| 417 | if (empty($body)) { |
||
| 418 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.body', 'dpf'); |
||
| 419 | $mailType = 'text/plain'; |
||
| 420 | } |
||
| 421 | |||
| 422 | $this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
||
| 423 | } |
||
| 424 | |||
| 425 | } catch (\Exception $e) { |
||
| 426 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 427 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 428 | |||
| 429 | $logger->log( |
||
| 430 | LogLevel::ERROR, "sendNewDocumentNotification failed", |
||
| 431 | array( |
||
| 432 | 'document' => $document |
||
| 433 | ) |
||
| 434 | ); |
||
| 435 | } |
||
| 436 | |||
| 437 | } |
||
| 438 | |||
| 439 | public function sendIngestNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
| 440 | { |
||
| 441 | |||
| 442 | try { |
||
| 443 | $client = $this->clientRepository->findAll()->current(); |
||
| 444 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 445 | $submitterEmail = $internalFormat->getSubmitterEmail(); |
||
| 446 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 447 | |||
| 448 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 449 | |||
| 450 | // Notify submitter |
||
| 451 | if ($submitterEmail) { |
||
| 452 | $subject = $client->getSubmitterIngestNotificationSubject(); |
||
| 453 | $body = $client->getSubmitterIngestNotificationBody(); |
||
| 454 | $mailType = 'text/html'; |
||
| 455 | |||
| 456 | if (empty($subject)) { |
||
| 457 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.subject', 'dpf'); |
||
| 458 | } |
||
| 459 | |||
| 460 | if (empty($body)) { |
||
| 461 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.body', 'dpf'); |
||
| 462 | $mailType = 'text/plain'; |
||
| 463 | } |
||
| 464 | |||
| 465 | $this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
||
| 466 | } |
||
| 467 | } catch (\Exception $e) { |
||
| 468 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 469 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 470 | |||
| 471 | $logger->log( |
||
| 472 | LogLevel::ERROR, "sendIngestNotification failed", |
||
| 473 | array( |
||
| 474 | 'document' => $document |
||
| 475 | ) |
||
| 476 | ); |
||
| 477 | } |
||
| 478 | |||
| 479 | } |
||
| 480 | |||
| 481 | public function sendEmbargoNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
| 517 | ) |
||
| 518 | ); |
||
| 519 | } |
||
| 520 | } |
||
| 521 | |||
| 522 | public function sendRegisterNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
| 523 | { |
||
| 524 | |||
| 525 | try { |
||
| 526 | $client = $this->clientRepository->findAll()->current(); |
||
| 527 | $clientAdminEmail = $client->getAdminEmail(); |
||
| 528 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 529 | |||
| 530 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 531 | |||
| 532 | // Notify client admin |
||
| 533 | if ($clientAdminEmail) { |
||
| 534 | $subject = $client->getAdminRegisterDocumentNotificationSubject(); |
||
| 535 | $body = $client->getAdminRegisterDocumentNotificationBody(); |
||
| 536 | $mailType = 'text/html'; |
||
| 537 | |||
| 538 | if (empty($subject)) { |
||
| 539 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.subject', 'dpf'); |
||
| 540 | } |
||
| 541 | |||
| 542 | if (empty($body)) { |
||
| 543 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.body', 'dpf'); |
||
| 544 | $mailType = 'text/plain'; |
||
| 545 | } |
||
| 546 | |||
| 547 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
| 548 | |||
| 549 | } |
||
| 550 | |||
| 551 | } catch (\Exception $e) { |
||
| 552 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 553 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 554 | |||
| 555 | $logger->log( |
||
| 556 | LogLevel::ERROR, "sendRegisterNotification failed", |
||
| 557 | array( |
||
| 558 | 'document' => $document |
||
| 559 | ) |
||
| 560 | ); |
||
| 561 | } |
||
| 562 | |||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 567 | * @param array $recipients |
||
| 568 | */ |
||
| 569 | public function sendMyPublicationUpdateNotification(\EWW\Dpf\Domain\Model\Document $document, $recipients) |
||
| 613 | ) |
||
| 614 | ); |
||
| 615 | } |
||
| 616 | |||
| 617 | } |
||
| 618 | |||
| 619 | |||
| 620 | /** |
||
| 621 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 622 | * @param array $recipients |
||
| 623 | */ |
||
| 624 | public function sendMyPublicationNewNotification(\EWW\Dpf\Domain\Model\Document $document, $recipients) |
||
| 625 | { |
||
| 626 | |||
| 627 | try { |
||
| 628 | /** @var Client $client */ |
||
| 629 | $client = $this->clientRepository->findAll()->current(); |
||
| 630 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 631 | $author = array_shift($document->getAuthors()); |
||
| 632 | |||
| 633 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 634 | |||
| 635 | // Notify client admin |
||
| 636 | /** @var FrontendUser $recipient */ |
||
| 637 | foreach ($recipients as $recipient) { |
||
| 638 | |||
| 639 | if ($recipient->getEmail()) { |
||
| 640 | |||
| 641 | $subject = $client->getMypublicationsNewNotificationSubject(); |
||
| 642 | $body = $client->getMypublicationsNewNotificationBody(); |
||
| 643 | $mailType = 'text/html'; |
||
| 644 | |||
| 645 | if (empty($subject)) { |
||
| 646 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newPublication.mypublications.subject', |
||
| 647 | 'dpf'); |
||
| 648 | } |
||
| 649 | |||
| 650 | if (empty($body)) { |
||
| 651 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newPublication.mypublications.body', |
||
| 652 | 'dpf'); |
||
| 653 | $mailType = 'text/plain'; |
||
| 654 | } |
||
| 655 | |||
| 656 | $this->sendMail($recipient->getEmail(), $subject, $body, $args, $mailType); |
||
| 657 | } |
||
| 658 | } |
||
| 659 | |||
| 660 | } catch (\Exception $e) { |
||
| 661 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 662 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 663 | |||
| 664 | $logger->log( |
||
| 665 | LogLevel::ERROR, "sendRegisterNotification failed", |
||
| 666 | array( |
||
| 667 | 'document' => $document |
||
| 668 | ) |
||
| 669 | ); |
||
| 670 | } |
||
| 671 | |||
| 672 | } |
||
| 673 | |||
| 674 | public function sendDepositLicenseNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
| 675 | { |
||
| 676 | |||
| 677 | try { |
||
| 678 | /** @var Client $client */ |
||
| 679 | $client = $this->clientRepository->findAll()->current(); |
||
| 680 | $clientAdminEmail = $client->getAdminEmail(); |
||
| 681 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
| 682 | |||
| 683 | $args = $this->getMailMarkerArray($document, $client, $documentType); |
||
| 684 | |||
| 685 | // Notify client admin |
||
| 686 | if ($clientAdminEmail && $client->isSendAdminDepositLicenseNotification()) { |
||
| 687 | |||
| 688 | $subject = $client->getAdminDepositLicenseNotificationSubject(); |
||
| 689 | $body = $client->getAdminDepositLicenseNotificationBody(); |
||
| 690 | $mailType = 'text/html'; |
||
| 691 | |||
| 692 | if (empty($subject)) { |
||
| 693 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.depositLicense.admin.subject', 'dpf'); |
||
| 694 | } |
||
| 695 | |||
| 696 | if (empty($body)) { |
||
| 697 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.depositLicense.admin.body', 'dpf'); |
||
| 698 | $mailType = 'text/plain'; |
||
| 699 | } |
||
| 700 | |||
| 701 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
| 702 | } |
||
| 703 | |||
| 704 | } catch (\Exception $e) { |
||
| 705 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
| 706 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
| 707 | |||
| 708 | $logger->log( |
||
| 709 | LogLevel::ERROR, "sendDepositLicenseNotification failed", |
||
| 710 | array( |
||
| 711 | 'document' => $document |
||
| 712 | ) |
||
| 713 | ); |
||
| 714 | } |
||
| 715 | |||
| 716 | } |
||
| 717 | |||
| 718 | protected function replaceMarkers($message, $args) |
||
| 726 | } |
||
| 727 | |||
| 728 | |||
| 729 | protected function sendMail($reveiver, $subject, $body, $args, $mailType) |
||
| 730 | { |
||
| 731 | $emailReceiver = array(); |
||
| 732 | $emailReceiver[$reveiver] = $reveiver; |
||
| 733 | $message = (new \TYPO3\CMS\Core\Mail\MailMessage()) |
||
| 742 |