3 database conversion util
4 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
5 If you need to special settings to the ewiki database you're converting
6 to, then please insert all required define(); statements above the first
7 include line, so you can override the settings from your main config.php
12 include("t_config.php");
16 <title>database conversion (wiki engine transition)</title>
17 <link rel="stylesheet" type="text/css" href="t_config.css">
19 <body bgcolor="#ffffff" text="#000000">
20 <h1>database conversion</h1>
23 if (empty($_REQUEST["convert"])
24 and empty($_REQUEST["readtest"])
25 and empty($_REQUEST["writetest"])) {
28 This tool can be used to convert an existing (foreign) wiki database with
29 all its pages to the ewiki database and page format. It is very experimental
30 and you should consider using the export utility of your previous Wiki with
31 <tt>ewikictl</tt> afterwards to reimport it here.
36 Some of the databases you can export from need more parameters, and if you
37 transfer data from one SQL-based database scheme to another, you need to
38 have source and target tables in the same database (cannot cross-convert
39 from/to different servers/dbms). And the target tables for foreign schemes
44 You must have your target ewiki database and plugin already defined
45 in your <tt>config.php</tt>. If you want a special target, then you must
46 edit <i>this</i> script (<tt title="<?php echo __FILE__; ?>">t_convertdb.php</tt>)
47 and uncomment the other targets and insert correct define() or assignment
48 statements to make it work yourself.
53 <form action="t_convertdb.php" method="POST">
54 <table border="0" width="100%">
56 <td width="50%" valign="top" class="add-border-right">
59 <label for="from_type">database type</label>
60 <select name="from_type" id="from_type">
61 <option value="pmwiki10" selected>PmWiki 0.6.x/1.0.x</option>
62 <option value="phpwiki13">PhpWiki 1.3.x</option>
63 <option value="ewiki">configured $ewiki_db</option>
64 <option value="mysql">ErfurtWiki/MySQL</option>
65 <option value="flat">ErfurtWiki/FlatFiles</option>
66 <option value="fast">ErfurtWiki/FastFiles</option>
67 <option value="dzf2">ErfurtWiki/dzf2</option>
68 <option value="dba">ErfurtWiki/dba+dbm</option>
69 <option value="zip">ErfurtWiki/zip</option>
70 <option value="anydb">ErfurtWiki/anydb+sql</option>
71 <option value="xmlrpc">XML-RPC remote database</option>
76 <input type="checkbox" name="from_convert_markup" value="1" id="from_cnv">
77 <label for="from_cnv">convert into ewiki markup</label>
81 <small>miscellaneous database access options</small>
83 <label for="from_o1">file / directory</label>
84 <input type="text" name="from_dir" id="from_o1" size="16" title="for dzf2, zip, PmWiki">
86 <label for="from_o2">subwiki identifier</label>
87 <input type="text" name="from_subwiki" value="Main" size="7" id="from_o2" title="for PmWiki, you can only import one of the various db fragments at a time">
89 <label for="from_o3">sql table name</label>
90 <input type="text" name="from_sqltable" id="from_o3" size="10" title="for most SQL databases">
94 <input type="submit" name="readtest" value="test read access">
101 - If you access the '<b>configured $ewiki_db</b>' then you do not need to
102 set any option, because this refers to whatever you configured in your
103 'config.php' script as default database. Always the best option.
105 - For <b>PmWiki</b> you must set the 'subwiki identifier' (to "Main" at best), so
106 the conversion utility can extract one of the database fragments. You
107 also need to define the 'file/directory' setting to the exact position
108 of PmWikis 'wiki.d' or 'wikilib.d' data dirs (relative to the ewiki
109 installations base directory; and separate multiple dir names using
110 spaces, commas or colons).
116 <td width="50%" valign="top">
119 <label for="to_type">destination</label>
120 <select name="to_type" id="to_type">
121 <option value="configured" selected>configured $ewiki_db</option>
123 <!-- can't use the following without extra config:
124 <option value="mysql">ErfurtWiki/MySQL</option>
125 <option value="flat">ErfurtWiki/FlatFiles</option>
126 <option value="fast">ErfurtWiki/FastFiles</option>
127 <option value="dzf2">ErfurtWiki/dzf2</option>
128 <option value="dba">ErfurtWiki/dba+dbm</option>
129 <option value="zip">ErfurtWiki/zip</option>
130 <option value="anydb">ErfurtWiki/anydb+sql</option>
132 <option value="phpwiki13">PhpWiki 1.3.x</option>
134 <option value="mysql">old PhpWiki 1.2</option>
140 <input type="checkbox" name="to_convert_markup" value="1" id="to_cnv">
141 <label for="to_cnv">use wiki markup export filters</label>
144 <input type="checkbox" name="all_versions" value="1" checked="checked" id="all_vers">
145 <label for="all_vers">transfer all page versions/revisions</label>
148 <input type="checkbox" name="overwrite" value="1" id="to_over">
149 <label for="to_over">overwrite page versions that already exist in target database</label>
150 <small>(or copied page will simply be appended as newest)</small>
154 <input type="submit" name="convert" value="start transfer">
165 #------------------------------------------------------------------ go ---
168 #-- localize expected vars
169 $from_convert = $_REQUEST["from_convert_markup"];
170 $from_type = $_REQUEST["from_type"];
171 $to_type = $_REQUEST["to_type"];
172 $to_convert = $_REQUEST["to_convert_markup"];
173 $all_versions = $_REQUEST["all_versions"];
174 $overwrite = $_REQUEST["overwrite"];
175 $read = $_REQUEST["readtest"];
176 $write = $_REQUEST["convert"];
179 #-- database types and plugins
183 "pmwiki10" => "read_pmwiki1.php",
184 "phpwiki13" => "phpwiki13.php",
186 "flat" => "flat_files.php",
187 "fast" => "fast_files.php",
188 "dzf2" => "dzf2.php",
190 "anydb" => "anydb.php",
191 "xmlrpc" => "xmlrpc.php",
195 "mysql" => "ewiki_database_mysql",
196 "pmwiki10" => "ewiki_database_pmwiki",
197 "phpwiki13" => "ewiki_database_phpwiki13",
198 "dba" => "ewiki_database_dba",
199 "flat" => "ewiki_database_files",
200 "fast" => "ewiki_database_files",
201 "dzf2" => "ewiki_database_DirZlibFiles2",
202 "zip" => "ewiki_database_zip",
203 "anydb" => "ewiki_database_anydb",
204 "xmlrpc" => "ewiki_database_xmlrpc",
206 $t_init = array( // auto-create database scheme (::INIT)
215 $t_in_convert = array(
216 "phpwiki13" => array("phpwiki.php"),
217 "usemod" => array("usemod.php"),
219 $t_out_convert = array(
220 "phpwiki13" => array(), // nothing ready yet
224 define("PHPWIKI13_WRITEACCESS", 1);
228 if ($script = $t_scr[$from_type]) include_once("plugins/db/$script");
229 $FROM = instantiate_db_api($t_api[$from_type]);
230 echo "- source database module loaded/instantiated<br>\n";
234 if ($script = $t_scr[$from_to]) include_once("plugins/db/$script");
235 $DEST = instantiate_db_api($t_api[$to_type]);
236 echo "- target database module loaded/instantiated<br>\n";
239 #-- set up options for $FROM database
240 if ($grp = $_REQUEST["from_subwiki"]) {
243 if ($dir = $_REQUEST["from_dir"]) {
246 $FROM->dirs = preg_split("/[\s:;,]+/", $dir);
248 if ($tbl = $_REQUEST["from_sqltable"]) {
254 #-- load markup conversion scripts
255 $ewiki_plugins["format_source"] = array(); // kill default ones
257 if ($scr_a = $t_in_convert[$from_type]) {
258 foreach ($scr_a as $script) {
259 echo "- loading markup conversion module '$script'<br>\n";
260 include_once("../plugins/markup/$script");
263 $ewiki_plugins["markup_convert"] = array();
265 if ($scr_a = $t_out_convert[$from_type]) {
266 foreach ($scr_a as $script) {
267 echo "- loading markup export plugin '$script'<br>\n";
268 include_once("plugins/markup/$script");
273 #-- creating ewiki database
274 if ($t_init[$to_type]) {
275 echo "- <u>creating</u> destination target database scheme/whatever...<br>\n";
279 echo "- cannot create database scheme for that target type [SKIPPED]<br>\n";
284 #-- start --------------------------------------------------------
285 echo "\n\n<br>\n<h4>copying pages:</h4>\n\n";
287 $result = $FROM->GETALL(array("flags", "version")); // not "id"!, we're doing raw access here, and need to obey the internal rules
288 while ($row = $result->get()) {
290 #-- run forever, if necessary
291 set_time_limit(2000);
295 echo htmlentities("$id");
299 $data = $FROM->GET($id);
305 #-- copy all page versions
306 for ($ver=$data["version"]; $version>=1; $version--) {
307 if ($data = $FROM->GET($id, $version)) {
308 markup_convert($data);
309 if ($DEST->WRITE($data, $overwrite)) {
322 #-- check for existence of current page
323 $old = $DEST->GET($id);
324 if (!$old["version"]) {
325 $data["version"] = 1;
327 elseif ($overwrite && $old) {
328 $data["version"] = $old["version"] + 1;
334 markup_convert($data);
335 if ($DEST->WRITE($data)) {
336 echo "[" . $data["version"] . "]";
339 echo "<b>[ERROR]</b>";
349 echo "<br><br>done\n";
358 #----------------------------------------------------------- utility code ---
363 #-- rewriting of page content to match target wiki engines markup
364 function markup_convert() {
365 global $ewiki_plugins;
368 if ($pf_a = $ewiki_plugins["format_source"]) foreach ($pf_a as $pf) {
369 $pf($data["content"]);
373 if ($pf_a = $ewiki_plugins["markup_convert"]) foreach ($pf_a as $pf) {
374 $pf($data["content"]);
377 #-- update {refs} (helpful for PmWiki, which does not have an equivalent)
378 ewiki_scan_wikiwords($data["content"], $ewiki_links, "_STRIP_EMAIL=1");
379 $data["refs"] = "\n\n".implode("\n", array_keys($ewiki_links))."\n\n";
386 function read_test() {
388 echo "- now performing only an<br>\n<br>\n<h4>read test</h4>\n";
389 $all = $FROM->GETALL(array("version","flags"));
391 echo "- following pages were found in that database:<br>\n";
392 while ($row = $all->get()) {
393 echo $row["id"] . "[" . $row["version"] . "], ";
394 $list[] = $row["id"];
396 echo "\n<br><br>\n<h4>randomly chosen entry</h4>\n";
397 $id = $list[rand(0,count($list)-1)];
398 $row = $FROM->GET($id);
401 echo "</pre>\n\n<br>\n</body></html>";
407 #-- create database object (or simply return reference to default $ewiki_db)
408 function & instantiate_db_api($class) {
410 if ((!$class) || ($class=="$")) {
411 if (!isset($ewiki_db)) {
412 $ewiki_db = & new ewiki_database_mysql();