Last active
July 12, 2016 15:36
-
-
Save dmitryd/7ae4b447b2db0899429dc04d54f20640 to your computer and use it in GitHub Desktop.
Fix Powermail convertor for records with sys_language_uid>0 and l18n_parent=0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DmitryDulepov\PowermailConversionFix\Xclass; | |
/*************************************************************** | |
* Copyright notice | |
* | |
* (c) 2016 Dmity Dulepov <[email protected]> | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
***************************************************************/ | |
use In2code\Powermail\Domain\Model\Form; | |
use In2code\Powermail\Utility\BackendUtility; | |
use In2code\Powermail\Utility\ObjectUtility; | |
use In2code\Powermail\Utility\TemplateUtility; | |
/** | |
* There is a bug in the EXT:powermail that creates corrupted forms when converting from | |
* v1 to v2 if sys_language_uid>0 but l18n_mode=0 (separate localization for content | |
* elements). This XCLASS solves the issue. | |
*/ | |
class FormConverterService extends \In2code\Powermail\Domain\Service\FormConverterService { | |
/** | |
* Create Form Record | |
* | |
* @param array $form | |
* @param int $formCounter | |
* @return int $formUid | |
*/ | |
protected function createFormRecord($form, $formCounter) | |
{ | |
$formProperties = [ | |
'uid' => 0, | |
'pid' => | |
($this->configuration['save'] === '[samePage]' ? $form['pid'] : (int) $this->configuration['save']), | |
'title' => $form['tx_powermail_title'], | |
'pages' => $form['tx_powermail_fieldsets'], | |
'cruser_id' => BackendUtility::getPropertyFromBackendUser(), | |
'hidden' => $form['hidden'], | |
'crdate' => time(), | |
'tstamp' => time() | |
]; | |
// Fix is on the line below | |
if ($form['sys_language_uid'] > 0 && isset($this->localizationRelations['form'][$form['l18n_parent']])) { | |
$formProperties['sys_language_uid'] = $form['sys_language_uid']; | |
$formProperties['l10n_parent'] = (int) $this->localizationRelations['form'][$form['l18n_parent']]; | |
} | |
if (!$this->isDryrun()) { | |
ObjectUtility::getDatabaseConnection()->exec_INSERTquery(Form::TABLE_NAME, $formProperties); | |
$formProperties['uid'] = ObjectUtility::getDatabaseConnection()->sql_insert_id(); | |
$this->localizationRelations['form'][$form['uid']] = $formProperties['uid']; | |
} | |
$this->result[$formCounter] = $formProperties; | |
// create pages | |
$pageCounter = 0; | |
foreach ((array) $form['_fieldsets'] as $page) { | |
$this->createPageRecord($form, $page, $formProperties['uid'], $formCounter, $pageCounter); | |
$pageCounter++; | |
} | |
return $formProperties['uid']; | |
} | |
/** | |
* Create FlexForm | |
* | |
* @param array $form | |
* @param int $formUid Form that was created before | |
* @return string | |
*/ | |
protected function createFlexForm($form, $formUid) | |
{ | |
$form['tx_powermail_thanks'] = $this->rewriteVariables($form['tx_powermail_thanks'], $form, true); | |
$form['tx_powermail_mailsender'] = $this->rewriteVariables($form['tx_powermail_mailsender'], $form, true); | |
$form['tx_powermail_mailreceiver'] = $this->rewriteVariables($form['tx_powermail_mailreceiver'], $form, true); | |
$form['tx_powermail_recipient'] = $this->rewriteVariables($form['tx_powermail_recipient'], $form); | |
$form['tx_powermail_subject_r'] = $this->rewriteVariables($form['tx_powermail_subject_r'], $form); | |
$form['tx_powermail_subject_s'] = $this->rewriteVariables($form['tx_powermail_subject_s'], $form); | |
// Fix is on the line below | |
if ($form['sys_language_uid'] > 0 && isset($this->localizationRelations['form'][$form['l18n_parent']])) { | |
$formUid = (int) $this->localizationRelations['form'][$form['l18n_parent']]; | |
} | |
$standaloneView = TemplateUtility::getDefaultStandAloneView(); | |
$standaloneView->getRequest()->setControllerName('Module'); | |
$standaloneView->setTemplatePathAndFilename(TemplateUtility::getTemplatePath('Module/ConverterFlexForm.xml')); | |
$standaloneView->assignMultiple( | |
[ | |
'formUid' => $formUid, | |
'form' => $form, | |
'configuration' => $this->configuration | |
] | |
); | |
return $standaloneView->render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment