22declare (strict_types = 1 );
33namespace In2code \Powermail \Finisher ;
44
5+ use Doctrine \DBAL \DBALException ;
6+ use In2code \Powermail \Domain \Model \Mail ;
57use In2code \Powermail \Domain \Repository \MailRepository ;
68use In2code \Powermail \Domain \Service \SaveToAnyTableService ;
9+ use In2code \Powermail \Exception \DatabaseFieldMissingException ;
10+ use In2code \Powermail \Exception \PropertiesMissingException ;
711use In2code \Powermail \Utility \ObjectUtility ;
812use In2code \Powermail \Utility \StringUtility ;
913use TYPO3 \CMS \Core \TypoScript \TypoScriptService ;
14+ use TYPO3 \CMS \Core \Utility \GeneralUtility ;
15+ use TYPO3 \CMS \Extbase \Configuration \ConfigurationManagerInterface ;
1016use TYPO3 \CMS \Extbase \Object \Exception ;
1117use TYPO3 \CMS \Extbase \SignalSlot \Exception \InvalidSlotException ;
1218use TYPO3 \CMS \Extbase \SignalSlot \Exception \InvalidSlotReturnException ;
1723 */
1824class SaveToAnyTableFinisher extends AbstractFinisher implements FinisherInterface
1925{
20-
2126 /**
2227 * @var ContentObjectRenderer
28+ * local instance that can be manipulated via start() and has no influence to parent::contentObject
2329 */
24- protected $ contentObject ;
30+ protected $ contentObjectLocal ;
2531
2632 /**
2733 * @var array
2834 */
2935 protected $ dataArray = [];
3036
37+ /**
38+ * @param Mail $mail
39+ * @param array $configuration
40+ * @param array $settings
41+ * @param bool $formSubmitted
42+ * @param string $actionMethodName
43+ * @param ContentObjectRenderer $contentObject
44+ */
45+ public function __construct (
46+ Mail $ mail ,
47+ array $ configuration ,
48+ array $ settings ,
49+ bool $ formSubmitted ,
50+ string $ actionMethodName ,
51+ ContentObjectRenderer $ contentObject
52+ ) {
53+ parent ::__construct ($ mail , $ configuration , $ settings , $ formSubmitted , $ actionMethodName , $ contentObject );
54+ $ configurationManager = GeneralUtility::makeInstance (ConfigurationManagerInterface::class);
55+ $ this ->contentObjectLocal = $ configurationManager ->getContentObject ();
56+ }
57+
3158 /**
3259 * Preperation function for every table
3360 *
3461 * @return void
35- * @throws Exception
62+ * @throws DBALException
63+ * @throws DatabaseFieldMissingException
64+ * @throws PropertiesMissingException
3665 */
3766 public function savePreflightFinisher (): void
3867 {
3968 if ($ this ->isConfigurationAvailable ()) {
4069 foreach (array_keys ($ this ->configuration ) as $ key ) {
41- $ this ->contentObject ->start ($ this ->getDataArray ());
70+ $ this ->contentObjectLocal ->start ($ this ->getDataArray ());
4271 $ tableConfiguration = $ this ->configuration [$ key ];
4372 $ numberKey = (int )StringUtility::removeLastDot ($ key );
4473 if ($ this ->isSaveToAnyTableActivatedForSpecifiedTable ($ tableConfiguration )) {
@@ -54,12 +83,14 @@ public function savePreflightFinisher(): void
5483 * @param int $numberKey
5584 * @param array $tableConfiguration
5685 * @return void
57- * @throws Exception
86+ * @throws DBALException
87+ * @throws DatabaseFieldMissingException
88+ * @throws PropertiesMissingException
5889 */
5990 protected function saveSpecifiedTablePreflight (int $ numberKey , array $ tableConfiguration ): void
6091 {
6192 /* @var $saveService SaveToAnyTableService */
62- $ saveService = ObjectUtility:: getObjectManager ()-> get (
93+ $ saveService = GeneralUtility:: makeInstance (
6394 SaveToAnyTableService::class,
6495 $ this ->getTableName ($ tableConfiguration )
6596 );
@@ -80,7 +111,7 @@ protected function setPropertiesInSaveService(SaveToAnyTableService $saveService
80111 {
81112 foreach (array_keys ($ tableConfiguration ) as $ field ) {
82113 if (!$ this ->isSkippedKey ($ field )) {
83- $ value = $ this ->contentObject ->cObjGetSingle (
114+ $ value = $ this ->contentObjectLocal ->cObjGetSingle (
84115 $ tableConfiguration [$ field ],
85116 $ tableConfiguration [$ field . '. ' ]
86117 );
@@ -130,7 +161,7 @@ protected function addAdditionalWhereClause(SaveToAnyTableService $saveService,
130161 }
131162 if (!empty ($ tableConfiguration ['_ifUniqueWhereClause ' ])
132163 && !empty ($ tableConfiguration ['_ifUniqueWhereClause. ' ])) {
133- $ whereClause = $ this ->contentObject ->cObjGetSingle (
164+ $ whereClause = $ this ->contentObjectLocal ->cObjGetSingle (
134165 $ tableConfiguration ['_ifUniqueWhereClause ' ],
135166 $ tableConfiguration ['_ifUniqueWhereClause. ' ]
136167 );
@@ -150,7 +181,7 @@ protected function addAdditionalWhereClause(SaveToAnyTableService $saveService,
150181 */
151182 protected function getTableName (array $ tableConfiguration ): string
152183 {
153- return $ this ->contentObject ->cObjGetSingle ($ tableConfiguration ['_table ' ], $ tableConfiguration ['_table. ' ]);
184+ return $ this ->contentObjectLocal ->cObjGetSingle ($ tableConfiguration ['_table ' ], $ tableConfiguration ['_table. ' ]);
154185 }
155186
156187 /**
@@ -159,7 +190,10 @@ protected function getTableName(array $tableConfiguration): string
159190 */
160191 protected function isSaveToAnyTableActivatedForSpecifiedTable ($ tableConfiguration ): bool
161192 {
162- $ enable = $ this ->contentObject ->cObjGetSingle ($ tableConfiguration ['_enable ' ]??'' , $ tableConfiguration ['_enable. ' ]??null );
193+ $ enable = $ this ->contentObjectLocal ->cObjGetSingle (
194+ $ tableConfiguration ['_enable ' ] ?? '' ,
195+ $ tableConfiguration ['_enable. ' ] ?? null
196+ );
163197 return !empty ($ enable );
164198 }
165199
@@ -234,13 +268,4 @@ public function initializeFinisher(): void
234268 $ this ->addArrayToDataArray ($ mailRepository ->getVariablesWithMarkersFromMail ($ this ->mail ));
235269 }
236270 }
237-
238- /**
239- * @param ContentObjectRenderer $contentObject
240- * @return void
241- */
242- public function injectContentObject (ContentObjectRenderer $ contentObject ): void
243- {
244- $ this ->contentObject = $ contentObject ;
245- }
246271}
0 commit comments