Skip to content
Snippets Groups Projects
Commit 66b1b0e3 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[TASK] Cleanup

parent 6d57b9b6
No related branches found
No related tags found
No related merge requests found
<?php <?php
namespace SGalinski\SgCookieOptin\Controller;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
* *
...@@ -26,6 +24,8 @@ namespace SGalinski\SgCookieOptin\Controller; ...@@ -26,6 +24,8 @@ namespace SGalinski\SgCookieOptin\Controller;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
namespace SGalinski\SgCookieOptin\Controller;
use DirectoryIterator; use DirectoryIterator;
use Exception; use Exception;
use SGalinski\SgCookieOptin\Exception\JsonImportException; use SGalinski\SgCookieOptin\Exception\JsonImportException;
...@@ -194,7 +194,9 @@ class OptinController extends ActionController { ...@@ -194,7 +194,9 @@ class OptinController extends ActionController {
if ($languageUid > 0) { if ($languageUid > 0) {
foreach ($cookies as &$cookie) { foreach ($cookies as &$cookie) {
$cookie = $pageRepository->getRecordOverlay('tx_sgcookieoptin_domain_model_cookie', $cookie, $languageUid); $cookie = $pageRepository->getRecordOverlay(
'tx_sgcookieoptin_domain_model_cookie', $cookie, $languageUid
);
} }
} }
$group['cookies'] = $cookies; $group['cookies'] = $cookies;
...@@ -211,7 +213,6 @@ class OptinController extends ActionController { ...@@ -211,7 +213,6 @@ class OptinController extends ActionController {
$view->setPartialRootPaths(['EXT:sg_cookie_optin/Resources/Private/Partials']); $view->setPartialRootPaths(['EXT:sg_cookie_optin/Resources/Private/Partials']);
$view->setLayoutRootPaths(['EXT:sg_cookie_optin/Resources/Private/Layouts']); $view->setLayoutRootPaths(['EXT:sg_cookie_optin/Resources/Private/Layouts']);
$view->assign('groups', $groups); $view->assign('groups', $groups);
$view->assign('optin', $optin); $view->assign('optin', $optin);
$view->assign('headline', $this->settings['headline'] ?? ''); $view->assign('headline', $this->settings['headline'] ?? '');
......
<?php <?php
namespace SGalinski\SgCookieOptin\Service;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
* *
...@@ -26,6 +24,9 @@ namespace SGalinski\SgCookieOptin\Service; ...@@ -26,6 +24,9 @@ namespace SGalinski\SgCookieOptin\Service;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
namespace SGalinski\SgCookieOptin\Service;
use Doctrine\DBAL\DBALException;
use SGalinski\SgCookieOptin\Exception\JsonImportException; use SGalinski\SgCookieOptin\Exception\JsonImportException;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
...@@ -62,6 +63,7 @@ class JsonImportService { ...@@ -62,6 +63,7 @@ class JsonImportService {
* *
* @param int $pid * @param int $pid
* @return \Doctrine\DBAL\Driver\Statement|int * @return \Doctrine\DBAL\Driver\Statement|int
* @throws DBALException
*/ */
public static function getDataForExport(int $pid) { public static function getDataForExport(int $pid) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable( $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(
...@@ -85,6 +87,7 @@ class JsonImportService { ...@@ -85,6 +87,7 @@ class JsonImportService {
* @param null|int $sysLanguageUid * @param null|int $sysLanguageUid
* @param null|int $defaultLanguageOptinId * @param null|int $defaultLanguageOptinId
* @return string * @return string
* @throws DBALException
*/ */
public function importJsonData($jsonData, $pid, $sysLanguageUid = NULL, $defaultLanguageOptinId = NULL) { public function importJsonData($jsonData, $pid, $sysLanguageUid = NULL, $defaultLanguageOptinId = NULL) {
// extract group data into other variables so that we can import all the settings information with little to no // extract group data into other variables so that we can import all the settings information with little to no
...@@ -98,30 +101,24 @@ class JsonImportService { ...@@ -98,30 +101,24 @@ class JsonImportService {
$footerLinks = []; $footerLinks = [];
} }
unset($jsonData['cookieGroups']); unset($jsonData['cookieGroups'], $jsonData['iFrameGroup'], $jsonData['footerLinks'], $jsonData['mustacheData']);
unset($jsonData['iFrameGroup']);
unset($jsonData['footerLinks']);
unset($jsonData['mustacheData']);
// flatten the data into one array to prepare it for SQL // flatten the data into one array to prepare it for SQL
$flatJsonData = []; $flatJsonData = [];
array_walk_recursive( array_walk_recursive(
$jsonData, $jsonData,
function ($value, $key) use (&$flatJsonData) { static function ($value, $key) use (&$flatJsonData) {
$flatJsonData[$key] = $value; $flatJsonData[$key] = $value;
} }
); );
// add required system data and remove junk from the JSON // add required system data and remove junk from the JSON
unset($flatJsonData['markup']); unset($flatJsonData['markup'], $flatJsonData['identifier'], $flatJsonData['save_history_webhook']);
unset($flatJsonData['identifier']);
unset($flatJsonData['save_history_webhook']);
$flatJsonData['pid'] = $pid; $flatJsonData['pid'] = $pid;
$flatJsonData['crdate'] = $GLOBALS['EXEC_TIME']; $flatJsonData['crdate'] = $GLOBALS['EXEC_TIME'];
$flatJsonData['tstamp'] = $GLOBALS['EXEC_TIME']; $flatJsonData['tstamp'] = $GLOBALS['EXEC_TIME'];
$flatJsonData['cruser_id'] = $GLOBALS['BE_USER']->user[$GLOBALS['BE_USER']->userid_column]; $flatJsonData['cruser_id'] = $GLOBALS['BE_USER']->user[$GLOBALS['BE_USER']->userid_column];
$flatJsonData['navigation'] = $this->buildNavigationFromFooterLinks($footerLinks); $flatJsonData['navigation'] = $this->buildNavigationFromFooterLinks($footerLinks);
// essential_description
$flatJsonData['essential_title'] = $cookieGroups[0]['label']; $flatJsonData['essential_title'] = $cookieGroups[0]['label'];
$flatJsonData['essential_description'] = $cookieGroups[0]['description']; $flatJsonData['essential_description'] = $cookieGroups[0]['description'];
$flatJsonData['iframe_title'] = $iframeGroup['label']; $flatJsonData['iframe_title'] = $iframeGroup['label'];
...@@ -137,44 +134,44 @@ class JsonImportService { ...@@ -137,44 +134,44 @@ class JsonImportService {
$connectionPool, $connectionPool,
'tx_sgcookieoptin_domain_model_optin', 'tx_sgcookieoptin_domain_model_optin',
[ [
'pid', 'pid',
'description', 'description',
'template_html', 'template_html',
'banner_html', 'banner_html',
'banner_description', 'banner_description',
'essential_description', 'essential_description',
'iframe_description', 'iframe_description',
'iframe_html', 'iframe_html',
'iframe_replacement_html', 'iframe_replacement_html',
'iframe_whitelist_regex', 'iframe_whitelist_regex',
'iframe_button_load_one_description', 'iframe_button_load_one_description',
'cookiebanner_whitelist_regex', 'cookiebanner_whitelist_regex',
'domains_to_delete_cookies_for', 'domains_to_delete_cookies_for',
'overwrite_baseurl', 'overwrite_baseurl',
'accept_all_text', 'accept_all_text',
'accept_specific_text', 'accept_specific_text',
'accept_essential_text', 'accept_essential_text',
'extend_box_link_text', 'extend_box_link_text',
'extend_box_link_text_close', 'extend_box_link_text_close',
'extend_table_link_text', 'extend_table_link_text',
'extend_table_link_text_close', 'extend_table_link_text_close',
'cookie_name_text', 'cookie_name_text',
'cookie_provider_text', 'cookie_provider_text',
'cookie_purpose_text', 'cookie_purpose_text',
'cookie_lifetime_text', 'cookie_lifetime_text',
'save_confirmation_text', 'save_confirmation_text',
'user_hash_text', 'user_hash_text',
'banner_button_accept_text', 'banner_button_accept_text',
'banner_button_settings_text', 'banner_button_settings_text',
'essential_title', 'essential_title',
'iframe_title', 'iframe_title',
'iframe_button_allow_all_text', 'iframe_button_allow_all_text',
'iframe_button_allow_one_text', 'iframe_button_allow_one_text',
'iframe_button_load_one_text', 'iframe_button_load_one_text',
'iframe_open_settings_text', 'iframe_open_settings_text',
'iframe_replacement_background_image' 'iframe_replacement_background_image'
], ],
$flatJsonData $flatJsonData
); );
...@@ -197,10 +194,11 @@ class JsonImportService { ...@@ -197,10 +194,11 @@ class JsonImportService {
$this->defaultLanguageIdMappingLookup['services'][$serviceIndex] = $serviceId; $this->defaultLanguageIdMappingLookup['services'][$serviceIndex] = $serviceId;
} }
$serviceIndex++; ++$serviceIndex;
} }
// Add Groups // Add Groups
$groupIndex = 0;
foreach ($cookieGroups as $groupIndex => $group) { foreach ($cookieGroups as $groupIndex => $group) {
$this->addGroupWithCookiesAndScripts( $this->addGroupWithCookiesAndScripts(
$groupIndex, $group, $pid, $optInId, $sysLanguageUid, $defaultLanguageOptinId, $connectionPool $groupIndex, $group, $pid, $optInId, $sysLanguageUid, $defaultLanguageOptinId, $connectionPool
...@@ -218,7 +216,7 @@ class JsonImportService { ...@@ -218,7 +216,7 @@ class JsonImportService {
} }
/** /**
* Builds the navigation CSV string from the footerlinks * Builds the navigation CSV string from the footer links
* *
* @param array $footerLinks * @param array $footerLinks
* @return string * @return string
...@@ -243,7 +241,8 @@ class JsonImportService { ...@@ -243,7 +241,8 @@ class JsonImportService {
* @param int|null $sysLanguageUid * @param int|null $sysLanguageUid
* @param int|null $defaultLanguageOptinId * @param int|null $defaultLanguageOptinId
* @param ConnectionPool $connectionPool * @param ConnectionPool $connectionPool
* @return mixed * @return string
* @throws DBALException
*/ */
protected function addGroup( protected function addGroup(
$pid, $pid,
...@@ -292,6 +291,7 @@ class JsonImportService { ...@@ -292,6 +291,7 @@ class JsonImportService {
* @param int $defaultLanguageOptinId * @param int $defaultLanguageOptinId
* @param ConnectionPool $connectionPool * @param ConnectionPool $connectionPool
* @return string * @return string
* @throws DBALException
*/ */
protected function addCookie( protected function addCookie(
$pid, $pid,
...@@ -336,14 +336,14 @@ class JsonImportService { ...@@ -336,14 +336,14 @@ class JsonImportService {
$connectionPool, $connectionPool,
'tx_sgcookieoptin_domain_model_cookie', 'tx_sgcookieoptin_domain_model_cookie',
[ [
'pid', 'purpose' 'pid', 'purpose'
], ],
$cookieData $cookieData
); );
} }
/** /**
* Inserts a data set in the table with it's initial values (that don't have default) and then updates all the rest * Inserts a data set in the table with its initial values (that don't have default) and then updates all the rest
* one by one to, ignoring Exceptions if a JSON field is missing in the database * one by one to, ignoring Exceptions if a JSON field is missing in the database
* *
* @param ConnectionPool $connectionPool * @param ConnectionPool $connectionPool
...@@ -351,7 +351,7 @@ class JsonImportService { ...@@ -351,7 +351,7 @@ class JsonImportService {
* @param array $initialDataKeys * @param array $initialDataKeys
* @param array $data * @param array $data
* @return string * @return string
* @throws \Doctrine\DBAL\DBALException * @throws DBALException
*/ */
protected function flexInsert( protected function flexInsert(
ConnectionPool $connectionPool, ConnectionPool $connectionPool,
...@@ -403,6 +403,7 @@ class JsonImportService { ...@@ -403,6 +403,7 @@ class JsonImportService {
* @param string $groupIdentifier * @param string $groupIdentifier
* @param ConnectionPool $connectionPool * @param ConnectionPool $connectionPool
* @return string * @return string
* @throws DBALException
*/ */
protected function addScript( protected function addScript(
$pid, $pid,
...@@ -442,8 +443,8 @@ class JsonImportService { ...@@ -442,8 +443,8 @@ class JsonImportService {
$connectionPool, $connectionPool,
'tx_sgcookieoptin_domain_model_script', 'tx_sgcookieoptin_domain_model_script',
[ [
'pid', 'html', 'script' 'pid', 'html', 'script'
], ],
$scriptData $scriptData
); );
} }
...@@ -457,9 +458,9 @@ class JsonImportService { ...@@ -457,9 +458,9 @@ class JsonImportService {
* @param int $optInId * @param int $optInId
* @param int|null $sysLanguageUid * @param int|null $sysLanguageUid
* @param int|null $defaultLanguageOptinId * @param int|null $defaultLanguageOptinId
* @param string $groupIdentifier
* @param ConnectionPool $connectionPool * @param ConnectionPool $connectionPool
* @return string * @return string
* @throws DBALException
*/ */
protected function addService( protected function addService(
$pid, $pid,
...@@ -492,8 +493,9 @@ class JsonImportService { ...@@ -492,8 +493,9 @@ class JsonImportService {
$connectionPool, $connectionPool,
'tx_sgcookieoptin_domain_model_service', 'tx_sgcookieoptin_domain_model_service',
[ [
'pid', 'identifier', 'replacement_html_overwritten', 'replacement_html', 'replacement_background_image', 'source_regex' 'pid', 'identifier', 'replacement_html_overwritten', 'replacement_html',
], 'replacement_background_image', 'source_regex'
],
$serviceData $serviceData
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment