Skip to content

Commit

Permalink
Version 6.3.4: additional fields in tt_address
Browse files Browse the repository at this point in the history
  • Loading branch information
bihor committed Jan 15, 2024
1 parent a2993e1 commit e3e85ae
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 31 deletions.
12 changes: 9 additions & 3 deletions Classes/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,13 @@ public function updateAction(Log $log): ResponseInterface
$salutation = $this->helpersUtility->getSalutation(intval($log->getGender()), $this->settings['gender']);
if ($dbuidext) {
if ($table == 'tt_address') {
$this->logRepository->updateInTtAddress($log, intval($this->settings['html']), $dbuidext, $salutation);
$this->logRepository->updateInTtAddress(
$log, intval($this->settings['html']), $dbuidext, $salutation, $this->settings['additionalTtAddressFields']
);
} elseif ($table == 'fe_users') {
$this->logRepository->updateInFeUsers($log, $dbuidext, $this->settings['newsletterExtension']);
$this->logRepository->updateInFeUsers(
$log, $dbuidext, $this->settings['newsletterExtension']
);
}
} else {
$error = 1;
Expand Down Expand Up @@ -1136,7 +1140,9 @@ public function verifyAction(): ResponseInterface
$dmCatArr = [];
}
if ($this->settings['table'] == 'tt_address') {
$success = $this->logRepository->insertInTtAddress($log, $html, $dmCatArr, $salutation);
$success = $this->logRepository->insertInTtAddress(
$log, $html, $dmCatArr, $salutation, $this->settings['additionalTtAddressFields']
);
} else if ($this->settings['table'] == 'fe_users' && $this->settings['password']) {
$frontendUser = new \Fixpunkt\FpNewsletter\Domain\Model\FrontendUser();
$password = $this->settings['password'];
Expand Down
86 changes: 63 additions & 23 deletions Classes/Domain/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,60 @@ function getByEmailAndPid(string $email, array $pids, int $sys_language_uid, int
}

/**
* getUidFromExternal: find user ID
* @param string $email die E-Mail-Adresse wurde schon vorher geprüft!
* @param mixed $pid PID oder Liste mit PIDs
* @param string $table tt_address oder fe_users
* @return integer
* getAllFields: find additional fields
* @param int $uid UID
* @return array
*/
function getUidFromExternal($email, $pid, $table)
function getAllFields($uid)
{
$dbuid = 0;
$table = 'tx_fpnewsletter_domain_model_log';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
if (is_numeric($pid)) {
$where = $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT));
} else {
$where = $queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pid, Connection::PARAM_INT_ARRAY));
}
$statement = $queryBuilder
->select('uid')
->select('*')
->from($table)
->where(
$where
)
->andWhere(
$queryBuilder->expr()->eq('email', $queryBuilder->createNamedParameter($email))
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->executeQuery();
while ($row = $statement->fetchAssociative()) {
$dbuid = intval($row['uid']);
break;
}
return $dbuid;
return $row;
}
return [];
}

/**
* getUidFromExternal: find user ID
* @param string $email die E-Mail-Adresse wurde schon vorher geprüft!
* @param mixed $pid PID oder Liste mit PIDs
* @param string $table tt_address oder fe_users
* @return integer
*/
function getUidFromExternal($email, $pid, $table)
{
$dbuid = 0;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
if (is_numeric($pid)) {
$where = $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT));
} else {
$where = $queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pid, Connection::PARAM_INT_ARRAY));
}
$statement = $queryBuilder
->select('uid')
->from($table)
->where(
$where
)
->andWhere(
$queryBuilder->expr()->eq('email', $queryBuilder->createNamedParameter($email))
)
->executeQuery();
while ($row = $statement->fetchAssociative()) {
$dbuid = intval($row['uid']);
break;
}
return $dbuid;
}

