ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDBUpdateEA.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/Database/classes/class.ilDBUpdate.php";
5 
13 class ilDBUpdateEA extends ilDBUpdate
14 {
17 
21  function hotfixAvailable()
22  {
23  $hotfixavailable = parent::hotfixAvailable();
24 
25  $this->readHotfixInfoEA();
26  if ($hotfixavailable || $this->hotfix_file_version_ea > $this->hotfix_current_version_ea)
27  {
28  return true;
29  }
30  return false;
31  }
32 
37  {
38  $this->readHotfixInfoEA();
40  }
41 
45  function setHotfixCurrentVersionEA($a_version)
46  {
47  $this->readHotfixInfoEA();
48  $this->hotfix_setting->set("db_hotfixes_ea", $a_version);
49  $this->hotfix_current_version = $a_version;
50  return true;
51  }
52 
57  {
58  $this->readHotfixInfoEA();
60  }
61 
65  function readHotfixInfoEA($a_force = false)
66  {
67  if ($this->hotfix_info_read_ea && !$a_force)
68  {
69  return;
70  }
71  include_once './Services/Administration/classes/class.ilSetting.php';
72  $GLOBALS["ilDB"] = $this->db;
73  $this->hotfix_setting_ea = new ilSetting();
74  $hotfix_file = $this->PATH."setup/sql/ilias_ea_dbfixes.php";
75  if (is_file($hotfix_file))
76  {
77  $this->hotfix_content_ea = @file($hotfix_file);
78  $this->hotfix_current_version_ea = (int) $this->hotfix_setting_ea->get("db_hotfixes_ea");
79  $this->hotfix_file_version_ea = $this->readHotfixFileVersion($this->hotfix_content_ea);
80  }
81  $this->hotfix_info_read_ea = true;
82  }
83 
90  function applyUpdateEANr($nr)
91  {
92  global $ilDB,$ilErr,$ilUser,$ilCtrlStructureReader,$ilModuleReader,$ilMySQLAbstraction;
93 
94  //search for desired $nr
95  reset($this->filecontent);
96 
97  //init
98  $i = 0;
99 
100  //go through filecontent
101  while (!ereg("^<#".$nr.">", $this->filecontent[$i]) && $i<count($this->filecontent))
102  {
103  $i++;
104  }
105 
106  //update not found
107  if ($i == count($this->filecontent))
108  {
109  $this->error = "update_not_found";
110  return false;
111  }
112 
113  $i++;
114 
115  //update found, now extract this update to a new array
116  $update = array();
117  while ($i<count($this->filecontent) && !ereg("^<#".($nr+1).">", $this->filecontent[$i]))
118  {
119  $update[] = trim($this->filecontent[$i]);
120  $i++;
121  }
122 
123  //now you have the update, now process it
124  $sql = array();
125  $php = array();
126  $mode = "sql";
127 
128  foreach ($update as $row)
129  {
130  if (ereg("<\?php", $row))
131  {
132  if (count($sql)>0)
133  {
134  if ($this->execQuery($this->db, implode("\n", $sql)) == false)
135  {
136  $this->error = $this->error;
137  return false;
138  }
139  $sql = array();
140  }
141  $mode = "php";
142  }
143  elseif (ereg("\?>", $row))
144  {
145  if (count($php)>0)
146  {
147  $code = implode("\n", $php);
148  eval($code);
149  $php = array();
150  }
151  $mode = "sql";
152 
153  }
154  else
155  {
156  if ($mode == "sql")
157  {
158  $sql[] = $row;
159  }
160 
161  if ($mode == "php")
162  {
163  $php[] = $row;
164  }
165  } //else
166  } //foreach
167 
168  if ($mode == "sql" && count($sql) > 0)
169  {
170  if ($this->execQuery($this->db, implode("\n", $sql)) == false)
171  {
172  $this->error = "dump_error: ".$this->error;
173  return false;
174  }
175  }
176 
177  $this->setHotfixCurrentVersionEA($nr);
178 
179  return true;
180 
181  }
182 
184  {
185  if ($this->getHotfixCurrentVersion() > 0 || $this->getHotfixCurrentVersionEA() > 0)
186  {
187  return sprintf("ILIAS: %d / EA: %d", $this->getHotfixCurrentVersion(), $this->getHotfixCurrentVersionEA());
188  }
189  else
190  {
191  return "";
192  }
193  }
194 
196  {
197  if ($this->getHotfixFileVersion() > 0 || $this->getHotfixFileVersionEA() > 0)
198  {
199  return sprintf("ILIAS: %d / EA: %d", $this->getHotfixFileVersion(), $this->getHotfixFileVersionEA());
200  }
201  else
202  {
203  return "";
204  }
205  }
206 
210  function applyHotfix()
211  {
213 
214  global $ilCtrlStructureReader, $ilMySQLAbstraction;
215 
216  include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
217 
218  $ilMySQLAbstraction = new ilMySQLAbstraction();
219  $GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
220 
221  $this->readHotfixInfoEA(true);
222 
223  $f = $this->getHotfixFileVersionEA();
224  $c = $this->getHotfixCurrentVersionEA();
225 
226  if ($c < $f)
227  {
228  $msg = array();
229  for ($i=($c+1); $i<=$f; $i++)
230  {
231  $this->filecontent = $this->hotfix_content_ea;
232  if ($this->applyUpdateEANr($i) == false)
233  {
234  $msg[] = array(
235  "msg" => "update_error: ".$this->error,
236  "nr" => $i
237  );
238  $this->updateMsg = $msg;
239  return false;
240  }
241  else
242  {
243  $msg[] = array(
244  "msg" => "hotfix_applied",
245  "nr" => $i
246  );
247  }
248  }
249 
250  $this->updateMsg = $msg;
251  }
252  else
253  {
254  $this->updateMsg = "no_changes";
255  }
256 
257  return $this->loadXMLInfo();
258  }
259 }