Total Complexity | 43 |
Total Lines | 393 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
22 | class Notifier |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * clientRepository |
||
27 | * |
||
28 | * @var \EWW\Dpf\Domain\Repository\ClientRepository |
||
29 | * @inject |
||
30 | */ |
||
31 | protected $clientRepository = null; |
||
32 | |||
33 | |||
34 | /** |
||
35 | * documentTypeRepository |
||
36 | * |
||
37 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
38 | * @inject |
||
39 | */ |
||
40 | protected $documentTypeRepository = null; |
||
41 | |||
42 | |||
43 | public function sendAdminNewSuggestionNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
44 | try { |
||
45 | /** @var $client \EWW\Dpf\Domain\Model\Client */ |
||
46 | $client = $this->clientRepository->findAll()->current(); |
||
47 | $clientAdminEmail = $client->getAdminEmail(); |
||
48 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
49 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
50 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
|
|||
51 | |||
52 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
53 | |||
54 | // Notify client admin |
||
55 | if ($clientAdminEmail) { |
||
56 | $subject = $client->getAdminNewSuggestionSubject(); |
||
57 | $body = $client->getAdminNewSuggestionBody(); |
||
58 | $mailType = 'text/html'; |
||
59 | |||
60 | if (empty($subject)) { |
||
61 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newSuggestion.admin.subject', 'dpf'); |
||
62 | } |
||
63 | |||
64 | if (empty($body)) { |
||
65 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newSuggestion.admin.body', 'dpf'); |
||
66 | $mailType = 'text/plain'; |
||
67 | } |
||
68 | |||
69 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
70 | |||
71 | } |
||
72 | |||
73 | } catch (\Exception $e) { |
||
74 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
75 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
76 | |||
77 | $logger->log( |
||
78 | LogLevel::ERROR, "sendAdminNewSuggestionNotification failed", |
||
79 | array( |
||
80 | 'document' => $document |
||
81 | ) |
||
82 | ); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | |||
87 | public function sendAdminEmbargoExpiredNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
88 | try { |
||
89 | /** @var $client \EWW\Dpf\Domain\Model\Client */ |
||
90 | $client = $this->clientRepository->findAll()->current(); |
||
91 | $clientAdminEmail = $client->getAdminEmail(); |
||
92 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
93 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
94 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
95 | |||
96 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
97 | |||
98 | // Notify client admin |
||
99 | if ($clientAdminEmail) { |
||
100 | $subject = $client->getAdminEmbargoSubject(); |
||
101 | $body = $client->getAdminEmbargoBody(); |
||
102 | $mailType = 'text/html'; |
||
103 | |||
104 | if (empty($subject)) { |
||
105 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.embargoExpired.admin.subject', 'dpf'); |
||
106 | } |
||
107 | |||
108 | if (empty($body)) { |
||
109 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.embargoExpired.admin.body', 'dpf'); |
||
110 | $mailType = 'text/plain'; |
||
111 | } |
||
112 | |||
113 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
114 | |||
115 | } |
||
116 | |||
117 | } catch (\Exception $e) { |
||
118 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
119 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
120 | |||
121 | $logger->log( |
||
122 | LogLevel::ERROR, "sendAdminEmbargoExpiredNotification failed", |
||
123 | array( |
||
124 | 'document' => $document |
||
125 | ) |
||
126 | ); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | |||
131 | public function getMailMarkerArray(Document $document, $client, $documentType, $slub, $mods) { |
||
132 | |||
133 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); |
||
134 | |||
135 | /** @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager */ |
||
136 | $configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface'); |
||
137 | $settings = $configurationManager->getConfiguration( |
||
138 | \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT, |
||
139 | 'dpf', |
||
140 | 'backoffice' |
||
141 | ); |
||
142 | |||
143 | $args['###CLIENT###'] = $client->getClient(); |
||
144 | $args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
||
145 | |||
146 | if ($documentType) { |
||
147 | $args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
||
148 | } else { |
||
149 | $args['###DOCUMENT_TYPE###'] = ''; |
||
150 | } |
||
151 | |||
152 | $args['###TITLE###'] = $document->getTitle(); |
||
153 | $args['###AUTHOR###'] = array_shift($document->getAuthors()); |
||
154 | |||
155 | $args['###SUBMITTER_NAME###'] = $slub->getSubmitterName(); |
||
156 | $args['###SUBMITTER_EMAIL###'] = $slub->getSubmitterEmail(); |
||
157 | $args['###SUBMITTER_NOTICE###'] = $slub->getSubmitterNotice(); |
||
158 | |||
159 | $args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
||
160 | $args['###URN###'] = $mods->getQucosaUrn(); |
||
161 | $args['###URL###'] = 'http://nbn-resolving.de/' . $mods->getQucosaUrn(); |
||
162 | |||
163 | $host = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); |
||
164 | $backofficePageId = $settings['plugin.']['tx_dpf.']['settings.']['backofficePluginPage']; |
||
165 | |||
166 | if ($document->isSuggestion()) { |
||
167 | $detailUrl = '<a href="' . $host . '/index.php?id=' . $backofficePageId; |
||
168 | $detailUrl .= '&tx_dpf_backoffice[document]=' . $document->getUid(); |
||
169 | $detailUrl .= '&tx_dpf_backoffice[action]=showSuggestionDetails'; |
||
170 | $detailUrl .= '&tx_dpf_backoffice[controller]=Document">Link zum Änderungsvorschlag</a>'; |
||
171 | } else { |
||
172 | $detailUrl = '<a href="' . $host . '/index.php?id=' . $backofficePageId; |
||
173 | $detailUrl .= '&tx_dpf_backoffice[document]=' . $document->getUid(); |
||
174 | $detailUrl .= '&tx_dpf_backoffice[action]=showDetails'; |
||
175 | $detailUrl .= '&tx_dpf_backoffice[controller]=Document">Link zum Dokument</a>'; |
||
176 | } |
||
177 | |||
178 | $args['###DETAIL_URL###'] = $detailUrl; |
||
179 | |||
180 | $args['###HAS_FILES###'] = 'Metadata only'; |
||
181 | |||
182 | if ($document->getFileData()) { |
||
183 | $args['###HAS_FILES###'] = 'Attachment'; |
||
184 | foreach ($document->getFileData() as $fileSection) { |
||
185 | foreach ($fileSection as $file) { |
||
186 | $args['###FILE_LIST###'] .= $file['title']; |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | |||
191 | return $args; |
||
192 | } |
||
193 | |||
194 | public function sendNewDocumentNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
195 | { |
||
196 | |||
197 | try { |
||
198 | $client = $this->clientRepository->findAll()->current(); |
||
199 | $clientAdminEmail = $client->getAdminEmail(); |
||
200 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
201 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
202 | $submitterEmail = $slub->getSubmitterEmail(); |
||
203 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
204 | $authors = $document->getAuthors(); |
||
205 | |||
206 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
207 | |||
208 | // Notify client admin |
||
209 | if ($clientAdminEmail) { |
||
210 | $subject = $client->getAdminNewDocumentNotificationSubject(); |
||
211 | $body = $client->getAdminNewDocumentNotificationBody(); |
||
212 | $mailType = 'text/html'; |
||
213 | |||
214 | if (empty($subject)) { |
||
215 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.subject', 'dpf'); |
||
216 | } |
||
217 | |||
218 | if (empty($body)) { |
||
219 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.body', 'dpf'); |
||
220 | $mailType = 'text/plain'; |
||
221 | } |
||
222 | |||
223 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
224 | |||
225 | } |
||
226 | |||
227 | |||
228 | // Notify submitter |
||
229 | if ($submitterEmail) { |
||
230 | $subject = $client->getSubmitterNewDocumentNotificationSubject(); |
||
231 | $body = $client->getSubmitterNewDocumentNotificationBody(); |
||
232 | $mailType = 'text/html'; |
||
233 | |||
234 | if (empty($subject)) { |
||
235 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.subject', 'dpf'); |
||
236 | } |
||
237 | |||
238 | if (empty($body)) { |
||
239 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.body', 'dpf'); |
||
240 | $mailType = 'text/plain'; |
||
241 | } |
||
242 | |||
243 | $this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
||
244 | } |
||
245 | |||
246 | } catch (\Exception $e) { |
||
247 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
248 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
249 | |||
250 | $logger->log( |
||
251 | LogLevel::ERROR, "sendNewDocumentNotification failed", |
||
252 | array( |
||
253 | 'document' => $document |
||
254 | ) |
||
255 | ); |
||
256 | } |
||
257 | |||
258 | } |
||
259 | |||
260 | public function sendIngestNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
261 | { |
||
262 | |||
263 | try { |
||
264 | $client = $this->clientRepository->findAll()->current(); |
||
265 | $clientAdminEmail = $client->getAdminEmail(); |
||
266 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
267 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
268 | $submitterEmail = $slub->getSubmitterEmail(); |
||
269 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
270 | |||
271 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
272 | |||
273 | // Notify submitter |
||
274 | if ($submitterEmail) { |
||
275 | $subject = $client->getSubmitterIngestNotificationSubject(); |
||
276 | $body = $client->getSubmitterIngestNotificationBody(); |
||
277 | $mailType = 'text/html'; |
||
278 | |||
279 | if (empty($subject)) { |
||
280 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.subject', 'dpf'); |
||
281 | } |
||
282 | |||
283 | if (empty($body)) { |
||
284 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.body', 'dpf'); |
||
285 | $mailType = 'text/plain'; |
||
286 | } |
||
287 | |||
288 | $this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
||
289 | } |
||
290 | } catch (\Exception $e) { |
||
291 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
292 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
293 | |||
294 | $logger->log( |
||
295 | LogLevel::ERROR, "sendIngestNotification failed", |
||
296 | array( |
||
297 | 'document' => $document |
||
298 | ) |
||
299 | ); |
||
300 | } |
||
301 | |||
302 | } |
||
303 | |||
304 | public function sendEmbargoNotification(\EWW\Dpf\Domain\Model\Document $document) { |
||
343 | ) |
||
344 | ); |
||
345 | } |
||
346 | } |
||
347 | |||
348 | public function sendRegisterNotification(\EWW\Dpf\Domain\Model\Document $document) |
||
349 | { |
||
350 | |||
351 | try { |
||
352 | $client = $this->clientRepository->findAll()->current(); |
||
353 | $clientAdminEmail = $client->getAdminEmail(); |
||
354 | $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
||
355 | $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
||
356 | $submitterEmail = $slub->getSubmitterEmail(); |
||
357 | $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
||
358 | |||
359 | $args = $this->getMailMarkerArray($document, $client, $documentType, $slub, $mods); |
||
360 | |||
361 | // Notify client admin |
||
362 | if ($clientAdminEmail) { |
||
363 | $subject = $client->getAdminRegisterDocumentNotificationSubject(); |
||
364 | $body = $client->getAdminRegisterDocumentNotificationBody(); |
||
365 | $mailType = 'text/html'; |
||
366 | |||
367 | if (empty($subject)) { |
||
368 | $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.subject', 'dpf'); |
||
369 | } |
||
370 | |||
371 | if (empty($body)) { |
||
372 | $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.body', 'dpf'); |
||
373 | $mailType = 'text/plain'; |
||
374 | } |
||
375 | |||
376 | $this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
||
377 | |||
378 | } |
||
379 | |||
380 | } catch (\Exception $e) { |
||
381 | /** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
||
382 | $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||
383 | |||
384 | $logger->log( |
||
385 | LogLevel::ERROR, "sendRegisterNotification failed", |
||
386 | array( |
||
387 | 'document' => $document |
||
388 | ) |
||
389 | ); |
||
390 | } |
||
391 | |||
392 | } |
||
393 | |||
394 | protected function replaceMarkers($message, $args) |
||
402 | } |
||
403 | |||
404 | |||
405 | protected function sendMail($reveiver, $subject, $body, $args, $mailType) |
||
406 | { |
||
418 |