-
Notifications
You must be signed in to change notification settings - Fork 6
/
export_translations.php
54 lines (41 loc) · 1.79 KB
/
export_translations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
use blackscorp\logd\Translate\{Translations, TranslationsEntity, TranslationsRepository};
require_once __DIR__.'/vendor/autoload.php';
require_once 'dbconnect.php';
$dsn = 'mysql:dbname='.$DB_NAME.';host=.'.$DB_HOST.';charset=utf8';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
];
$pdo = new \PDO($dsn, $DB_USER, $DB_PASS, $options);
$translationsRepository = new TranslationsRepository($pdo);
$handle = fopen('translations_german.sql', "w");
fwrite($handle, "START TRANSACTION;\n");
fwrite($handle, "DROP TABLE IF EXISTS `translations`;\n");
fwrite($handle, "CREATE TABLE `translations` (
`tid` int(11) NOT NULL,
`language` varchar(10) NOT NULL,
`uri` varchar(255) NOT NULL,
`intext` blob NOT NULL,
`outtext` blob NOT NULL,
`author` varchar(50) DEFAULT NULL,
`version` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n");
fwrite($handle, "ALTER TABLE `translations`
ADD PRIMARY KEY (`tid`),
ADD KEY `language` (`language`,`uri`),
ADD KEY `uri` (`uri`);
\n");
fwrite($handle, "ALTER TABLE `translations`
MODIFY `tid` int(11) NOT NULL AUTO_INCREMENT;\n");
$allTranslations = $translationsRepository->findAll();
foreach ($allTranslations as $translations) {
$data = "INSERT INTO `translations` (`language`, `uri`, `intext`, `outtext`, `author`, `version`) "
. "VALUES ( "
. "'".$translations->getLanguage()."', '".$translations->getNamespace()."', 0x".bin2hex($translations->getIntext()).", 0x".bin2hex($translations->getOuttext()).", '".$translations->getAuthor()."', '".$translations->getVersion()."');\n";
fwrite($handle, $data);
}
fwrite($handle, "COMMIT;\n");
?>
<a href="translated_data.php">Daten überschrieben - zurück</a>