ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPluginDBUpdate.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 {
17  function ilPluginDBUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname,
18  $a_db_handler, $tmp_flag, $a_db_prefix)
19  {
20  $this->db_prefix = $a_db_prefix;
21 
22  // workaround to allow setup migration
23  if ($a_db_handler)
24  {
25  $this->db =& $a_db_handler;
26 
27  if ($tmp_flag)
28  {
29  $this->PATH = "./";
30  }
31  else
32  {
33  $this->PATH = "../";
34  }
35  }
36  else
37  {
38  global $mySetup;
39  $this->db = $mySetup->db;
40  $this->PATH = "./";
41  }
42 
43  $this->ctype = $a_ctype;
44  $this->cname = $a_cname;
45  $this->slot_id = $a_slot_id;
46  $this->pname = $a_pname;
47 
48  include_once("./Services/Component/classes/class.ilPluginSlot.php");
49  $this->slot_name = ilPluginSlot::lookupSlotName($this->ctype,
50  $this->cname, $this->slot_id);
51 
52  $this->getCurrentVersion();
53 
54  // get update file for current version
55  $updatefile = $this->getFileForStep($this->currentVersion + 1);
56 
57  $this->current_file = $updatefile;
58  $this->DB_UPDATE_FILE = $this->PATH.
59  ilPlugin::getDBUpdateScriptName($this->ctype, $this->cname,
60  $this->slot_name, $this->pname);
61 
62  //
63  // NOTE: multiple update files for plugins are not supported yet
64  //
65  $this->LAST_UPDATE_FILE = $this->PATH.
66  ilPlugin::getDBUpdateScriptName($this->ctype, $this->cname,
67  $this->slot_name, $this->pname);
68 
69  $this->readDBUpdateFile();
70  $this->readLastUpdateFile();
71  $this->readFileVersion();
72  }
73 
77  function getFileForStep($a_version)
78  {
79  return "dbupdate.php";
80  }
81 
87  function _DBUpdate()
88  {
89  // this may be used in setup!?
90 // $this->db->disconnect();
91  }
92 
96  function getCurrentVersion()
97  {
98  $q = "SELECT db_version FROM il_plugin ".
99  " WHERE component_type = ".$this->db->quote($this->ctype, "text").
100  " AND component_name = ".$this->db->quote($this->cname, "text").
101  " AND slot_id = ".$this->db->quote($this->slot_id, "text").
102  " AND name = ".$this->db->quote($this->pname, "text");
103  $set = $this->db->query($q);
104  $rec = $this->db->fetchAssoc($set);
105 
106  $this->currentVersion = (int) $rec["db_version"];
107 
108  return $this->currentVersion;
109  }
110 
114  function setCurrentVersion($a_version)
115  {
116  $q = "UPDATE il_plugin SET db_version = ".$this->db->quote((int) $a_version, "integer").
117  " WHERE component_type = ".$this->db->quote($this->ctype, "text").
118  " AND component_name = ".$this->db->quote($this->cname, "text").
119  " AND slot_id = ".$this->db->quote($this->slot_id, "text").
120  " AND name = ".$this->db->quote($this->pname, "text");
121  $this->db->manipulate($q);
122  $this->currentVersion = $a_version;
123  return true;
124  }
125 
126  function loadXMLInfo()
127  {
128  // to do: reload control structure information for plugin
129  return true;
130  }
131 
135  function checkQuery($q)
136  {
137  if ((is_int(stripos($q, "create table")) || is_int(stripos($q, "alter table")) ||
138  is_int(stripos($q, "drop table")))
139  && !is_int(stripos($q, $this->db_prefix)))
140  {
141  return "Plugin may only create or alter tables that use prefix ".
142  $this->db_prefix;
143  }
144  else
145  {
146  return true;
147  }
148  }
149 
150 
151 } // END class.DBUdate
152 ?>