ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjLanguageDBAccess Class Reference
+ Collaboration diagram for ilObjLanguageDBAccess:

Public Member Functions

 __construct (ilDBInterface $ilDB, string $key, array $content, array $local_changes, string $scope="", string $separator="#:#", string $comment_separator="###")
 
 insertLangEntries (string $lang_file)
 
 replaceLangModules (array $lang_array)
 

Protected Member Functions

 checkModules ()
 

Protected Attributes

ilDBInterface $ilDB
 
string $key
 
array $content
 
string $scope
 
array $local_changes
 
string $change_date = null
 
string $separator
 
string $comment_separator
 

Detailed Description

Definition at line 21 of file class.ilObjLanguageDBAccess.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjLanguageDBAccess::__construct ( ilDBInterface  $ilDB,
string  $key,
array  $content,
array  $local_changes,
string  $scope = "",
string  $separator = "#:#",
string  $comment_separator = "###" 
)

Definition at line 32 of file class.ilObjLanguageDBAccess.php.

References $comment_separator, $content, $ilDB, $key, $local_changes, $scope, and $separator.

32  :#", string $comment_separator = "###")
33  {
34  $this->ilDB = $ilDB;
35  $this->key = $key;
36  $this->content = $content;
37  $this->local_changes = $local_changes;
38  $this->scope = $scope;
39  if ($scope === "local") {
40  $this->change_date = date("Y-m-d H:i:s", time());
41  }
42  $this->separator = $separator;
43  $this->comment_separator = $comment_separator;
44  }

Member Function Documentation

◆ checkModules()

ilObjLanguageDBAccess::checkModules ( )
protected

Definition at line 157 of file class.ilObjLanguageDBAccess.php.

References $DIC.

Referenced by replaceLangModules().

157  : void
158  {
159  $result = $this->ilDB->queryF(
160  "SELECT module, lang_array FROM lng_modules WHERE lang_key = %s",
161  array("text"),
162  array($this->key)
163  );
164 
165  foreach ($this->ilDB->fetchAll($result) as $module) {
166  $unserialied = unserialize($module["lang_array"], ["allowed_classes" => false]);
167  if (!is_array($unserialied)) {
168  global $DIC;
169  $DIC->ui()->mainTemplate()->setOnScreenMessage(
170  'failure',
171  "Data for module '" . $module["module"] . "' of language '" . $this->key . "' is not correctly saved. " .
172  "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
173  true);
174  $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class, 'view');
175  }
176  }
177  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ insertLangEntries()

ilObjLanguageDBAccess::insertLangEntries ( string  $lang_file)

Definition at line 46 of file class.ilObjLanguageDBAccess.php.

References $DIC, $key, and null.

46  : array
47  {
48  // initialize the array for updating lng_modules below
49  $lang_array = array();
50  $lang_array["common"] = array();
51 
52  $double_checker = [];
53  $query_check = false;
54  $query = "INSERT INTO lng_data (module,identifier,lang_key,value,local_change,remarks) VALUES ";
55  foreach ($this->content as $val) {
56  // split the line of the language file
57  // [0]: module
58  // [1]: identifier
59  // [2]: value
60  // [3]: comment (optional)
61  $separated = explode($this->separator, trim($val));
62  $pos = strpos($separated[2], $this->comment_separator);
63  if ($pos !== false) {
64  $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
65  $separated[2] = substr($separated[2], 0, $pos);
66  }
67 
68  // check if the value has a local change
69  $local_value = $this->local_changes[$separated[0]][$separated[1]] ?? "";
70 
71  if (empty($this->scope)) {
72  // import of a global language file
73  if ($local_value !== "" && $local_value !== $separated[2]) {
74  // keep an existing and different local value
75  $lang_array[$separated[0]][$separated[1]] = $local_value;
76  continue;
77  }
78  } elseif ($this->scope === "local") {
79  // import of a local language file
80  if ($local_value !== "") {
81  // keep a locally changed value that is newer than the file
82  $lang_array[$separated[0]][$separated[1]] = $local_value;
83  continue;
84  }
85  }
86  if ($double_checker[$separated[0]][$separated[1]][$this->key] ?? false) {
87  global $DIC;
88  $DIC->ui()->mainTemplate()->setOnScreenMessage(
89  'failure',
90  "Duplicate Language Entry in $lang_file:\n$val",
91  true);
92  $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class, 'view');
93  }
94  $double_checker[$separated[0]][$separated[1]][$this->key] = true;
95 
96  $query .= sprintf(
97  "(%s,%s,%s,%s,%s,%s),",
98  $this->ilDB->quote($separated[0], "text"),
99  $this->ilDB->quote($separated[1], "text"),
100  $this->ilDB->quote($this->key, "text"),
101  $this->ilDB->quote($separated[2], "text"),
102  $this->ilDB->quote($this->change_date, "timestamp"),
103  $this->ilDB->quote($separated[3] ?? null, "text")
104  );
105  $query_check = true;
106  $lang_array[$separated[0]][$separated[1]] = $separated[2];
107  }
108  $query = rtrim($query, ",") . " ON DUPLICATE KEY UPDATE value=VALUES(value),local_change=VALUES(local_change),remarks=VALUES(remarks);";
109  if ($query_check) {
110  $this->ilDB->manipulate($query);
111  }
112 
113  return $lang_array;
114  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22

