Skip to content

Commit f0a631e

Browse files
committed
[BUGFIX] Fix regression after dd72729
For whatever reason the injection method for a local contentObject stopped working. We now create instances via constructor. In addition we renamed the property contentObject to contentObjectLocal to give a hint that this must not be deleted. Related: #776
1 parent 7085cf2 commit f0a631e

File tree

6 files changed

+104
-68
lines changed

6 files changed

+104
-68
lines changed

Classes/Domain/Service/SaveToAnyTableService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function setAdditionalWhere(string $additionalWhere): void
308308
/**
309309
* Remove not allowed signs
310310
*
311-
* @param $string
311+
* @param string $string
312312
* @return void
313313
*/
314314
protected function removeNotAllowedSigns(string &$string): void

Classes/Finisher/AbstractFinisher.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111
abstract class AbstractFinisher implements FinisherInterface
1212
{
13-
1413
/**
1514
* @var Mail
1615
*/
@@ -49,6 +48,30 @@ abstract class AbstractFinisher implements FinisherInterface
4948
*/
5049
protected $contentObject;
5150

51+
/**
52+
* @param Mail $mail
53+
* @param array $configuration
54+
* @param array $settings
55+
* @param bool $formSubmitted
56+
* @param string $actionMethodName
57+
* @param ContentObjectRenderer $contentObject
58+
*/
59+
public function __construct(
60+
Mail $mail,
61+
array $configuration,
62+
array $settings,
63+
bool $formSubmitted,
64+
string $actionMethodName,
65+
ContentObjectRenderer $contentObject
66+
) {
67+
$this->setMail($mail);
68+
$this->setConfiguration($configuration);
69+
$this->setSettings($settings);
70+
$this->setFormSubmitted($formSubmitted);
71+
$this->setActionMethodName($actionMethodName);
72+
$this->contentObject = $contentObject;
73+
}
74+
5275
/**
5376
* @return Mail
5477
*/
@@ -147,28 +170,4 @@ public function setActionMethodName(string $actionMethodName): FinisherInterface
147170
public function initializeFinisher(): void
148171
{
149172
}
150-
151-
/**
152-
* @param Mail $mail
153-
* @param array $configuration
154-
* @param array $settings
155-
* @param bool $formSubmitted
156-
* @param string $actionMethodName
157-
* @param ContentObjectRenderer $contentObject
158-
*/
159-
public function __construct(
160-
Mail $mail,
161-
array $configuration,
162-
array $settings,
163-
bool $formSubmitted,
164-
string $actionMethodName,
165-
ContentObjectRenderer $contentObject
166-
) {
167-
$this->setMail($mail);
168-
$this->setConfiguration($configuration);
169-
$this->setSettings($settings);
170-
$this->setFormSubmitted($formSubmitted);
171-
$this->setActionMethodName($actionMethodName);
172-
$this->contentObject = $contentObject;
173-
}
174173
}

Classes/Finisher/RedirectFinisher.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use In2code\Powermail\Domain\Service\RedirectUriService;
66
use In2code\Powermail\Utility\FrontendUtility;
7-
use In2code\Powermail\Utility\ObjectUtility;
7+
use TYPO3\CMS\Core\Utility\GeneralUtility;
88
use TYPO3\CMS\Core\Utility\HttpUtility;
99
use TYPO3\CMS\Extbase\Object\Exception;
1010

