Index: trunk/extensions/SemanticMediaWiki/specials/SMWAdmin/SMW_SpecialSMWAdmin.php |
— | — | @@ -15,51 +15,46 @@ |
16 | 16 | { |
17 | 17 | global $wgMessageCache; |
18 | 18 | $wgMessageCache->addMessages(array('smwadmin' => 'Admin functions for Semantic MediaWiki')); |
19 | | - |
| 19 | + |
20 | 20 | SpecialPage::addPage( new SpecialPage('SMWAdmin','delete',true,'doSpecialSMWAdmin',false) ); |
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | | - |
25 | | - |
26 | | -function doSpecialSMWAdmin($par = null) |
27 | | -{ |
| 24 | +function doSpecialSMWAdmin($par = null) { |
28 | 25 | global $IP, $smwgIP; |
29 | 26 | require_once($smwgIP . '/includes/SMW_Storage.php'); |
30 | | - require_once( "$IP/includes/SpecialPage.php" ); |
31 | | - require_once( "$IP/includes/Title.php" ); |
32 | | - |
| 27 | + require_once($IP . '/includes/SpecialPage.php' ); |
| 28 | + require_once($IP . '/includes/Title.php' ); |
| 29 | + |
33 | 30 | global $wgOut, $wgRequest; |
34 | 31 | global $wgServer; // "http://www.yourserver.org" |
35 | 32 | // (should be equal to 'http://'.$_SERVER['SERVER_NAME']) |
36 | 33 | global $wgScript; // "/subdirectory/of/wiki/index.php" |
37 | 34 | global $wgUser; |
38 | | - |
| 35 | + |
39 | 36 | if ( ! $wgUser->isAllowed('delete') ) { |
40 | 37 | $wgOut->sysopRequired(); |
41 | 38 | return; |
42 | 39 | } |
43 | | - |
| 40 | + |
44 | 41 | /**** Execute actions if any ****/ |
45 | | - |
| 42 | + |
46 | 43 | $action = $wgRequest->getText( 'action' ); |
47 | 44 | $message=''; |
48 | 45 | if ( $action=='updatetables' ) { |
49 | 46 | $sure = $wgRequest->getText( 'udsure' ); |
50 | 47 | if ($sure == 'yes') { |
51 | | - $message = smwfAdminUpdateTables(); |
| 48 | + $message = smwfGetStore()->setup(); |
| 49 | + if ($message === true) { |
| 50 | + $message = 'The database was set up successfully.'; |
| 51 | + } |
52 | 52 | } |
53 | 53 | } |
54 | | - |
55 | | -// Special function for fixing development testing DBs after messing around ... |
56 | | - if ( $action=='restore' ) { |
57 | | - $message = smwfRestoreTableTitles(); |
58 | | - } |
59 | | - |
| 54 | + |
60 | 55 | /**** Output ****/ |
61 | | - |
| 56 | + |
62 | 57 | $wgOut->setPageTitle(wfMsg('smwadmin')); |
63 | | - |
| 58 | + |
64 | 59 | // only report success/failure after an action |
65 | 60 | if ( $message!='' ) { |
66 | 61 | $html = $message; |
— | — | @@ -67,400 +62,376 @@ |
68 | 63 | $wgOut->addHTML($html); |
69 | 64 | return true; |
70 | 65 | } |
71 | | - |
72 | | - // standard output interface |
73 | | - $db =& wfGetDB( DB_MASTER ); |
74 | | - $curTableNames = $db->tableExists('smw_relations'); |
75 | | - if ($curTableNames === true) { |
76 | | - $curFieldNames = $db->fieldExists('smw_relations', 'subject_id'); |
77 | | - $oldTableNames = false; // we assume this ... |
78 | | - } else { |
79 | | - $oldTableNames = $db->tableExists('semantic_relations'); |
80 | | - $curFieldNames = false; |
81 | | - } |
82 | | - |
83 | | - |
| 66 | + |
84 | 67 | $html = '<p>This special page helps you during installation and upgrade of |
85 | 68 | Semantic MediaWiki. Remember to backup valuable data before |
86 | 69 | executing administrative functions.</p>' . "\n"; |
87 | 70 | // creating tables and converting contents from older versions |
88 | 71 | $html .= '<form name="buildtables" action="" method="POST">' . "\n" . |
89 | | - '<input type="hidden" name="action" value="updatetables" />' . "\n"; |
90 | | - if (($curTableNames === true) && ($curFieldNames === false)) { |
91 | | - $html .= '<h2>Upgrading from Semantic MediaWiki ≤0.3</h2>' . "\n" . |
92 | | - '<p>Semantic MediaWiki versions until 0.3 used a slightly simpler internal data format. |
93 | | - The new format increases efficiency, but older entries must be |
94 | | - converted in order to be preserved. This does only affect your semantic |
95 | | - data; article texts are not touched.<p/>' . "\n"; |
96 | | - $html .= '<p>If the operation fails with obscure SQL errors, the database user employed |
| 72 | + '<input type="hidden" name="action" value="updatetables" />' . "\n"; |
| 73 | + $html .= '<h2>Preparing database for Semantic MediaWiki</h2>' . "\n" . |
| 74 | + '<p>Semantic MediaWiki requires some minor extensions to the MediaWiki database in |
| 75 | + order to store the semantic data. The below function ensures that your database is |
| 76 | + set up properly. The changes made in this step do not affect the rest of the |
| 77 | + MediaWiki database, and can easily be undone if desired. This setup function |
| 78 | + can be executed multiple times without doing any harm, but it is needed only once on |
| 79 | + installation or upgrade.<p/>' . "\n"; |
| 80 | + $html .= '<p>If the operation fails with obscure SQL errors, the database user employed |
97 | 81 | by your wiki (check your LocalSettings.php) probably does not have sufficient |
98 | 82 | permissions. Either grant this user additional persmissions to create and delete |
99 | | - tables, or temporarily enter the login of your database root in LocalSettings.php.<p/>' . |
100 | | - "\n" . |
101 | | - '<input type="checkbox" name="udsure" value="yes">Yes, I am sure.</input>' . |
102 | | - ' <input type="submit" value="Update tables"/>' . "\n"; |
103 | | - } elseif (($curTableNames === false) && ($oldTableNames === false)) { |
104 | | - $html .= '<h2>Preparing database for Semantic MediaWiki</h2>' . "\n" . |
105 | | - '<p>Semantic MediaWiki requires some minor extensions to the MediaWiki database in |
106 | | - order to store the semantic data. These extensions must still be initialised on your |
107 | | - site. The changes made in this step do not affect the rest of the MediaWiki database, |
108 | | - and can easily be undone if desired.<p/>' . "\n"; |
109 | | - $html .= '<p>If the operation fails with obscure SQL errors, the database user employed |
110 | | - by your wiki (check your LocalSettings.php) probably does not have sufficient |
111 | | - permissions. Either grant this user additional persmissions to create and delete |
112 | | - tables, or temporarily enter the login of your database root in LocalSettings.php.<p/>' . |
113 | | - "\n" . '<input type="hidden" name="udsure" value="yes"/>' . |
114 | | - '<input type="submit" value="Initialise tables"/>' . "\n"; |
115 | | - } elseif (($curTableNames === false) && ($oldTableNames === true)) { |
116 | | - $html .= '<h2>Upgrade instructions from version ≤0.3</h2>' . "\n" . |
117 | | - '<p>A installation of Semantic MediaWiki version ≤ 0.3 was detected. To upgrade and convert existing semantic data where possible, subsequently install all released versions starting from your old version (e.g., if you used 0.2, download and install 0.3 next). Alternatively, you can manually delete the table <b>semantic_relations</b> from your wiki database. In this case, existing annotations will no longer be accessible until the respective articles are stored again.<p/>' . "\n"; |
118 | | - } else { |
119 | | - $html .= '<h2>Semantic MediaWiki database status</h2>' . "\n" . |
120 | | - '<p>Your database setup seems to be alright. If you experience problems with |
121 | | - your installation, check the guidelines in your INSTALL file. If this does not |
122 | | - solve your problem, send an email to <a href="malito:semediawiki-user@lists.sourceforge.net">semediawiki-user@lists.sourceforge.net</a>.<p/>' . "\n"; |
123 | | - } |
| 83 | + tables, or temporarily enter the login of your database root in LocalSettings.php.<p/>' . |
| 84 | + "\n" . '<input type="hidden" name="udsure" value="yes"/>' . |
| 85 | + '<input type="submit" value="Initialise or upgrade tables"/>' . "\n"; |
| 86 | + |
| 87 | + $html .= '<h2>Getting support</h2>' . "\n" . |
| 88 | + '<p>Various resources might help you in case of problems:</p> |
| 89 | + <ul> |
| 90 | + <li> If you experience problems with your installation, start by checking the guidelines in the <a href="http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SemanticMediaWiki/INSTALL">INSTALL file</a>.</li> |
| 91 | + <li>The complete user documentation to Semantic MediaWiki is at <a href="http://ontoworld.org/wiki/Help:Semantics">ontoworld.org</a>.</li> |
| 92 | + <li>Bugs can be reported to <a href="http://bugzilla.wikimedia.org/">MediaZilla</a>.</li> |
| 93 | + <li>If you have further questions or suggestions, join the discussion on <a href="malito:semediawiki-user@lists.sourceforge.net">semediawiki-user@lists.sourceforge.net</a>.</li> |
| 94 | + <ul/>' . "\n"; |
124 | 95 | $html .= '</form>'; |
125 | 96 | |
126 | 97 | $wgOut->addHTML($html); |
127 | 98 | return true; |
128 | 99 | } |
129 | 100 | |
130 | | -// Special function for fixing development testing DBs after messing around ... |
131 | | -function smwfRestoreTableTitles() { |
132 | | - $dbr =& wfGetDB( DB_SLAVE ); |
133 | | - extract( $dbr->tableNames( 'smw_attributes','smw_relations','smw_specialprops' )); |
134 | | - |
135 | | - // convert old values |
136 | | - $sql = 'SELECT DISTINCT attribute_title FROM ' . $smw_attributes; |
137 | | - $res = $dbr->query( $sql, $fname ); |
138 | | - if($dbr->numRows( $res ) > 0) { |
139 | | - $row = $dbr->fetchObject($res); |
140 | | - while($row) { |
141 | | - $t = Title::newFromText($row->attribute_title, SMW_NS_ATTRIBUTE); |
142 | | - if ($t != NULL) { |
143 | | - $text = $t->getDBkey(); |
144 | | - $sql = "UPDATE $smw_attributes SET attribute_title = " . $dbr->addQuotes($text) . " WHERE attribute_title = " . $dbr->addQuotes($row->attribute_title) ; |
145 | | - $dbr->query( $sql, $fname ); |
146 | | - } |
147 | | - $row = $dbr->fetchObject($res); |
148 | | - } |
149 | | - } |
150 | | - |
151 | | - // convert old values |
152 | | - $sql = 'SELECT DISTINCT relation_title FROM ' . $smw_relations; |
153 | | - $res = $dbr->query( $sql, $fname ); |
154 | | - if($dbr->numRows( $res ) > 0) { |
155 | | - $row = $dbr->fetchObject($res); |
156 | | - while($row) { |
157 | | - $t = Title::newFromText($row->relation_title, SMW_NS_RELATION); |
158 | | - if ($t != NULL) { |
159 | | - $text = $t->getDBkey(); |
160 | | - $sql = "UPDATE $smw_relations SET relation_title = " . $dbr->addQuotes($text) . " WHERE relation_title = " . $dbr->addQuotes($row->relation_title) ; |
161 | | - $dbr->query( $sql, $fname ); |
162 | | - } |
163 | | - $row = $dbr->fetchObject($res); |
164 | | - } |
165 | | - } |
166 | | - |
167 | | - // convert old values |
168 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_attributes; |
169 | | - $res = $dbr->query( $sql, $fname ); |
170 | | - if($dbr->numRows( $res ) > 0) { |
171 | | - $row = $dbr->fetchObject($res); |
172 | | - while($row) { |
173 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
174 | | - if ($t != NULL) { |
175 | | - $id = $t->getArticleID(); |
176 | | - $stitle = $t->getDBkey(); |
177 | | - $sql = "UPDATE $smw_attributes SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
178 | | - $dbr->query( $sql, $fname ); |
179 | | - } |
180 | | - $row = $dbr->fetchObject($res); |
181 | | - } |
182 | | - } |
183 | | - |
184 | | - // convert old values |
185 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace, object_title FROM ' . $smw_relations; |
186 | | - $res = $dbr->query( $sql, $fname ); |
187 | | - if($dbr->numRows( $res ) > 0) { |
188 | | - $row = $dbr->fetchObject($res); |
189 | | - while($row) { |
190 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
191 | | - if ($t != NULL) { |
192 | | - $id = $t->getArticleID(); |
193 | | - $stitle = $t->getDBkey(); |
194 | | - $sql = "UPDATE $smw_relations SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . ", object_title = " . $dbr->addQuotes(str_replace(" ", "_", $row->object_title)) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title) . " AND object_title = " . $dbr->addQuotes($row->object_title); |
195 | | - $dbr->query( $sql, $fname ); |
196 | | - } |
197 | | - $row = $dbr->fetchObject($res); |
198 | | - } |
199 | | - } |
200 | | - |
201 | | - // convert old values |
202 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_specialprops; |
203 | | - $res = $dbr->query( $sql, $fname ); |
204 | | - if($dbr->numRows( $res ) > 0) { |
205 | | - $row = $dbr->fetchObject($res); |
206 | | - while($row) { |
207 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
208 | | - if ($t != NULL) { |
209 | | - $id = $t->getArticleID(); |
210 | | - $stitle = $t->getDBkey(); |
211 | | - $sql = "UPDATE $smw_specialprops SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
212 | | - $dbr->query( $sql, $fname ); |
213 | | - } |
214 | | - $row = $dbr->fetchObject($res); |
215 | | - } |
216 | | - } |
217 | | - |
218 | | - //add more indices for new columns |
219 | | -// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `attribute_title` )"; |
| 101 | +// // Special function for fixing development testing DBs after messing around ... |
| 102 | +// function smwfRestoreTableTitles() { |
| 103 | +// $dbr =& wfGetDB( DB_SLAVE ); |
| 104 | +// extract( $dbr->tableNames( 'smw_attributes','smw_relations','smw_specialprops' )); |
| 105 | +// |
| 106 | +// // convert old values |
| 107 | +// $sql = 'SELECT DISTINCT attribute_title FROM ' . $smw_attributes; |
| 108 | +// $res = $dbr->query( $sql, $fname ); |
| 109 | +// if($dbr->numRows( $res ) > 0) { |
| 110 | +// $row = $dbr->fetchObject($res); |
| 111 | +// while($row) { |
| 112 | +// $t = Title::newFromText($row->attribute_title, SMW_NS_ATTRIBUTE); |
| 113 | +// if ($t != NULL) { |
| 114 | +// $text = $t->getDBkey(); |
| 115 | +// $sql = "UPDATE $smw_attributes SET attribute_title = " . $dbr->addQuotes($text) . " WHERE attribute_title = " . $dbr->addQuotes($row->attribute_title) ; |
| 116 | +// $dbr->query( $sql, $fname ); |
| 117 | +// } |
| 118 | +// $row = $dbr->fetchObject($res); |
| 119 | +// } |
| 120 | +// } |
| 121 | +// |
| 122 | +// // convert old values |
| 123 | +// $sql = 'SELECT DISTINCT relation_title FROM ' . $smw_relations; |
| 124 | +// $res = $dbr->query( $sql, $fname ); |
| 125 | +// if($dbr->numRows( $res ) > 0) { |
| 126 | +// $row = $dbr->fetchObject($res); |
| 127 | +// while($row) { |
| 128 | +// $t = Title::newFromText($row->relation_title, SMW_NS_RELATION); |
| 129 | +// if ($t != NULL) { |
| 130 | +// $text = $t->getDBkey(); |
| 131 | +// $sql = "UPDATE $smw_relations SET relation_title = " . $dbr->addQuotes($text) . " WHERE relation_title = " . $dbr->addQuotes($row->relation_title) ; |
| 132 | +// $dbr->query( $sql, $fname ); |
| 133 | +// } |
| 134 | +// $row = $dbr->fetchObject($res); |
| 135 | +// } |
| 136 | +// } |
| 137 | +// |
| 138 | +// // convert old values |
| 139 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_attributes; |
| 140 | +// $res = $dbr->query( $sql, $fname ); |
| 141 | +// if($dbr->numRows( $res ) > 0) { |
| 142 | +// $row = $dbr->fetchObject($res); |
| 143 | +// while($row) { |
| 144 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 145 | +// if ($t != NULL) { |
| 146 | +// $id = $t->getArticleID(); |
| 147 | +// $stitle = $t->getDBkey(); |
| 148 | +// $sql = "UPDATE $smw_attributes SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
| 149 | +// $dbr->query( $sql, $fname ); |
| 150 | +// } |
| 151 | +// $row = $dbr->fetchObject($res); |
| 152 | +// } |
| 153 | +// } |
| 154 | +// |
| 155 | +// // convert old values |
| 156 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace, object_title FROM ' . $smw_relations; |
| 157 | +// $res = $dbr->query( $sql, $fname ); |
| 158 | +// if($dbr->numRows( $res ) > 0) { |
| 159 | +// $row = $dbr->fetchObject($res); |
| 160 | +// while($row) { |
| 161 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 162 | +// if ($t != NULL) { |
| 163 | +// $id = $t->getArticleID(); |
| 164 | +// $stitle = $t->getDBkey(); |
| 165 | +// $sql = "UPDATE $smw_relations SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . ", object_title = " . $dbr->addQuotes(str_replace(" ", "_", $row->object_title)) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title) . " AND object_title = " . $dbr->addQuotes($row->object_title); |
| 166 | +// $dbr->query( $sql, $fname ); |
| 167 | +// } |
| 168 | +// $row = $dbr->fetchObject($res); |
| 169 | +// } |
| 170 | +// } |
| 171 | +// |
| 172 | +// // convert old values |
| 173 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_specialprops; |
| 174 | +// $res = $dbr->query( $sql, $fname ); |
| 175 | +// if($dbr->numRows( $res ) > 0) { |
| 176 | +// $row = $dbr->fetchObject($res); |
| 177 | +// while($row) { |
| 178 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 179 | +// if ($t != NULL) { |
| 180 | +// $id = $t->getArticleID(); |
| 181 | +// $stitle = $t->getDBkey(); |
| 182 | +// $sql = "UPDATE $smw_specialprops SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
| 183 | +// $dbr->query( $sql, $fname ); |
| 184 | +// } |
| 185 | +// $row = $dbr->fetchObject($res); |
| 186 | +// } |
| 187 | +// } |
| 188 | +// |
| 189 | +// //add more indices for new columns |
| 190 | +// // $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `attribute_title` )"; |
| 191 | +// // $dbr->query( $sql, $fname ); |
| 192 | +// // $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_num` )"; |
| 193 | +// // $dbr->query( $sql, $fname ); |
| 194 | +// // $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_xsd` )"; |
| 195 | +// // $dbr->query( $sql, $fname ); |
| 196 | +// // $sql = "ALTER TABLE $smw_relations ADD INDEX ( `relation_title` )"; |
| 197 | +// // $dbr->query( $sql, $fname ); |
| 198 | +// // $sql = "ALTER TABLE $smw_relations ADD INDEX ( `object_title` )"; |
| 199 | +// // $dbr->query( $sql, $fname ); |
| 200 | +// |
| 201 | +// |
| 202 | +// // // modify table structure for attributes |
| 203 | +// // $sql = "ALTER TABLE $smw_attributes CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 204 | +// // $dbr->query( $sql, $fname ); |
| 205 | +// // $sql = "ALTER TABLE $smw_attributes CHANGE `attribute_title` `attribute_title` VARCHAR(255) NOT NULL"; |
| 206 | +// // $dbr->query( $sql, $fname ); |
| 207 | +// // $sql = "ALTER TABLE $smw_attributes CHANGE `value_unit` `value_unit` VARCHAR(63)"; |
| 208 | +// // $dbr->query( $sql, $fname ); |
| 209 | +// // $sql = "ALTER TABLE $smw_attributes CHANGE `value_datatype` `value_datatype` VARCHAR(31) NOT NULL"; |
| 210 | +// // $dbr->query( $sql, $fname ); |
| 211 | +// // $sql = "ALTER TABLE $smw_attributes CHANGE `value_xsd` `value_xsd` VARCHAR(255) NOT NULL"; |
| 212 | +// // $dbr->query( $sql, $fname ); |
| 213 | +// // |
| 214 | +// // $sql = "ALTER TABLE $smw_relations CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 215 | +// // $dbr->query( $sql, $fname ); |
| 216 | +// // $sql = "ALTER TABLE $smw_relations CHANGE `relation_title` `relation_title` VARCHAR(255) NOT NULL"; |
| 217 | +// // $dbr->query( $sql, $fname ); |
| 218 | +// // $sql = "ALTER TABLE $smw_relations CHANGE `object_title` `object_title` VARCHAR(255) NOT NULL"; |
| 219 | +// // $dbr->query( $sql, $fname ); |
| 220 | +// // |
| 221 | +// // $sql = "ALTER TABLE $smw_specialprops CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 222 | +// // $dbr->query( $sql, $fname ); |
| 223 | +// // $sql = "ALTER TABLE $smw_specialprops CHANGE `value_string` `value_string` VARCHAR(255) NOT NULL"; |
| 224 | +// // $dbr->query( $sql, $fname ); |
| 225 | +// |
| 226 | +// return "Done"; |
| 227 | +// } |
| 228 | + |
| 229 | +// /** |
| 230 | +// * A function for updating tables from 0.3 to post 0.3 |
| 231 | +// */ |
| 232 | +// function smwfAdminUpdateTables() { |
| 233 | +// $dbr =& wfGetDB( DB_MASTER ); |
| 234 | +// |
| 235 | +// if ($dbr->tableExists('smw_relations') === false) { |
| 236 | +// smwfGetStore()->setup(); |
| 237 | +// return 'The database has been initialised successfully.'; |
| 238 | +// } |
| 239 | +// |
| 240 | +// if ($dbr->fieldExists('smw_relations', 'subject_id')) { |
| 241 | +// return 'This function was probably called accidentally. Your database already has the required structure.'; |
| 242 | +// } |
| 243 | +// |
| 244 | +// extract( $dbr->tableNames( 'smw_attributes','smw_relations','smw_specialprops' )); |
| 245 | +// $fname = 'SMW::AdminUpdateTables'; |
| 246 | +// |
| 247 | +// // modify table structure for attributes |
| 248 | +// $sql = "ALTER TABLE $smw_attributes TYPE = innodb"; |
220 | 249 | // $dbr->query( $sql, $fname ); |
221 | | -// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_num` )"; |
| 250 | +// $sql = "ALTER TABLE $smw_attributes ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
222 | 251 | // $dbr->query( $sql, $fname ); |
223 | | -// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_xsd` )"; |
224 | | -// $dbr->query( $sql, $fname ); |
225 | | -// $sql = "ALTER TABLE $smw_relations ADD INDEX ( `relation_title` )"; |
| 252 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
226 | 253 | // $dbr->query( $sql, $fname ); |
227 | | -// $sql = "ALTER TABLE $smw_relations ADD INDEX ( `object_title` )"; |
| 254 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
228 | 255 | // $dbr->query( $sql, $fname ); |
229 | | - |
230 | | - |
231 | | -// // modify table structure for attributes |
232 | | -// $sql = "ALTER TABLE $smw_attributes CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 256 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `attribute` `attribute_title` VARCHAR(255) NOT NULL"; |
233 | 257 | // $dbr->query( $sql, $fname ); |
234 | | -// $sql = "ALTER TABLE $smw_attributes CHANGE `attribute_title` `attribute_title` VARCHAR(255) NOT NULL"; |
| 258 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `unit` `value_unit` VARCHAR(63)"; |
235 | 259 | // $dbr->query( $sql, $fname ); |
236 | | -// $sql = "ALTER TABLE $smw_attributes CHANGE `value_unit` `value_unit` VARCHAR(63)"; |
| 260 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `datatype` `value_datatype` VARCHAR(31) NOT NULL"; |
237 | 261 | // $dbr->query( $sql, $fname ); |
238 | | -// $sql = "ALTER TABLE $smw_attributes CHANGE `value_datatype` `value_datatype` VARCHAR(31) NOT NULL"; |
| 262 | +// $sql = "ALTER TABLE $smw_attributes CHANGE `value` `value_xsd` VARCHAR(255) NOT NULL"; |
239 | 263 | // $dbr->query( $sql, $fname ); |
240 | | -// $sql = "ALTER TABLE $smw_attributes CHANGE `value_xsd` `value_xsd` VARCHAR(255) NOT NULL"; |
| 264 | +// $sql = "ALTER TABLE $smw_attributes ADD `value_num` DOUBLE"; |
241 | 265 | // $dbr->query( $sql, $fname ); |
242 | 266 | // |
243 | | -// $sql = "ALTER TABLE $smw_relations CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 267 | +// // convert old values |
| 268 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_attributes; |
| 269 | +// $res = $dbr->query( $sql, $fname ); |
| 270 | +// if($dbr->numRows( $res ) > 0) { |
| 271 | +// $row = $dbr->fetchObject($res); |
| 272 | +// while($row) { |
| 273 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 274 | +// if ($t != NULL) { |
| 275 | +// $id = $t->getArticleID(); |
| 276 | +// $stitle = $t->getDBkey(); |
| 277 | +// $sql = "UPDATE $smw_attributes SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
| 278 | +// $dbr->query( $sql, $fname ); |
| 279 | +// } |
| 280 | +// $row = $dbr->fetchObject($res); |
| 281 | +// } |
| 282 | +// } |
| 283 | +// |
| 284 | +// // create new scalar representations |
| 285 | +// // (luckily, for all 0.3 datatypes that have a scalar representation, the |
| 286 | +// // scalar version has the same PHP representation as the textual one. |
| 287 | +// foreach (array('int','float','geoarea','geolength') as $type) { |
| 288 | +// $sql = "SELECT DISTINCT value_xsd FROM $smw_attributes WHERE value_datatype = " . $dbr->addQuotes($type); |
| 289 | +// $res = $dbr->query( $sql, $fname ); |
| 290 | +// if($dbr->numRows( $res ) > 0) { |
| 291 | +// $row = $dbr->fetchObject($res); |
| 292 | +// while($row) { |
| 293 | +// $sql = "UPDATE $smw_attributes SET value_num = $row->value_xsd WHERE value_xsd = $row->value_xsd AND value_datatype = " . $dbr->addQuotes($type); |
| 294 | +// $dbr->query( $sql, $fname ); |
| 295 | +// |
| 296 | +// $row = $dbr->fetchObject($res); |
| 297 | +// } |
| 298 | +// } |
| 299 | +// } |
| 300 | +// |
| 301 | +// // rename attributes according to their DBkey |
| 302 | +// $sql = 'SELECT DISTINCT attribute_title FROM ' . $smw_attributes; |
| 303 | +// $res = $dbr->query( $sql, $fname ); |
| 304 | +// if($dbr->numRows( $res ) > 0) { |
| 305 | +// $row = $dbr->fetchObject($res); |
| 306 | +// while($row) { |
| 307 | +// $t = Title::newFromText($row->attribute_title, SMW_NS_ATTRIBUTE); |
| 308 | +// if ($t != NULL) { |
| 309 | +// $text = $t->getDBkey(); |
| 310 | +// $sql = "UPDATE $smw_attributes SET attribute_title = " . $dbr->addQuotes($text) . " WHERE attribute_title = " . $dbr->addQuotes($row->attribute_title) ; |
| 311 | +// $dbr->query( $sql, $fname ); |
| 312 | +// } |
| 313 | +// $row = $dbr->fetchObject($res); |
| 314 | +// } |
| 315 | +// } |
| 316 | +// |
| 317 | +// // modify table structure for relations |
| 318 | +// $sql = "ALTER TABLE $smw_relations TYPE = innodb"; |
244 | 319 | // $dbr->query( $sql, $fname ); |
245 | | -// $sql = "ALTER TABLE $smw_relations CHANGE `relation_title` `relation_title` VARCHAR(255) NOT NULL"; |
| 320 | +// $sql = "ALTER TABLE $smw_relations ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
246 | 321 | // $dbr->query( $sql, $fname ); |
247 | | -// $sql = "ALTER TABLE $smw_relations CHANGE `object_title` `object_title` VARCHAR(255) NOT NULL"; |
248 | | -// $dbr->query( $sql, $fname ); |
| 322 | +// $sql = "ALTER TABLE $smw_relations CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
| 323 | +// $dbr->query( $sql, $fname ); |
| 324 | +// $sql = "ALTER TABLE $smw_relations CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
| 325 | +// $dbr->query( $sql, $fname ); |
| 326 | +// $sql = "ALTER TABLE $smw_relations CHANGE `relation` `relation_title` VARCHAR(255) NOT NULL"; |
| 327 | +// $dbr->query( $sql, $fname ); |
| 328 | +// $sql = "ALTER TABLE $smw_relations CHANGE `objectns` `object_namespace` INT( 11 ) NOT NULL"; |
| 329 | +// $dbr->query( $sql, $fname ); |
| 330 | +// $sql = "ALTER TABLE $smw_relations CHANGE `object` `object_title` VARCHAR(255) NOT NULL"; |
| 331 | +// $dbr->query( $sql, $fname ); |
249 | 332 | // |
250 | | -// $sql = "ALTER TABLE $smw_specialprops CHANGE `subject_title` `subject_title` VARCHAR(255) NOT NULL"; |
| 333 | +// // convert old values |
| 334 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace, object_title FROM ' . $smw_relations; |
| 335 | +// $res = $dbr->query( $sql, $fname ); |
| 336 | +// if($dbr->numRows( $res ) > 0) { |
| 337 | +// $row = $dbr->fetchObject($res); |
| 338 | +// while($row) { |
| 339 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 340 | +// if ($t != NULL) { |
| 341 | +// $id = $t->getArticleID(); |
| 342 | +// $stitle = $t->getDBkey(); |
| 343 | +// $sql = "UPDATE $smw_relations SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . ", object_title = " . $dbr->addQuotes(str_replace(" ", "_", $row->object_title)) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title) . " AND object_title = " . $dbr->addQuotes($row->object_title); |
| 344 | +// $dbr->query( $sql, $fname ); |
| 345 | +// } |
| 346 | +// $row = $dbr->fetchObject($res); |
| 347 | +// } |
| 348 | +// } |
| 349 | +// |
| 350 | +// // convert old values |
| 351 | +// $sql = 'SELECT DISTINCT relation_title FROM ' . $smw_relations; |
| 352 | +// $res = $dbr->query( $sql, $fname ); |
| 353 | +// if($dbr->numRows( $res ) > 0) { |
| 354 | +// $row = $dbr->fetchObject($res); |
| 355 | +// while($row) { |
| 356 | +// $t = Title::newFromText($row->relation_title, SMW_NS_RELATION); |
| 357 | +// if ($t != NULL) { |
| 358 | +// $text = $t->getDBkey(); |
| 359 | +// $sql = "UPDATE $smw_relations SET relation_title = " . $dbr->addQuotes($text) . " WHERE relation_title = " . $dbr->addQuotes($row->relation_title) ; |
| 360 | +// $dbr->query( $sql, $fname ); |
| 361 | +// } |
| 362 | +// $row = $dbr->fetchObject($res); |
| 363 | +// } |
| 364 | +// } |
| 365 | +// |
| 366 | +// |
| 367 | +// // delete obsolete categorisation values; in the future, we will use the MediaWiki table instead |
| 368 | +// $sql = "DELETE FROM $smw_specialprops WHERE property = " . $dbr->addQuotes(SMW_SP_HAS_CATEGORY); |
| 369 | +// $res = $dbr->query( $sql, $fname ); |
| 370 | +// // extend table structure for special properties |
| 371 | +// $sql = "ALTER TABLE $smw_specialprops TYPE = innodb"; |
251 | 372 | // $dbr->query( $sql, $fname ); |
252 | | -// $sql = "ALTER TABLE $smw_specialprops CHANGE `value_string` `value_string` VARCHAR(255) NOT NULL"; |
| 373 | +// $sql = "ALTER TABLE $smw_specialprops ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
253 | 374 | // $dbr->query( $sql, $fname ); |
254 | | - |
255 | | - return "Done"; |
256 | | -} |
257 | | - |
258 | | -/** |
259 | | - * A function for updating tables from 0.3 to post 0.3 |
260 | | - */ |
261 | | -function smwfAdminUpdateTables() { |
262 | | - $dbr =& wfGetDB( DB_MASTER ); |
263 | | - |
264 | | - if ($dbr->tableExists('smw_relations') === false) { |
265 | | - smwfGetStore()->setup(); |
266 | | - return 'The database has been initialised successfully.'; |
267 | | - } |
268 | | - |
269 | | - if ($dbr->fieldExists('smw_relations', 'subject_id')) { |
270 | | - return 'This function was probably called accidentally. Your database already has the required structure.'; |
271 | | - } |
272 | | - |
273 | | - extract( $dbr->tableNames( 'smw_attributes','smw_relations','smw_specialprops' )); |
274 | | - $fname = 'SMW::AdminUpdateTables'; |
275 | | - |
276 | | - // modify table structure for attributes |
277 | | - $sql = "ALTER TABLE $smw_attributes TYPE = innodb"; |
278 | | - $dbr->query( $sql, $fname ); |
279 | | - $sql = "ALTER TABLE $smw_attributes ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
280 | | - $dbr->query( $sql, $fname ); |
281 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
282 | | - $dbr->query( $sql, $fname ); |
283 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
284 | | - $dbr->query( $sql, $fname ); |
285 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `attribute` `attribute_title` VARCHAR(255) NOT NULL"; |
286 | | - $dbr->query( $sql, $fname ); |
287 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `unit` `value_unit` VARCHAR(63)"; |
288 | | - $dbr->query( $sql, $fname ); |
289 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `datatype` `value_datatype` VARCHAR(31) NOT NULL"; |
290 | | - $dbr->query( $sql, $fname ); |
291 | | - $sql = "ALTER TABLE $smw_attributes CHANGE `value` `value_xsd` VARCHAR(255) NOT NULL"; |
292 | | - $dbr->query( $sql, $fname ); |
293 | | - $sql = "ALTER TABLE $smw_attributes ADD `value_num` DOUBLE"; |
294 | | - $dbr->query( $sql, $fname ); |
295 | | - |
296 | | - // convert old values |
297 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_attributes; |
298 | | - $res = $dbr->query( $sql, $fname ); |
299 | | - if($dbr->numRows( $res ) > 0) { |
300 | | - $row = $dbr->fetchObject($res); |
301 | | - while($row) { |
302 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
303 | | - if ($t != NULL) { |
304 | | - $id = $t->getArticleID(); |
305 | | - $stitle = $t->getDBkey(); |
306 | | - $sql = "UPDATE $smw_attributes SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
307 | | - $dbr->query( $sql, $fname ); |
308 | | - } |
309 | | - $row = $dbr->fetchObject($res); |
310 | | - } |
311 | | - } |
312 | | - |
313 | | - // create new scalar representations |
314 | | - // (luckily, for all 0.3 datatypes that have a scalar representation, the |
315 | | - // scalar version has the same PHP representation as the textual one. |
316 | | - foreach (array('int','float','geoarea','geolength') as $type) { |
317 | | - $sql = "SELECT DISTINCT value_xsd FROM $smw_attributes WHERE value_datatype = " . $dbr->addQuotes($type); |
318 | | - $res = $dbr->query( $sql, $fname ); |
319 | | - if($dbr->numRows( $res ) > 0) { |
320 | | - $row = $dbr->fetchObject($res); |
321 | | - while($row) { |
322 | | - $sql = "UPDATE $smw_attributes SET value_num = $row->value_xsd WHERE value_xsd = $row->value_xsd AND value_datatype = " . $dbr->addQuotes($type); |
323 | | - $dbr->query( $sql, $fname ); |
324 | | - |
325 | | - $row = $dbr->fetchObject($res); |
326 | | - } |
327 | | - } |
328 | | - } |
329 | | - |
330 | | - // rename attributes according to their DBkey |
331 | | - $sql = 'SELECT DISTINCT attribute_title FROM ' . $smw_attributes; |
332 | | - $res = $dbr->query( $sql, $fname ); |
333 | | - if($dbr->numRows( $res ) > 0) { |
334 | | - $row = $dbr->fetchObject($res); |
335 | | - while($row) { |
336 | | - $t = Title::newFromText($row->attribute_title, SMW_NS_ATTRIBUTE); |
337 | | - if ($t != NULL) { |
338 | | - $text = $t->getDBkey(); |
339 | | - $sql = "UPDATE $smw_attributes SET attribute_title = " . $dbr->addQuotes($text) . " WHERE attribute_title = " . $dbr->addQuotes($row->attribute_title) ; |
340 | | - $dbr->query( $sql, $fname ); |
341 | | - } |
342 | | - $row = $dbr->fetchObject($res); |
343 | | - } |
344 | | - } |
345 | | - |
346 | | - // modify table structure for relations |
347 | | - $sql = "ALTER TABLE $smw_relations TYPE = innodb"; |
348 | | - $dbr->query( $sql, $fname ); |
349 | | - $sql = "ALTER TABLE $smw_relations ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
350 | | - $dbr->query( $sql, $fname ); |
351 | | - $sql = "ALTER TABLE $smw_relations CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
352 | | - $dbr->query( $sql, $fname ); |
353 | | - $sql = "ALTER TABLE $smw_relations CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
354 | | - $dbr->query( $sql, $fname ); |
355 | | - $sql = "ALTER TABLE $smw_relations CHANGE `relation` `relation_title` VARCHAR(255) NOT NULL"; |
356 | | - $dbr->query( $sql, $fname ); |
357 | | - $sql = "ALTER TABLE $smw_relations CHANGE `objectns` `object_namespace` INT( 11 ) NOT NULL"; |
358 | | - $dbr->query( $sql, $fname ); |
359 | | - $sql = "ALTER TABLE $smw_relations CHANGE `object` `object_title` VARCHAR(255) NOT NULL"; |
360 | | - $dbr->query( $sql, $fname ); |
361 | | - |
362 | | - // convert old values |
363 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace, object_title FROM ' . $smw_relations; |
364 | | - $res = $dbr->query( $sql, $fname ); |
365 | | - if($dbr->numRows( $res ) > 0) { |
366 | | - $row = $dbr->fetchObject($res); |
367 | | - while($row) { |
368 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
369 | | - if ($t != NULL) { |
370 | | - $id = $t->getArticleID(); |
371 | | - $stitle = $t->getDBkey(); |
372 | | - $sql = "UPDATE $smw_relations SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . ", object_title = " . $dbr->addQuotes(str_replace(" ", "_", $row->object_title)) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title) . " AND object_title = " . $dbr->addQuotes($row->object_title); |
373 | | - $dbr->query( $sql, $fname ); |
374 | | - } |
375 | | - $row = $dbr->fetchObject($res); |
376 | | - } |
377 | | - } |
378 | | - |
379 | | - // convert old values |
380 | | - $sql = 'SELECT DISTINCT relation_title FROM ' . $smw_relations; |
381 | | - $res = $dbr->query( $sql, $fname ); |
382 | | - if($dbr->numRows( $res ) > 0) { |
383 | | - $row = $dbr->fetchObject($res); |
384 | | - while($row) { |
385 | | - $t = Title::newFromText($row->relation_title, SMW_NS_RELATION); |
386 | | - if ($t != NULL) { |
387 | | - $text = $t->getDBkey(); |
388 | | - $sql = "UPDATE $smw_relations SET relation_title = " . $dbr->addQuotes($text) . " WHERE relation_title = " . $dbr->addQuotes($row->relation_title) ; |
389 | | - $dbr->query( $sql, $fname ); |
390 | | - } |
391 | | - $row = $dbr->fetchObject($res); |
392 | | - } |
393 | | - } |
394 | | - |
395 | | - |
396 | | - // delete obsolete categorisation values; in the future, we will use the MediaWiki table instead |
397 | | - $sql = "DELETE FROM $smw_specialprops WHERE property = " . $dbr->addQuotes(SMW_SP_HAS_CATEGORY); |
398 | | - $res = $dbr->query( $sql, $fname ); |
399 | | - // extend table structure for special properties |
400 | | - $sql = "ALTER TABLE $smw_specialprops TYPE = innodb"; |
401 | | - $dbr->query( $sql, $fname ); |
402 | | - $sql = "ALTER TABLE $smw_specialprops ADD `subject_id` INT( 8 ) UNSIGNED NOT NULL FIRST"; |
403 | | - $dbr->query( $sql, $fname ); |
404 | | - $sql = "ALTER TABLE $smw_specialprops CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
405 | | - $dbr->query( $sql, $fname ); |
406 | | - $sql = "ALTER TABLE $smw_specialprops CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
407 | | - $dbr->query( $sql, $fname ); |
408 | | - $sql = "ALTER TABLE $smw_specialprops CHANGE `property` `property_id` SMALLINT NOT NULL"; |
409 | | - $dbr->query( $sql, $fname ); |
410 | | - $sql = "ALTER TABLE $smw_specialprops CHANGE `value` `value_string` VARCHAR(255) NOT NULL"; |
411 | | - $dbr->query( $sql, $fname ); |
412 | | - |
413 | | - |
414 | | - // convert old values |
415 | | - $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_specialprops; |
416 | | - $res = $dbr->query( $sql, $fname ); |
417 | | - if($dbr->numRows( $res ) > 0) { |
418 | | - $row = $dbr->fetchObject($res); |
419 | | - while($row) { |
420 | | - $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
421 | | - if ($t != NULL) { |
422 | | - $id = $t->getArticleID(); |
423 | | - $stitle = $t->getDBkey(); |
424 | | - $sql = "UPDATE $smw_specialprops SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
425 | | - $dbr->query( $sql, $fname ); |
426 | | - } |
427 | | - $row = $dbr->fetchObject($res); |
428 | | - } |
429 | | - } |
430 | | - |
431 | | - //add indices for new columns |
432 | | - $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `subject_id` )"; |
433 | | - $dbr->query( $sql, $fname ); |
434 | | - $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `attribute_title` )"; |
435 | | - $dbr->query( $sql, $fname ); |
436 | | - $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_num` )"; |
437 | | - $dbr->query( $sql, $fname ); |
438 | | - $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_xsd` )"; |
439 | | - $dbr->query( $sql, $fname ); |
440 | | - $sql = "ALTER TABLE $smw_relations ADD INDEX ( `subject_id` )"; |
441 | | - $dbr->query( $sql, $fname ); |
442 | | - $sql = "ALTER TABLE $smw_relations ADD INDEX ( `relation_title` )"; |
443 | | - $dbr->query( $sql, $fname ); |
444 | | - $sql = "ALTER TABLE $smw_relations ADD INDEX ( `object_title` )"; |
445 | | - $dbr->query( $sql, $fname ); |
446 | | - $sql = "ALTER TABLE $smw_specialprops ADD INDEX ( `subject_id` )"; |
447 | | - $dbr->query( $sql, $fname ); |
448 | | - |
449 | | -// //We don't drop the tables -- some denormalization is good for our performance here ... |
450 | | - // finally, drop the obsolete columns from all tables |
451 | | -// $sql = "ALTER TABLE $smw_attributes DROP `subject_namespace`"; |
| 375 | +// $sql = "ALTER TABLE $smw_specialprops CHANGE `subjectns` `subject_namespace` INT( 11 ) NOT NULL"; |
452 | 376 | // $dbr->query( $sql, $fname ); |
453 | | -// $sql = "ALTER TABLE $smw_attributes DROP `subject_title`"; |
454 | | -// $dbr->query( $sql, $fname ); |
455 | | -// $sql = "ALTER TABLE $smw_relations DROP `subject_namespace`"; |
| 377 | +// $sql = "ALTER TABLE $smw_specialprops CHANGE `subject` `subject_title` VARCHAR(255) NOT NULL"; |
456 | 378 | // $dbr->query( $sql, $fname ); |
457 | | -// $sql = "ALTER TABLE $smw_relations DROP `subject_title`"; |
| 379 | +// $sql = "ALTER TABLE $smw_specialprops CHANGE `property` `property_id` SMALLINT NOT NULL"; |
| 380 | +// $dbr->query( $sql, $fname ); |
| 381 | +// $sql = "ALTER TABLE $smw_specialprops CHANGE `value` `value_string` VARCHAR(255) NOT NULL"; |
| 382 | +// $dbr->query( $sql, $fname ); |
| 383 | +// |
| 384 | +// |
| 385 | +// // convert old values |
| 386 | +// $sql = 'SELECT DISTINCT subject_title, subject_namespace FROM ' . $smw_specialprops; |
| 387 | +// $res = $dbr->query( $sql, $fname ); |
| 388 | +// if($dbr->numRows( $res ) > 0) { |
| 389 | +// $row = $dbr->fetchObject($res); |
| 390 | +// while($row) { |
| 391 | +// $t = Title::newFromText($row->subject_title,$row->subject_namespace); |
| 392 | +// if ($t != NULL) { |
| 393 | +// $id = $t->getArticleID(); |
| 394 | +// $stitle = $t->getDBkey(); |
| 395 | +// $sql = "UPDATE $smw_specialprops SET subject_id = $id, subject_title = " . $dbr->addQuotes($stitle) . " WHERE subject_namespace = $row->subject_namespace AND subject_title = " . $dbr->addQuotes($row->subject_title); |
| 396 | +// $dbr->query( $sql, $fname ); |
| 397 | +// } |
| 398 | +// $row = $dbr->fetchObject($res); |
| 399 | +// } |
| 400 | +// } |
| 401 | +// |
| 402 | +// //add indices for new columns |
| 403 | +// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `subject_id` )"; |
| 404 | +// $dbr->query( $sql, $fname ); |
| 405 | +// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `attribute_title` )"; |
| 406 | +// $dbr->query( $sql, $fname ); |
| 407 | +// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_num` )"; |
| 408 | +// $dbr->query( $sql, $fname ); |
| 409 | +// $sql = "ALTER TABLE $smw_attributes ADD INDEX ( `value_xsd` )"; |
458 | 410 | // $dbr->query( $sql, $fname ); |
459 | | -// $sql = "ALTER TABLE $smw_specialprops DROP `subject_namespace`"; |
| 411 | +// $sql = "ALTER TABLE $smw_relations ADD INDEX ( `subject_id` )"; |
460 | 412 | // $dbr->query( $sql, $fname ); |
461 | | -// $sql = "ALTER TABLE $smw_specialprops DROP `subject_title`"; |
| 413 | +// $sql = "ALTER TABLE $smw_relations ADD INDEX ( `relation_title` )"; |
462 | 414 | // $dbr->query( $sql, $fname ); |
463 | | - |
464 | | - return "The database has been updated successfully."; |
465 | | -} |
| 415 | +// $sql = "ALTER TABLE $smw_relations ADD INDEX ( `object_title` )"; |
| 416 | +// $dbr->query( $sql, $fname ); |
| 417 | +// $sql = "ALTER TABLE $smw_specialprops ADD INDEX ( `subject_id` )"; |
| 418 | +// $dbr->query( $sql, $fname ); |
| 419 | +// |
| 420 | +// // //We don't drop the tables -- some denormalization is good for our performance here ... |
| 421 | +// // finally, drop the obsolete columns from all tables |
| 422 | +// // $sql = "ALTER TABLE $smw_attributes DROP `subject_namespace`"; |
| 423 | +// // $dbr->query( $sql, $fname ); |
| 424 | +// // $sql = "ALTER TABLE $smw_attributes DROP `subject_title`"; |
| 425 | +// // $dbr->query( $sql, $fname ); |
| 426 | +// // $sql = "ALTER TABLE $smw_relations DROP `subject_namespace`"; |
| 427 | +// // $dbr->query( $sql, $fname ); |
| 428 | +// // $sql = "ALTER TABLE $smw_relations DROP `subject_title`"; |
| 429 | +// // $dbr->query( $sql, $fname ); |
| 430 | +// // $sql = "ALTER TABLE $smw_specialprops DROP `subject_namespace`"; |
| 431 | +// // $dbr->query( $sql, $fname ); |
| 432 | +// // $sql = "ALTER TABLE $smw_specialprops DROP `subject_title`"; |
| 433 | +// // $dbr->query( $sql, $fname ); |
| 434 | +// |
| 435 | +// return "The database has been updated successfully."; |
| 436 | +// } |
466 | 437 | |
467 | 438 | ?> |