◆ replaceLangModules()

ilObjLanguageDBAccess::replaceLangModules ( array  $lang_array)

Definition at line 116 of file class.ilObjLanguageDBAccess.php.

References $q, checkModules(), and ilCachedLanguage\getInstance().

116  : void
117  {
118  // avoid flushing the whole cache (see mantis #28818)
119  ilCachedLanguage::getInstance($this->key)->deleteInCache();
120 
121  $query = "INSERT INTO lng_modules (module, lang_key, lang_array) VALUES ";
122  $modules_to_delete = [];
123  foreach ($lang_array as $module => $lang_arr) {
124  if ($this->scope === "local") {
125  $q = "SELECT * FROM lng_modules WHERE " .
126  " lang_key = " . $this->ilDB->quote($this->key, "text") .
127  " AND module = " . $this->ilDB->quote($module, "text");
128  $set = $this->ilDB->query($q);
129  $row = $this->ilDB->fetchAssoc($set);
130  $arr2 = unserialize($row["lang_array"], ["allowed_classes" => false]);
131  if (is_array($arr2)) {
132  $lang_arr = array_merge($arr2, $lang_arr);
133  }
134  }
135  $query .= sprintf(
136  "(%s,%s,%s),",
137  $this->ilDB->quote($module, "text"),
138  $this->ilDB->quote($this->key, "text"),
139  $this->ilDB->quote(serialize($lang_arr), "clob"),
140  );
141  $modules_to_delete[] = $module;
142  }
143 
144  $inModulesToDelete = $this->ilDB->in('module', $modules_to_delete, false, 'text');
145  $this->ilDB->manipulate(sprintf("DELETE FROM lng_modules WHERE lang_key = %s AND $inModulesToDelete",
146  $this->ilDB->quote($this->key, "text")
147  ));
148 
149  $query = rtrim($query, ",") . ";";
150  $this->ilDB->manipulate($query);
151 
152  // check if the module is correctly saved
153  // see mantis #20046 and #19140
154  $this->checkModules();
155  }
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:

Field Documentation

◆ $change_date

string ilObjLanguageDBAccess::$change_date = null
protected

Definition at line 28 of file class.ilObjLanguageDBAccess.php.

◆ $comment_separator

string ilObjLanguageDBAccess::$comment_separator
protected

Definition at line 30 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().

◆ $content

array ilObjLanguageDBAccess::$content
protected

Definition at line 25 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().

◆ $ilDB

ilDBInterface ilObjLanguageDBAccess::$ilDB
protected

Definition at line 23 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().

◆ $key

string ilObjLanguageDBAccess::$key
protected

Definition at line 24 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct(), and insertLangEntries().

◆ $local_changes

array ilObjLanguageDBAccess::$local_changes
protected

Definition at line 27 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().

◆ $scope

string ilObjLanguageDBAccess::$scope
protected

Definition at line 26 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().

◆ $separator

string ilObjLanguageDBAccess::$separator
protected

Definition at line 29 of file class.ilObjLanguageDBAccess.php.

Referenced by __construct().


The documentation for this class was generated from the following file: