upgrade.inc.php
5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* $Id$
*
* Assists in discovering what needs to be done to upgrade one version
* of KnowledgeTree to another.
*
* The contents of this file are subject to the KnowledgeTree Public
* License Version 1.1.2 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.knowledgetree.com/KPL
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights and
* limitations under the License.
*
* All copies of the Covered Code must include on each user interface screen:
* (i) the "Powered by KnowledgeTree" logo and
* (ii) the KnowledgeTree copyright notice
* in the same form as they appear in the distribution. See the License for
* requirements.
*
* The Original Code is: KnowledgeTree Open Source
*
* The Initial Developer of the Original Code is The Jam Warehouse Software
* (Pty) Ltd, trading as KnowledgeTree.
* Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
* (C) 2007 The Jam Warehouse Software (Pty) Ltd;
* All Rights Reserved.
* Contributor( s): ______________________________________
*/
require_once(KT_LIB_DIR . '/upgrades/UpgradeItems.inc.php');
function setupAdminDatabase() {
global $default;
$dsn = array(
'phptype' => $default->dbType,
'username' => $default->dbAdminUser,
'password' => $default->dbAdminPass,
'hostspec' => $default->dbHost,
'database' => $default->dbName,
'port' => $default->dbPort,
);
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ERRORS,
'seqname_format' => 'zseq_%s',
);
$default->_admindb = &DB::connect($dsn, $options);
if (PEAR::isError($default->_admindb)) {
die($default->_admindb->toString());
}
$default->_admindb->setFetchMode(DB_FETCHMODE_ASSOC);
return;
}
setupAdminDatabase();
// {{{ Format of the descriptor
/**
* Format of the descriptor
*
* type*version*phase*simple description for uniqueness
*
* type is: sql, function, subupgrade, upgrade
* version is: 1.2.4, 2.0.0rc5
* phase is: 0, 1, 0pre. Phase is _only_ evaluated by describeUpgrades.
* description is: anything, unique in terms of version and type.
*/
// }}}
// {{{ describeUpgrade
/**
* Describe the upgrade path between two versions of KnowledgeTree.
*
* @param string Original version (e.g., "1.2.4")
* @param string Current version (e.g., "2.0.2")
*
* @return array Array of UpgradeItem describing steps to be taken
*/
function &describeUpgrade ($origVersion, $currVersion) {
// How to figure out what upgrades to do:
//
// 1. Get all SQL upgrades >= origVersion and <= currVersion
// 2. Get all Function upgrades >= origVersion and <= currVersion
// 3. Categorise each into version they upgrade to
// 4. Sort each version subgroup into correct order
// 5. Add "recordSubUpgrade" for each version there.
// 6. Add back into one big list again
// 7. Add "recordUpgrade" for whole thing
// $recordUpgrade = array('upgrade*' . $currVersion, 'Upgrade to ' . $currVersion, null);
$steps = array();
foreach (array('SQLUpgradeItem', 'FunctionUpgradeItem') as $itemgen) {
$f = array($itemgen, 'getUpgrades');
$ssteps =& call_user_func($f, $origVersion, $currVersion);
$scount = count($ssteps);
for ($i = 0; $i < $scount; $i++) {
$steps[] =& $ssteps[$i];
}
}
$upgradestep =& new RecordUpgradeItem($currVersion, $origVersion);
$steps[] =& $upgradestep;
$stepcount = count($steps);
for ($i = 0; $i < $stepcount; $i++) {
$step =& $steps[$i];
$step->setParent($upgradestep);
}
usort($steps, 'step_sort_func');
return $steps;
}
// }}}
// {{{ step_sort_func
function step_sort_func ($obj1, $obj2) {
// Ugly hack to ensure that upgrade table is made first...
if ($obj1->name === "2.0.6/create_upgrade_table.sql") {
return -1;
}
if ($obj2->name === "2.0.6/create_upgrade_table.sql") {
return 1;
}
$res = compare_version($obj1->getVersion(), $obj2->getVersion());
if ($res !== 0) {
return $res;
}
if ($obj1->getPhase() > $obj2->getPhase()) {
return 1;
}
if ($obj1->getPhase() < $obj2->getPhase()) {
return -1;
}
return 0;
}
// }}}
// {{{ compare_version
/**
* Compares two version numbers and returns a value based on this comparison
*
* Using standard software version rules, such as 2.0.5rc1 comes before
* 2.0.5, and 2.0.5rc1 comes after 2.0.5alpha1, compare two version
* numbers, and determine which is the higher.
*
* XXX: Actually, just does $version1 < $version2
*
* @param string First version number
* @param string Second version number
*
* @return int -1, 0, 1
*/
function compare_version($version1, $version2) {
// XXX: Version comparisons should be better.
if ($version1 < $version2) {
return -1;
}
if ($version1 > $version2) {
return 1;
}
return 0;
}
// }}}
// {{{ lte_version
/**
* Quick-hand for checking if a version number is lower-than-or-equal-to
*/
function lte_version($version1, $version2) {
if (in_array(compare_version($version1, $version2), array(-1, 0))) {
return true;
}
return false;
}
// }}
// {{ gte_version
/**
* Quick-hand for checking if a version number is greater-than-or-equal-to
*/
function gte_version($version1, $version2) {
if (in_array(compare_version($version1, $version2), array(0, 1))) {
return true;
}
return false;
}
// }}}
?>