19 declare(strict_types=1);
32 public function __construct(
ilDBInterface $ilDB,
string $key, array $content, array $local_changes,
string $scope =
"",
string $separator =
"#:#",
string $comment_separator =
"###")
39 if ($scope ===
"local") {
41 ->format(
'Y-m-d H:i:s');
50 $lang_array = array();
51 $lang_array[
"common"] = array();
55 $query =
"INSERT INTO lng_data (module,identifier,lang_key,value,local_change,remarks) VALUES ";
56 foreach ($this->content as $val) {
62 $separated = explode($this->separator, trim($val));
63 $pos = strpos($separated[2], $this->comment_separator);
65 $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
66 $separated[2] = substr($separated[2], 0, $pos);
70 $local_value = $this->local_changes[$separated[0]][$separated[1]] ??
"";
72 if (empty($this->scope)) {
74 if ($local_value !==
"" && $local_value !== $separated[2]) {
76 $lang_array[$separated[0]][$separated[1]] = $local_value;
79 } elseif ($this->scope ===
"local") {
81 if ($local_value !==
"") {
83 $lang_array[$separated[0]][$separated[1]] = $local_value;
87 if ($double_checker[$separated[0]][$separated[1]][$this->key] ??
false) {
89 $DIC->ui()->mainTemplate()->setOnScreenMessage(
91 "Duplicate Language Entry in $lang_file:\n$val",
94 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
96 $double_checker[$separated[0]][$separated[1]][
$this->key] =
true;
99 "(%s,%s,%s,%s,%s,%s),",
100 $this->ilDB->quote($separated[0],
"text"),
101 $this->ilDB->quote($separated[1],
"text"),
102 $this->ilDB->quote($this->key,
"text"),
103 $this->ilDB->quote($separated[2],
"text"),
104 $this->ilDB->quote($this->change_date,
"timestamp"),
105 $this->ilDB->quote($separated[3] ??
null,
"text")
108 $lang_array[$separated[0]][$separated[1]] = $separated[2];
110 $query = rtrim($query,
",") .
" ON DUPLICATE KEY UPDATE value=VALUES(value),local_change=VALUES(local_change),remarks=VALUES(remarks);";
112 $this->ilDB->manipulate($query);
123 $query =
"INSERT INTO lng_modules (module, lang_key, lang_array) VALUES ";
124 $modules_to_delete = [];
125 foreach ($lang_array as $module => $lang_arr) {
126 if ($this->scope ===
"local") {
127 $q =
"SELECT * FROM lng_modules WHERE " .
128 " lang_key = " . $this->ilDB->quote($this->key,
"text") .
129 " AND module = " . $this->ilDB->quote($module,
"text");
130 $set = $this->ilDB->query(
$q);
131 $row = $this->ilDB->fetchAssoc($set);
132 $arr2 = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
133 if (is_array($arr2)) {
134 $lang_arr = array_merge($arr2, $lang_arr);
139 $this->ilDB->quote($module,
"text"),
140 $this->ilDB->quote($this->key,
"text"),
141 $this->ilDB->quote(serialize($lang_arr),
"clob"),
143 $modules_to_delete[] = $module;
146 $inModulesToDelete = $this->ilDB->in(
'module', $modules_to_delete,
false,
'text');
147 $this->ilDB->manipulate(sprintf(
148 "DELETE FROM lng_modules WHERE lang_key = %s AND $inModulesToDelete",
149 $this->ilDB->quote($this->key,
"text")
152 $query = rtrim($query,
",") .
";";
153 $this->ilDB->manipulate($query);
162 $result = $this->ilDB->queryF(
163 "SELECT module, lang_array FROM lng_modules WHERE lang_key = %s",
168 foreach ($this->ilDB->fetchAll($result) as $module) {
169 $unserialied = unserialize($module[
"lang_array"], [
"allowed_classes" =>
false]);
170 if (!is_array($unserialied)) {
172 $DIC->ui()->mainTemplate()->setOnScreenMessage(
174 "Data for module '" . $module[
"module"] .
"' of language '" . $this->key .
"' is not correctly saved. " .
175 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
178 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
string $comment_separator
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
replaceLangModules(array $lang_array)
insertLangEntries(string $lang_file)
__construct(ilDBInterface $ilDB, string $key, array $content, array $local_changes, string $scope="", string $separator="#:#", string $comment_separator="###")