ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPluginDBUpdate.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./classes/class.ilDBUpdate.php");
25 
33 {
37  function ilPluginDBUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname,
38  $a_db_handler, $tmp_flag, $a_db_prefix)
39  {
40  $this->db_prefix = $a_db_prefix;
41 
42  // workaround to allow setup migration
43  if ($a_db_handler)
44  {
45  $this->db =& $a_db_handler;
46 
47  if ($tmp_flag)
48  {
49  $this->PATH = "./";
50  }
51  else
52  {
53  $this->PATH = "../";
54  }
55  }
56  else
57  {
58  global $mySetup;
59  $this->db = $mySetup->db;
60  $this->PATH = "./";
61  }
62 
63  $this->ctype = $a_ctype;
64  $this->cname = $a_cname;
65  $this->slot_id = $a_slot_id;
66  $this->pname = $a_pname;
67 
68  include_once("./Services/Component/classes/class.ilPluginSlot.php");
69  $this->slot_name = ilPluginSlot::lookupSlotName($this->ctype,
70  $this->cname, $this->slot_id);
71 
72  $this->getCurrentVersion();
73 
74  // get update file for current version
75  $updatefile = $this->getFileForStep($this->currentVersion + 1);
76 
77  $this->current_file = $updatefile;
78  $this->DB_UPDATE_FILE = $this->PATH.
79  ilPlugin::getDBUpdateScriptName($this->ctype, $this->cname,
80  $this->slot_name, $this->pname);
81 
82  //
83  // NOTE: multiple update files for plugins are not supported yet
84  //
85  $this->LAST_UPDATE_FILE = $this->PATH.
86  ilPlugin::getDBUpdateScriptName($this->ctype, $this->cname,
87  $this->slot_name, $this->pname);
88 
89  $this->readDBUpdateFile();
90  $this->readLastUpdateFile();
91  $this->readFileVersion();
92  }
93 
97  function getFileForStep($a_version)
98  {
99  return "dbupdate.php";
100  }
101 
107  function _DBUpdate()
108  {
109  // this may be used in setup!?
110 // $this->db->disconnect();
111  }
112 
116  function getCurrentVersion()
117  {
118  $q = "SELECT db_version FROM il_plugin ".
119  " WHERE component_type = ".$this->db->quote($this->ctype).
120  " AND component_name = ".$this->db->quote($this->cname).
121  " AND slot_id = ".$this->db->quote($this->slot_id).
122  " AND name = ".$this->db->quote($this->pname);
123  $set = $this->db->query($q);
124  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
125 
126  $this->currentVersion = (int) $rec["db_version"];
127 
128  return $this->currentVersion;
129  }
130 
134  function setCurrentVersion($a_version)
135  {
136  $q = "UPDATE il_plugin SET db_version = ".$this->db->quote($a_version).
137  " WHERE component_type = ".$this->db->quote($this->ctype).
138  " AND component_name = ".$this->db->quote($this->cname).
139  " AND slot_id = ".$this->db->quote($this->slot_id).
140  " AND name = ".$this->db->quote($this->pname);
141  $this->db->query($q);
142  $this->currentVersion = $a_version;
143  return true;
144  }
145 
146  function loadXMLInfo()
147  {
148  // to do: reload control structure information for plugin
149  return true;
150  }
151 
155  function checkQuery($q)
156  {
157  if ((is_int(stripos($q, "create table")) || is_int(stripos($q, "alter table")) ||
158  is_int(stripos($q, "drop table")))
159  && !is_int(stripos($q, $this->db_prefix)))
160  {
161  return "Plugin may only create or alter tables that start with prefix ".
162  $this->db_prefix;
163  }
164  else
165  {
166  return true;
167  }
168  }
169 
170 
171 } // END class.DBUdate
172 ?>