This repository was archived by the owner on Jul 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtools.php
More file actions
100 lines (88 loc) · 4.04 KB
/
Copy pathtools.php
File metadata and controls
100 lines (88 loc) · 4.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once('vendor/autoload.php');
session_start();
$core = new \Quantum\Core();
if(!array_key_exists('type', $_GET)) {
echo '<a href="tools.php?type=import">Import languages</a><br />';
echo '<a href="tools.php?type=export">Export languages</a><br />';
echo '<a href="tools.php?type=importPrivileges">Import privileges</a><br />';
echo '<a href="tools.php?type=exampleData">Generate Example Data</a><br />';
} else {
if($_GET['type'] == 'import') {
// Step 1: Read all files in install/languages
$dir = ROOT_DIR . 'install' . DS . 'languages' . DS;
$internal = $core->getInternalDatabase()->getEntityManager();
$translationsRepo = $internal->getRepository('Quantum\\DBO\\Translation');
if($handle = opendir($dir)) {
while(false !== ($entry = readdir($handle))) {
if($entry != '.' && $entry != '..') {
// Step 2: Import
echo 'Import ' . $entry . '<br />';
$lang = explode('.', $entry)[0];
$lang = strtoupper($lang);
$keys = parse_ini_file($dir . $entry);
foreach($keys as $key => $translated) {
$translation = $translationsRepo->findOneBy(
array("trans" => $key, "lang" => $lang)
);
if($translation == null) {
$translation = new \Quantum\DBO\Translation($key, $lang, utf8_encode($translated));
}
$translation->setTranslated($translated);
$internal->persist($translation);
}
}
}
}
$internal->flush();
echo 'Done';
} else if($_GET['type'] == 'export') {
$dir = ROOT_DIR . 'install' . DS . 'languages' . DS;
$internal = $core->getInternalDatabase()->getEntityManager();
$translationsRepo = $internal->getRepository('Quantum\\DBO\\Translation');
$handles = array();
/** @var $translation \Quantum\DBO\Translation */
foreach($translationsRepo->findAll() as $translation) {
$lang = $translation->getLang();
if(!array_key_exists($lang, $handles)) {
$handles[$lang] = fopen($dir . $lang . '.ini', 'w+');
}
fwrite($handles[$lang], $translation->getTrans() . ' = "' . $translation->getTranslated() . '"' . PHP_EOL);
}
foreach($handles as $handle) {
fclose($handle);
}
echo 'Done';
} else if($_GET['type'] == 'importPrivileges') {
$data = json_decode(file_get_contents(ROOT_DIR . 'install' . DS . 'privileges' . DS . 'privileges.json'));
$privileges = $data->{'Privileges'};
$em = $core->getInternalDatabase()->getEntityManager();
foreach($privileges as $privilege) {
// Check if database entry exists
$tmp = $em->getRepository('\\Quantum\\DBO\\Privilege')->findOneBy(array(
'technicalName' => $privilege->{'TechnicalName'}
));
if($tmp === null) {
$tmp = new \Quantum\DBO\Privilege();
$tmp->setTechnicalName($privilege->{'TechnicalName'});
}
$tmp->setName($privilege->{'Name'});
$tmp->setCategory($privilege->{'Category'});
$tmp->setDescription($privilege->{'Description'});
$em->persist($tmp);
}
$em->flush();
echo 'Done';
} else if($_GET['type'] == 'exampleData') {
$coreStatuses = array();
$coreStatuses[] = new \Quantum\DBO\CoreStatus("MySQL", '127.0.0.1', 3306, false, time());
for($i = 1; $i <= 8; $i++) {
$coreStatuses[] = new \Quantum\DBO\CoreStatus("Channel " . $i, '127.0.0.1', 79 + $i, false, time());
}
$internal = $core->getInternalDatabase()->getEntityManager();
foreach($coreStatuses as $coreStatus) {
$internal->persist($coreStatus);
}
$internal->flush();
}
}