Skip to content

Commit

Permalink
fixed updater and runonce
Browse files Browse the repository at this point in the history
  • Loading branch information
iCodr8 committed Jan 30, 2018
1 parent 618e936 commit fefc691
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Resources/contao/config/runonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
*/

$updater = new Craffft\AccountmailBundle\Util\Updater();
$updater->addTranslationFieldTableAndFields();
$updater->addDefaultEmailContents();
44 changes: 34 additions & 10 deletions src/Util/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,45 @@
namespace Craffft\AccountmailBundle\Util;

use Contao\ClassLoader;
use Contao\Config;
use Contao\Controller;
use Contao\Database;
use Contao\System;
use TranslationFields\TranslationFieldsModel;

class Updater extends Controller
class Updater
{
public function __construct()
/**
* Add translation field database table and fields if the are not existing already
*/
public function addTranslationFieldTableAndFields()
{
parent::__construct();

$this->import('Config');
$db = Database::getInstance();

if (!$db->tableExists('tl_translation_fields')) {
$sql = trim("
CREATE TABLE `tl_translation_fields` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tstamp` int(10) unsigned NOT NULL DEFAULT '0',
`fid` int(10) unsigned NOT NULL DEFAULT '0',
`language` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `fid_language` (`fid`,`language`),
KEY `fid` (`fid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
");
$db->execute($sql);
}
}

/**
* Add default email contents to the configuration fields of the accountmail extension
*/
public function addDefaultEmailContents()
{
$this->addContentToField('emailFrom', $this->Config->get('adminEmail'));
$config = Config::getInstance();
$this->addContentToField('emailFrom', $config->get('adminEmail'));
$this->addContentToField('emailNewMemberTemplate', 'mail_default');
$this->addContentToField('emailChangedMemberPasswordTemplate', 'mail_default');
$this->addContentToField('emailNewUserTemplate', 'mail_default');
Expand All @@ -47,8 +67,10 @@ public function addDefaultEmailContents()
*/
protected function addContentToField($strField, $strValue)
{
if ($this->Config->get($strField) === null) {
$this->Config->persist($strField, $strValue);
$config = Config::getInstance();

if ($config->get($strField) === null) {
$config->persist($strField, $strValue);
}
}

Expand All @@ -73,7 +95,9 @@ protected function getFieldNames()
*/
protected function addTranslationContentToField($strField)
{
if ($this->Config->get($strField) === null) {
$config = Config::getInstance();

if ($config->get($strField) === null) {
$arrValues = array();

System::loadLanguageFile('tl_email', 'de', true);
Expand All @@ -94,7 +118,7 @@ protected function addTranslationContentToField($strField)
// Load translation file by current language
System::loadLanguageFile('tl_email', null, true);

$this->Config->persist(
$config->persist(
$strField,
TranslationFieldsModel::saveValuesAndReturnFid($arrValues)
);
Expand Down

0 comments on commit fefc691

Please sign in to comment.