ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
39  $mySetup = $DIC['mySetup'];
40  $this->db = $mySetup->db;
41  $this->PATH = "./";
42  }
43 
44  $this->ctype = $a_ctype;
45  $this->cname = $a_cname;
46  $this->slot_id = $a_slot_id;
47  $this->pname = $a_pname;
48 
49  include_once("./Services/Component/classes/class.ilPluginSlot.php");
50  $this->slot_name = ilPluginSlot::lookupSlotName(
51  $this->ctype,
52  $this->cname,
53  $this->slot_id
54  );
55 
56  $this->getCurrentVersion();
57 
58  // get update file for current version
59  $updatefile = $this->getFileForStep($this->currentVersion + 1);
60 
61  $this->current_file = $updatefile;
62  $this->DB_UPDATE_FILE = $this->PATH .
64  $this->ctype,
65  $this->cname,
66  $this->slot_name,
67  $this->pname
68  );
69 
70  //
71  // NOTE: multiple update files for plugins are not supported yet
72  //
73  $this->LAST_UPDATE_FILE = $this->PATH .
75  $this->ctype,
76  $this->cname,
77  $this->slot_name,
78  $this->pname
79  );
80 
81  $this->readDBUpdateFile();
82  $this->readLastUpdateFile();
83  $this->readFileVersion();
84  }
85 
89  public function getFileForStep($a_version)
90  {
91  return "dbupdate.php";
92  }
93 
99  public function _DBUpdate()
100  {
101  // this may be used in setup!?
102 // $this->db->disconnect();
103  }
104 
108  public function getCurrentVersion()
109  {
110  $q = "SELECT db_version FROM il_plugin " .
111  " WHERE component_type = " . $this->db->quote($this->ctype, "text") .
112  " AND component_name = " . $this->db->quote($this->cname, "text") .
113  " AND slot_id = " . $this->db->quote($this->slot_id, "text") .
114  " AND name = " . $this->db->quote($this->pname, "text");
115  $set = $this->db->query($q);
116  $rec = $this->db->fetchAssoc($set);
117 
118  $this->currentVersion = (int) $rec["db_version"];
119 
120  return $this->currentVersion;
121  }
122 
126  public function setCurrentVersion($a_version)
127  {
128  $q = "UPDATE il_plugin SET db_version = " . $this->db->quote((int) $a_version, "integer") .
129  " WHERE component_type = " . $this->db->quote($this->ctype, "text") .
130  " AND component_name = " . $this->db->quote($this->cname, "text") .
131  " AND slot_id = " . $this->db->quote($this->slot_id, "text") .
132  " AND name = " . $this->db->quote($this->pname, "text");
133  $this->db->manipulate($q);
134  $this->currentVersion = $a_version;
135  return true;
136  }
137 
138  public function loadXMLInfo()
139  {
140  // to do: reload control structure information for plugin
141  return true;
142  }
143 
147  public function checkQuery($q)
148  {
149  if ((is_int(stripos($q, "create table")) || is_int(stripos($q, "alter table")) ||
150  is_int(stripos($q, "drop table")))
151  && !is_int(stripos($q, $this->db_prefix))) {
152  return "Plugin may only create or alter tables that use prefix " .
153  $this->db_prefix;
154  } else {
155  return true;
156  }
157  }
158 } // END class.DBUdate
global $DIC
Definition: saml.php:7
static getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname)
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.
getCurrentVersion()
Get current DB version.
getFileForStep($a_version)
Get db update file name for db step.