/**
* getExternalUid: found user in tt_address or fe_users
* @param string $dbemail E-Mail
Expand Down Expand Up @@ -234,8 +256,9 @@ function deleteInMm($tableUid, $table = 'tt_address')
* @param integer $mode HTML-mode
* @param array $dmCatArr categories
* @param string $salutation Anrede
* @param string $additionalFields weitere extern zugefügte Felder
*/
function insertInTtAddress($address, $mode, $dmCatArr = [], $salutation = '')
function insertInTtAddress($address, $mode, $dmCatArr = [], $salutation = '', $additionalFields = '')
{
$timestamp = time();
if ($address->getGender() == 1) $gender = 'f';
Expand Down Expand Up @@ -280,6 +303,14 @@ function insertInTtAddress($address, $mode, $dmCatArr = [], $salutation = '')
if ($gender) {
$insert['gender'] = $gender;
}
if ($additionalFields) {
// um zusätzliche Felder befüllen zu können, wird ein Array statt ein Objekt gebraucht
$addressArray = $this->getAllFields($address->getUid());
$additionalArray = explode(',', $additionalFields);
foreach ($additionalArray as $customField) {
$insert[trim($customField)] = $addressArray[trim($customField)];
}
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_address');
$queryBuilder
->insert('tt_address')
Expand All @@ -298,8 +329,9 @@ function insertInTtAddress($address, $mode, $dmCatArr = [], $salutation = '')
* @param integer $mode HTML-mode
* @param int $tableUid externe uid
* @param string $salutation Anrede
* @param string $additionalFields weitere extern zugefügte Felder
*/
function updateInTtAddress($address, $mode, $tableUid, $salutation = '')
function updateInTtAddress($address, $mode, $tableUid, $salutation = '', $additionalFields)
{
$timestamp = time();
if ($address->getGender() == 1) $gender = 'f';
Expand Down Expand Up @@ -342,6 +374,14 @@ function updateInTtAddress($address, $mode, $tableUid, $salutation = '')
->set('mail_salutation', $salutation)
->set('mail_active', 1);
}
if ($additionalFields) {
// um zusätzliche Felder befüllen zu können, wird ein Array statt ein Objekt gebraucht
$addressArray = $this->getAllFields($address->getUid());
$additionalArray = explode(',', $additionalFields);
foreach ($additionalArray as $customField) {
$queryBuilder->set(trim($customField), $addressArray[trim($customField)]);
}
}
$queryBuilder->executeStatement();
$this->deleteInMm($tableUid, 'tt_address');
$this->insertIntoMm($tableUid, $dmCatArr, 'tt_address');
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugin.tx_fpnewsletter {
newsletterExtension =
optionalFields = gender,firstname,lastname
optionalFieldsRequired =
additionalTtAddressFields =
doubleOptOut = 1
disableErrorMsg = 0
enableUnsubscribeForm = 0
Expand Down
16 changes: 16 additions & 0 deletions Documentation/Administrator/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ this extension::
}


.. _admin-additional-fields:

Adding additional fields to tt_address
--------------------------------------

If you want to add additional fields to tt_address, they must be already present in the log-table
(tx_fpnewsletter_domain_model_log) and in the tt_address-table.
If they are not present, then you must add the fields to both tables via an own
extension in your ext_tables.sql file. Example: you want to add the field "gdpr" to tt_address.
This field is already part of the log-table. You need to add it only to the tt_address-table by your own.
Then you must specify which additional fields should be copied from the log-table to the tt_address-table via TypoScript::

plugin.tx_fpnewsletter.settings.additionalTtAddressFields = gdpr

That's all.

.. _admin-security:

Security-notice to version 3.2.6
Expand Down
5 changes: 4 additions & 1 deletion Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,7 @@ Version 6.3.1:
- Bugfix: Luxletter is now the default newsletter-extension - to prevent a PHP warning.

Version 6.3.2:
- Bugfix: reCAPTCHA fixed.
- Bugfix: reCAPTCHA fixed.

Version 6.4.0:
- Additional fields can now be copied from the log-entry to the tt_address-table. Setting additionalTtAddressFields added.
16 changes: 16 additions & 0 deletions Documentation/Localization.de_DE/Administrator/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ benutzt werden kann::
}


.. _admin-additional-fields:

Weitere Felder zu tt_address hinzufügen
---------------------------------------

Wenn du weitere Felder zu tt_address hinzufügen möchtest, dann müssen diese Felder sowohl in der Log-Tabelle
(tx_fpnewsletter_domain_model_log) als auch in der tt_address-Tabelle vorhanden sein.
Wenn sie noch nicht da sind, müssen sie in einer Extension in der Datei ext_tables.sql hinzugefügt werden.
Beispiel: du willst das Feld "gdpr" nach tt_address kopieren.
Dieses Feld ist in der Log-Tabelle bereits vorhanden und deshalb muss es nur noch zur tt_address-Tabelle von dir
hinzugefügt werden. Danach muss man noch per TypoScript angeben, welche zusätzlichen Felder mit kopiert werden soll::

plugin.tx_fpnewsletter.settings.additionalTtAddressFields = gdpr

Das ist alles.

.. _admin-security:

Sicherheitshinweis zu Version 3.2.6
Expand Down
5 changes: 4 additions & 1 deletion Documentation/Localization.de_DE/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ Version 6.3.1:
- Bugfix: Luxletter ist nun die Standard Newsletter-Extension - um eine PHP-Warnung zu verhindern.

Version 6.3.2:
- Bugfix: reCAPTCHA repariert.
- Bugfix: reCAPTCHA repariert.

Version 6.4.0:
- Zusätzliche Felder können nun aus dem Log-Eintrag in eine tt_address-Tabelle kopiert werden. Setting additionalTtAddressFields hinzugefügt.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fp_newsletter

version 6.3.2
version 6.4.0

The TYPO3 extension fp_newsletter is designed to provide a newsletter subscription and unsubscription service for the
table tt_address which can be used by the extension mail OR for the table fe_users which can be used by luxletter or mail.
Expand Down Expand Up @@ -38,4 +38,7 @@ Version 6.3.1:
- Bugfix: Luxletter is now the default newsletter-extension - to prevent a PHP warning.

Version 6.3.2:
- Bugfix: reCAPTCHA fixed.
- Bugfix: reCAPTCHA fixed.

Version 6.4.0:
- Additional fields can now be copied from the log-entry to the tt_address-table. Setting additionalTtAddressFields added.
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'author_company' => 'fixpunkt für digitales GmbH',
'state' => 'stable',
'clearCacheOnLoad' => 0,
'version' => '6.3.2',
'version' => '6.4.0',
'constraints' => [
'depends' => [
'typo3' => '11.5.0-12.4.99'
Expand Down

0 comments on commit e3e85ae

Please sign in to comment.