|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
10
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
11
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
12
|
|
|
|
|
13
|
|
|
class Version20250328161000 extends AbstractMigrationChamilo |
|
14
|
|
|
{ |
|
15
|
|
|
public function getDescription(): string |
|
16
|
|
|
{ |
|
17
|
|
|
return 'Migrate ext_translations.locale to new ISO code format for sublanguages'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function up(Schema $schema): void |
|
21
|
|
|
{ |
|
22
|
|
|
$sublanguages = $this->connection |
|
23
|
|
|
->executeQuery( |
|
24
|
|
|
"SELECT * FROM language |
|
25
|
|
|
WHERE parent_id IS NOT NULL AND isocode NOT IN('".implode("', '", Version20::ALLOWED_SUBLANGUAGES)."')" |
|
26
|
|
|
) |
|
27
|
|
|
->fetchAllAssociative() |
|
28
|
|
|
; |
|
29
|
|
|
|
|
30
|
|
|
$filesystem = new Filesystem(); |
|
31
|
|
|
$projectDir = $this->container->get('kernel')->getProjectDir(); |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** @var array $sublanguage */ |
|
34
|
|
|
foreach ($sublanguages as $sublanguage) { |
|
35
|
|
|
$newIsoCode = $this->getNewIsoCode($sublanguage); |
|
36
|
|
|
|
|
37
|
|
|
// Update the isocode in the language table |
|
38
|
|
|
$this->connection->executeStatement( |
|
39
|
|
|
'UPDATE ext_translations SET locale = ? WHERE locale = ?', |
|
40
|
|
|
[$newIsoCode, $sublanguage['isocode']] |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
// Rename old PO file |
|
44
|
|
|
$filesystem->rename( |
|
45
|
|
|
$projectDir.'/var/translations/messages.'.$sublanguage['isocode'].'.po', |
|
46
|
|
|
$projectDir.'/var/translations/messages.'.$newIsoCode.'.po' |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function getNewIsoCode(array $sublanguage) |
|
52
|
|
|
{ |
|
53
|
|
|
$parentId = $sublanguage['parent_id']; |
|
54
|
|
|
|
|
55
|
|
|
// Query to obtain the isocode of the parent language |
|
56
|
|
|
$parentIsoCode = $this->connection |
|
57
|
|
|
->executeQuery('SELECT isocode FROM language WHERE id = ?', [$parentId]) |
|
58
|
|
|
->fetchOne() |
|
59
|
|
|
; |
|
60
|
|
|
|
|
61
|
|
|
// Get the prefix of the parent language's isocode |
|
62
|
|
|
$firstIso = explode('_', $parentIsoCode)[0]; |
|
63
|
|
|
|
|
64
|
|
|
return $firstIso.'_'.$sublanguage['id']; |
|
65
|
|
|
} |
|
66
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.