Skip to content

Commit

Permalink
[framework] tweak complaint status migration (#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav authored Sep 14, 2024
1 parent b7a132e commit bf511fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
63 changes: 30 additions & 33 deletions src/Migrations/Version20240816221930.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\FrameworkBundle\Component\Translation\Translator;
use Shopsys\FrameworkBundle\Model\Complaint\Status\ComplaintStatusTypeEnum;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class Version20240816221930 extends AbstractMigration
class Version20240816221930 extends AbstractMigration implements ContainerAwareInterface
{
use MultidomainMigrationTrait;

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
Expand All @@ -33,18 +37,13 @@ public function up(Schema $schema): void
ADD
CONSTRAINT FK_BBBBB6722C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES complaint_statuses (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');

$this->createComplaintStatusWithEnglishAndCzechTranslations(
1,
ComplaintStatusTypeEnum::STATUS_TYPE_NEW,
'New',
'Nová',
);
$this->createComplaintStatusWithEnglishAndCzechTranslations(
2,
'resolved',
'Resolved',
'Vyřízena',
);
$this->createComplaintStatus(1, ComplaintStatusTypeEnum::STATUS_TYPE_NEW);
$this->createComplaintStatus(2, ComplaintStatusTypeEnum::STATUS_TYPE_RESOLVED);

foreach ($this->getAllLocales() as $locale) {
$this->createComplaintStatusTranslations(1, t('New', [], Translator::DEFAULT_TRANSLATION_DOMAIN, $locale), $locale);
$this->createComplaintStatusTranslations(2, t('Resolved', [], Translator::DEFAULT_TRANSLATION_DOMAIN, $locale), $locale);
}

$this->sql('ALTER SEQUENCE complaint_statuses_id_seq RESTART WITH 3');

Expand All @@ -65,34 +64,32 @@ public function up(Schema $schema): void

/**
* @param int $complaintStatusId
* @param string $complaintStatus
* @param string $complaintStatusEnglishName
* @param string $complaintStatusCzechName
* @param string $complaintStatusType
*/
private function createComplaintStatusWithEnglishAndCzechTranslations(
int $complaintStatusId,
string $complaintStatus,
string $complaintStatusEnglishName,
string $complaintStatusCzechName,
): void {
private function createComplaintStatus(int $complaintStatusId, string $complaintStatusType): void
{
$this->sql('INSERT INTO complaint_statuses (id, status_type) VALUES (:id, :statusType)', [
'id' => $complaintStatusId,
'statusType' => $complaintStatus,
'statusType' => $complaintStatusType,
]);
}

/**
* @param int $complaintStatusId
* @param string $complaintStatusTranslatedName
* @param string $locale
*/
private function createComplaintStatusTranslations(
int $complaintStatusId,
string $complaintStatusTranslatedName,
string $locale,
): void {
$this->sql(
'INSERT INTO complaint_status_translations (translatable_id, name, locale) VALUES (:translatableId, :name, :locale)',
[
'translatableId' => $complaintStatusId,
'name' => $complaintStatusEnglishName,
'locale' => 'en',
],
);
$this->sql(
'INSERT INTO complaint_status_translations (translatable_id, name, locale) VALUES (:translatableId, :name, :locale)',
[
'translatableId' => $complaintStatusId,
'name' => $complaintStatusCzechName,
'locale' => 'cs',
'name' => $complaintStatusTranslatedName,
'locale' => $locale,
],
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/translations/messages.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,9 @@ msgstr "Byla upravena položka navigace <strong><a href=\"{{ url }}\">{{ name }}
msgid "Navigation item <strong>{{ name }}</strong> has been removed"
msgstr "Položka navigace <strong>{{ name }}</strong> byla odebrána"

msgid "New"
msgstr "Nová"

msgid "New SEO page"
msgstr "Nová SEO stránka"

Expand Down Expand Up @@ -3049,6 +3052,9 @@ msgstr "Zrušit filtr"
msgid "Reset password request was sent to <strong>{{ email }}</strong>"
msgstr "Žádost o resetování hesla byla odeslána na adresu <strong>{{ email }}</strong>"

msgid "Resolved"
msgstr "Vyřízena"

msgid "Return back"
msgstr "Vrátit zpět"

Expand Down
6 changes: 6 additions & 0 deletions src/Resources/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,9 @@ msgstr ""
msgid "Navigation item <strong>{{ name }}</strong> has been removed"
msgstr ""

msgid "New"
msgstr ""

msgid "New SEO page"
msgstr ""

Expand Down Expand Up @@ -3049,6 +3052,9 @@ msgstr ""
msgid "Reset password request was sent to <strong>{{ email }}</strong>"
msgstr ""

msgid "Resolved"
msgstr ""

msgid "Return back"
msgstr ""

Expand Down

0 comments on commit bf511fe

Please sign in to comment.