Files
kupshop/bundles/KupShop/ContentBundle/Resources/upgrade/RegistrationEmailUpgrade.php
2025-08-02 16:30:27 +02:00

77 lines
2.5 KiB
PHP

<?php
namespace KupShop\ContentBundle\Resources\upgrade;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Email\UserRegisterEmail;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\KupShopBundle\Util\System\PathFinder;
class RegistrationEmailUpgrade extends \UpgradeNew
{
protected $priority = 200;
public function check_RegistrationEmailUpgrade()
{
return !$this->selectSQL('emails', ['type' => UserRegisterEmail::getType()], ['id'])->fetchColumn();
}
/** Move Registration email to database */
public function upgrade_RegistrationEmailUpgrade()
{
$languageContext = ServiceContainer::getService(LanguageContext::class);
// nejdriv default language, abych ho tam mel ulozeny jako prvni
$content = $this->getEmailContent($languageContext->getDefaultId());
$this->insertSQL(
'emails',
[
'type' => UserRegisterEmail::getType(),
'body' => $content,
'subject' => translate('RegConfirm', 'login'),
'name' => '',
]
);
$objectID = sqlInsertId();
// pak ostatni languages
if (findModule(\Modules::TRANSLATIONS)) {
foreach ($languageContext->getSupported() as $language) {
$content = $this->getEmailContent($language->getId());
if ($languageContext->translationActive()) {
$this->insertSQL('emails_translations', [
'id_email' => $objectID,
'id_language' => $language->getId(),
'id_admin' => null,
'subject' => translate('RegConfirm', 'login'),
'body' => $content,
]);
}
}
}
$this->upgradeOK();
}
private function getEmailContent($language)
{
global $cfg;
$languageContext = ServiceContainer::getService(LanguageContext::class);
$languageContext->activate($language);
// HACK musim zalohovat a vracet config, protoze smarty mi smaze Connection host, password, user, ktery potom
// chybi testum
$cfgBackup = clone $cfg;
$smarty = createSmarty();
$cfg = $cfgBackup;
$smarty->assign(['email' => '{EMAIL_UZIVATELE}']);
$content = $smarty->fetch(PathFinder::getService()->getAdminDir().'/templates/email/email_user_register.tpl');
return $content;
}
}