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