-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Language: Migrations to use parent ISO code + self ID for new sub lan…
…guages - refs BT#21568
- Loading branch information
Showing
5 changed files
with
144 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
src/CoreBundle/Migrations/Schema/V200/Version20250106152600.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; | ||
|
||
use Chamilo\CoreBundle\DataFixtures\LanguageFixtures; | ||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; | ||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
final class Version20250106152600 extends AbstractMigrationChamilo | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Set parent as null for initial lenguages.'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$languageNameList = array_column( | ||
LanguageFixtures::getLanguages(), | ||
'english_name', | ||
); | ||
|
||
$this->addSql( | ||
'UPDATE language SET parent_id = NULL WHERE english_name IN ("'.implode('", "', $languageNameList).'")' | ||
); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/CoreBundle/Migrations/Schema/V200/Version20250106152601.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; | ||
|
||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
final class Version20250106152601 extends AbstractMigrationChamilo | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Set new ISO code for sub-languages.'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$kernel = $this->container->get('kernel'); | ||
$baseTranslationPath = $kernel->getProjectDir().'/var/translations/messages.'; | ||
|
||
$fs = new Filesystem(); | ||
|
||
$subLanguages = $this->connection | ||
->executeQuery("SELECT id, isocode, parent_id FROM language WHERE parent_id IS NOT NULL") | ||
->fetchAllAssociative() | ||
; | ||
|
||
/** @var array $subLanguage */ | ||
foreach ($subLanguages as $subLanguage) { | ||
|
||
$parentIsoCode = $this->connection | ||
->executeQuery('SELECT isocode FROM language WHERE id = ?', [$subLanguage['parent_id']]) | ||
->fetchOne() | ||
; | ||
|
||
$newIsoCode = sprintf( | ||
'%s_%d', | ||
explode('_', $parentIsoCode)[0], | ||
$subLanguage['id'] | ||
); | ||
|
||
$params = [ | ||
'new_iso' => $newIsoCode, | ||
'old_iso' => $subLanguage['isocode'], | ||
]; | ||
|
||
if ($params['new_iso'] === $params['old_iso']) { | ||
continue; | ||
} | ||
|
||
$this->addSql( | ||
'UPDATE language SET isocode = :new_iso WHERE id = :id', | ||
[ | ||
'new_iso' => $newIsoCode, | ||
'id' => $subLanguage['id'], | ||
] | ||
); | ||
|
||
$this->addSql('UPDATE user SET locale = :new_iso WHERE locale = :old_iso', $params); | ||
$this->addSql('UPDATE course SET course_language = :new_iso WHERE course_language = :old_iso', $params); | ||
$this->addSql("UPDATE settings SET selected_value = :new_iso WHERE variable = 'platform_language' AND selected_value = :old_iso", $params); | ||
|
||
$oldPoFile = $baseTranslationPath.$params['old_iso'].'.po'; | ||
$newPoFile = $baseTranslationPath.$params['new_iso'].'.po'; | ||
|
||
if ($fs->exists($oldPoFile)) { | ||
$fs->rename($oldPoFile, $newPoFile); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/CoreBundle/Migrations/Schema/V200/Version20250106152602.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; | ||
|
||
use Chamilo\CoreBundle\Entity\Language; | ||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; | ||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
final class Version20250106152602 extends AbstractMigrationChamilo | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Change iso code length to 8 characters.'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE language CHANGE isocode isocode VARCHAR('.Language::ISO_MAX_LENGTH.') NOT NULL'); | ||
} | ||
} |