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