Skip to content

Commit

Permalink
[framework] added missing migration to create admin reset password ma…
Browse files Browse the repository at this point in the history
…il template (#3654)
  • Loading branch information
grossmannmartin authored Dec 17, 2024
1 parent 92961cf commit c7e3e87
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Migrations/Version20241212064226.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\FrameworkBundle\Component\Translation\Translator;
use Shopsys\FrameworkBundle\Model\Administrator\Mail\ResetPasswordMail;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class Version20241212064226 extends AbstractMigration implements ContainerAwareInterface
{
use MultidomainMigrationTrait;

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$this->createMailTemplateIfNotExist(ResetPasswordMail::MAIL_TEMPLATE_NAME);

foreach ($this->getAllDomainIds() as $domainId) {
$domainLocale = $this->getDomainLocale($domainId);

$this->updateMailTemplate(
ResetPasswordMail::MAIL_TEMPLATE_NAME,
t('Administrator reset password request', [], Translator::DATA_FIXTURES_TRANSLATION_DOMAIN, $domainLocale),
t('Dear administrator.<br /><br />'
. 'You can set a new password following this link: <a href="{new_password_url}">{new_password_url}</a>', [], Translator::DATA_FIXTURES_TRANSLATION_DOMAIN, $domainLocale),
$domainId,
);
}
}

/**
* @param string $mailTemplateName
*/
private function createMailTemplateIfNotExist(
string $mailTemplateName,
): void {
foreach ($this->getAllDomainIds() as $domainId) {
$mailTemplateCount = $this->sql(
'SELECT count(*) FROM mail_templates WHERE name = :mailTemplateName and domain_id = :domainId',
[
'mailTemplateName' => $mailTemplateName,
'domainId' => $domainId,
],
)->fetchOne();

if ($mailTemplateCount !== 0) {
continue;
}

$this->sql(
'INSERT INTO mail_templates (name, domain_id, send_mail) VALUES (:mailTemplateName, :domainId, :sendMail)',
[
'mailTemplateName' => $mailTemplateName,
'domainId' => $domainId,
'sendMail' => true,
],
);
}
}

/**
* @param string $mailTemplateName
* @param string $subject
* @param string $body
* @param int $domainId
*/
private function updateMailTemplate(string $mailTemplateName, string $subject, string $body, int $domainId): void
{
$this->sql(
'UPDATE mail_templates SET subject = :subject, body = :body WHERE name = :mailTemplateName AND domain_id = :domainId',
[
'subject' => $subject,
'body' => $body,
'mailTemplateName' => $mailTemplateName,
'domainId' => $domainId,
],
);
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
6 changes: 6 additions & 0 deletions src/Resources/translations/dataFixtures.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ msgstr "<p> Platba pro objednávku číslo {number} proběhla úspěšně. <br /
msgid "<p> Payment for order number {number} has failed. <br /><br /> Please contact us to resolve the issue. </p>"
msgstr "<p> Platba pro objednávku číslo {number} nebyla úspěšná. <br /><br /> Prosím kontaktujte nás pro vyřešení problému. </p>"

msgid "Administrator reset password request"
msgstr "Požadavek na resetování hesla administrátora"

msgid "Dear administrator.<br /><br />You can set a new password following this link: <a href=\"{new_password_url}\">{new_password_url}</a>"
msgstr "Vážený administrátore.<br /><br />Můžete nastavit nové heslo následujícím odkazem: <a href=\"{new_password_url}\">{new_password_url}</a>"

msgid "New product inquiry received"
msgstr "Byla přijata nová poptávka produktu"

Expand Down
6 changes: 6 additions & 0 deletions src/Resources/translations/dataFixtures.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ msgstr ""
msgid "<p> Payment for order number {number} has failed. <br /><br /> Please contact us to resolve the issue. </p>"
msgstr ""

msgid "Administrator reset password request"
msgstr ""

msgid "Dear administrator.<br /><br />You can set a new password following this link: <a href=\"{new_password_url}\">{new_password_url}</a>"
msgstr ""

msgid "New product inquiry received"
msgstr ""

Expand Down

0 comments on commit c7e3e87

Please sign in to comment.