ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function __construct(
18  $a_ctype,
19  $a_cname,
20  $a_slot_id,
21  $a_pname,
22  $a_db_handler,
23  $tmp_flag,
24  $a_db_prefix
25  ) {
26  $this->db_prefix = $a_db_prefix;
27 
28  // workaround to allow setup migration
29  if ($a_db_handler) {
30  $this->db = $a_db_handler;
31 
32  if ($tmp_flag) {
33  $this->PATH = "./";
34  } else {
35  $this->PATH = "../";
36  }
37  } else {
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(
50  $this->ctype,
51  $this->cname,
52  $this->slot_id
53  );
54 
55  $this->getCurrentVersion();
56 
57  // get update file for current version
58  $updatefile = $this->getFileForStep($this->currentVersion + 1);
59 
60  $this->current_file = $updatefile;
61  $this->DB_UPDATE_FILE = $this->PATH .
63  $this->ctype,
64  $this->cname,
65  $this->slot_name,
66  $this->pname
67  );
68 
69  //
70  // NOTE: multiple update files for plugins are not supported yet
71  //
72  $this->LAST_UPDATE_FILE = $this->PATH .
74  $this->ctype,
75  $this->cname,
76  $this->slot_name,
77  $this->pname
78  );
79 
80  $this->readDBUpdateFile();
81  $this->readLastUpdateFile();
82  $this->readFileVersion();
83  }
84 
88  public function getFileForStep($a_version)
89  {
90  return "dbupdate.php";
91  }
92 
98  public function _DBUpdate()
99  {
100  // this may be used in setup!?
101 // $this->db->disconnect();
102  }
103 
107  public function getCurrentVersion()
108  {
109  $q = "SELECT db_version FROM il_plugin " .
110  " WHERE component_type = " . $this->db->quote($this->ctype, "text") .
111  " AND component_name = " . $this->db->quote($this->cname, "text") .
112  " AND slot_id = " . $this->db->quote($this->slot_id, "text") .
113  " AND name = " . $this->db->quote($this->pname, "text");
114  $set = $this->db->query($q);
115  $rec = $this->db->fetchAssoc($set);
116 
117  $this->currentVersion = (int) $rec["db_version"];
118 
119  return $this->currentVersion;
120  }
121 
125  public function setCurrentVersion($a_version)
126  {
127  $q = "UPDATE il_plugin SET db_version = " . $this->db->quote((int) $a_version, "integer") .
128  " WHERE component_type = " . $this->db->quote($this->ctype, "text") .
129  " AND component_name = " . $this->db->quote($this->cname, "text") .
130  " AND slot_id = " . $this->db->quote($this->slot_id, "text") .
131  " AND name = " . $this->db->quote($this->pname, "text");
132  $this->db->manipulate($q);
133  $this->currentVersion = $a_version;
134  return true;
135  }
136 
137  public function loadXMLInfo()
138  {
139  // to do: reload control structure information for plugin
140  return true;
141  }
142 
146  public function checkQuery($q)
147  {
148  if ((is_int(stripos($q, "create table")) || is_int(stripos($q, "alter table")) ||
149  is_int(stripos($q, "drop table")))
150  && !is_int(stripos($q, $this->db_prefix))) {
151  return "Plugin may only create or alter tables that use prefix " .
152  $this->db_prefix;
153  } else {
154  return true;
155  }
156  }
157 } // END class.DBUdate
Database Update class.
__construct( $a_ctype, $a_cname, $a_slot_id, $a_pname, $a_db_handler, $tmp_flag, $a_db_prefix)
constructor
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
setCurrentVersion($a_version)
Set current DB version.
const PATH
Definition: proxy_ylocal.php:8
checkQuery($q)
This is a very simple check.
Database Update class.
static getDBUpdateScriptName($a_ctype, $a_cname, $a_slot_name, $a_pname)
Get DB update script filename (full path)
getCurrentVersion()
Get current DB version.
getFileForStep($a_version)
Get db update file name for db step.