@@ -13,7 +13,6 @@
1313
*/
1414
class RedirectFinisher extends AbstractFinisher implements FinisherInterface
1515
{
16-
1716
/**
1817
* @var array
1918
*/
@@ -27,8 +26,7 @@ class RedirectFinisher extends AbstractFinisher implements FinisherInterface
2726
*/
2827
public function redirectToUriFinisher(): void
2928
{
30-
/** @var RedirectUriService $redirectService */
31-
$redirectService = ObjectUtility::getObjectManager()->get(RedirectUriService::class, $this->contentObject);
29+
$redirectService = GeneralUtility::makeInstance(RedirectUriService::class, $this->contentObject);
3230
$uri = $redirectService->getRedirectUri();
3331
if (!empty($uri) && $this->isRedirectEnabled()) {
3432
HttpUtility::redirect($uri);

Classes/Finisher/SaveToAnyTableFinisher.php

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\Finisher;
44

5+
use Doctrine\DBAL\DBALException;
6+
use In2code\Powermail\Domain\Model\Mail;
57
use In2code\Powermail\Domain\Repository\MailRepository;
68
use In2code\Powermail\Domain\Service\SaveToAnyTableService;
9+
use In2code\Powermail\Exception\DatabaseFieldMissingException;
10+
use In2code\Powermail\Exception\PropertiesMissingException;
711
use In2code\Powermail\Utility\ObjectUtility;
812
use In2code\Powermail\Utility\StringUtility;
913
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
14+
use TYPO3\CMS\Core\Utility\GeneralUtility;
15+
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
1016
use TYPO3\CMS\Extbase\Object\Exception;
1117
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException;
1218
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException;
@@ -17,28 +23,51 @@
1723
*/
1824
class 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
}

Classes/Finisher/SendParametersFinisher.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\Finisher;
44

5+
use In2code\Powermail\Domain\Model\Mail;
56
use In2code\Powermail\Domain\Repository\MailRepository;
67
use In2code\Powermail\Domain\Service\ConfigurationService;
78
use In2code\Powermail\Utility\ObjectUtility;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
810
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
911
use TYPO3\CMS\Extbase\Object\Exception;
1012
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException;
1113
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException;
14+
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1215

1316
/**
1417
* SendParametersFinisher to send params via CURL
1518
*/
1619
class SendParametersFinisher extends AbstractFinisher implements FinisherInterface
1720
{
18-
1921
/**
2022
* @var ConfigurationManagerInterface
23+
* local instance that can be manipulated via start() and has no influence to parent::contentObject
2124
*/
2225
protected $configurationManager;
2326

2427
/**
25-
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
28+
* @var ContentObjectRenderer
2629
*/
27-
protected $contentObject = null;
30+
protected $contentObjectLocal = null;
2831

2932
/**
3033
* TypoScript configuration part sendPost
@@ -48,6 +51,27 @@ class SendParametersFinisher extends AbstractFinisher implements FinisherInterfa
4851
*/
4952
protected $configuration;
5053

54+
/**
55+
* @param Mail $mail
56+
* @param array $configuration
57+
* @param array $settings
58+
* @param bool $formSubmitted
59+
* @param string $actionMethodName
60+
* @param ContentObjectRenderer $contentObject
61+
*/
62+
public function __construct(
63+
Mail $mail,
64+
array $configuration,
65+
array $settings,
66+
bool $formSubmitted,
67+
string $actionMethodName,
68+
ContentObjectRenderer $contentObject
69+
) {
70+
parent::__construct($mail, $configuration, $settings, $formSubmitted, $actionMethodName, $contentObject);
71+
$configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
72+
$this->contentObjectLocal = $configurationManager->getContentObject();
73+
}
74+
5175
/**
5276
* Send values via curl to a third party software
5377
*
@@ -103,7 +127,10 @@ protected function getCurlSettings(): array
103127
*/
104128
protected function getValues(): string
105129
{
106-
return $this->contentObject->cObjGetSingle($this->configuration['values'], $this->configuration['values.']);
130+
return $this->contentObjectLocal->cObjGetSingle(
131+
$this->configuration['values'],
132+
$this->configuration['values.']
133+
);
107134
}
108135

109136
/**
@@ -115,7 +142,7 @@ protected function getValues(): string
115142
*/
116143
protected function isEnabled(): bool
117144
{
118-
return $this->contentObject->cObjGetSingle(
145+
return $this->contentObjectLocal->cObjGetSingle(
119146
$this->configuration['_enable'],
120147
$this->configuration['_enable.']
121148
) === '1' && $this->isFormSubmitted();
@@ -129,21 +156,10 @@ protected function isEnabled(): bool
129156
*/
130157
public function initializeFinisher(): void
131158
{
132-
// @extensionScannerIgnoreLine Seems to be a false positive: getContentObject() is still correct in 9.0
133-
$this->contentObject = $this->configurationManager->getContentObject();
134159
$mailRepository = ObjectUtility::getObjectManager()->get(MailRepository::class);
135-
$this->contentObject->start($mailRepository->getVariablesWithMarkersFromMail($this->mail));
160+
$this->contentObjectLocal->start($mailRepository->getVariablesWithMarkersFromMail($this->mail));
136161
$configurationService = ObjectUtility::getObjectManager()->get(ConfigurationService::class);
137162
$configuration = $configurationService->getTypoScriptConfiguration();
138163
$this->configuration = $configuration['marketing.']['sendPost.'];
139164
}
140-
141-
/**
142-
* @param ConfigurationManagerInterface $configurationManager
143-
* @return void
144-
*/
145-
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
146-
{
147-
$this->configurationManager = $configurationManager;
148-
}
149165
}

Configuration/Services.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ services:
77
In2code\Powermail\:
88
resource: '../Classes/*'
99

10-
# Commands
11-
1210
In2code\Powermail\Command\CleanupExportsCommand:
1311
tags:
1412
- name: 'console.command'

0 commit comments

Comments
 (0)