-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrator.php
350 lines (319 loc) · 16.1 KB
/
migrator.php
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<html>
<head>
<title>Database migration for BibSonomy - ext_bibsonomy to ext_bibsonomy_csl</title>
</head>
<body>
<h1>Database migration for BibSonomy - ext_bibsonomy to ext_bibsonomy_csl</h1>
<p>
<form action="" method="post">
<p>User: <input name="user" value="<?php echo @$_POST["user"]; ?>" type=text></p>
<p>Pass: <input name="pass" value="<?php echo @$_POST["pass"]; ?>" type=password></p>
<p>Host: <input name="host" value="<?php echo @$_POST["host"]; ?>" type=text></p>
<p>Datenbank: <input name="db" value="<?php echo @$_POST["db"]; ?>" type=text></p>
<button type=submit>Migrate</button></form>
</p>
<?php
/*$source = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="bib_general">
<language index="lDEF">
<field index="bib_content">
<value index="vDEF">/user/butonic</value>
</field>
<field index="bib_include_publications">
<value index="vDEF">1</value>
</field>
<field index="bib_publication_count">
<value index="vDEF">500</value>
</field>
<field index="bib_include_tagcloud">
<value index="vDEF">1</value>
</field>
<field index="bib_publications_width">
<value index="vDEF">100%</value>
</field>
<field index="bib_tagcloud_width">
<value index="vDEF">100%</value>
</field>
</language>
</sheet>
<sheet index="bib_tagcloud">
<language index="lDEF">
<field index="bib_tagcloud_size">
<value index="vDEF">100</value>
</field>
<field index="bib_show_relatedtags">
<value index="vDEF">0</value>
</field>
<field index="bib_tagcloud_blacklist">
<value index="vDEF"></value>
</field>
</language>
</sheet>
<sheet index="bib_layout">
<language index="lDEF">
<field index="bib_layout_type">
<value index="vDEF">/layout/custom</value>
</field>
<field index="bib_show_quickbar">
<value index="vDEF">0</value>
</field>
<field index="bib_select_entrytype">
<value index="vDEF">all</value>
</field>
<field index="bib_update_layouts">
<value index="vDEF">0</value>
</field>
</language>
</sheet>
<sheet index="bib_login">
<language index="lDEF">
<field index="bib_login_name">
<value index="vDEF">test.user</value>
</field>
<field index="bib_user_password">
<value index="vDEF">f5cc5te32fb8f13e0k8d6ee37bfe25ff</value>
</field>
</language>
</sheet>
<sheet index="bib_misc">
<language index="lDEF">
<field index="bib_decode_iso">
<value index="vDEF">0</value>
</field>
<field index="bib_show_metadata">
<value index="vDEF">0</value>
</field>
<field index="bib_server_url">
<value index="vDEF">http://www.bibsonomy.org</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>';*/
/*
source database columns: tt_content: pi_flexform;
target database columns: tt_content: tx_extbibsonomy_login_name, tx_extbibsonomy_api_key, tx_extbibsonomy_server_url, tx_extbibsonomy_export_layout,
tx_extbibsonomy_export_content, tx_extbibsonomy_decode_iso, tx_extbibsonomy_include_tagcloud, tx_extbibsonomy_include_publications,
tx_extbibsonomy_tagcloud_size, tx_extbibsonomy_related_tags, tx_extbibsonomy_meta_output;
*/
if(empty($_POST['host']) || empty($_POST['user']) || empty($_POST['pass']) || empty($_POST['db'])) exit;
$con = mysql_connect(@$_POST["host"],@$_POST["user"],@$_POST["pass"])
or die('Invalid/No data sent!');
// select a database:
mysql_select_db(@$_POST["db"])
or die('Could not select database!');
$result = mysql_query("SELECT uid, pi_flexform FROM tt_content WHERE list_type='ext_bibsonomy_pi1' AND deleted=0")
or die('Error: ' . mysql_error());
echo "<p><b>All database entries have been converted. Don't forget to clear the cache.</b></p>";
while ($row = mysql_fetch_array($result)) {
$typ = "Unknown";
//$newtype = "'"; //in emergency, break the script instead of the database
$dataArr = Main($row['pi_flexform']);
//print_r($dataArr);
//print_r($sheets);
if ($dataArr["include_tagcloud"] == 1) {
//require_once('tagcloud.php');
$typ = 'Tagcloud'; $newtype = 'extbibsonomycsl_tagcloud';
$export = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="bib_general">
<language index="lDEF">
<field index="settings.bib_tag_content_key">
<value index="vDEF">' . $dataArr["content_key"] . '</value>
</field>
<field index="settings.bib_tag_content_value">
<value index="vDEF">' . $dataArr["content_value"] . '</value>
</field>
<field index="settings.bib_tags">
<value index="vDEF"></value>
</field>
<field index="settings.bib_blacklist_tags">
<value index="vDEF">' . $dataArr["tagcloud_blacklist"] . '</value>
</field>
<field index="settings.bib_tag_maxcount">
<value index="vDEF">' . $dataArr["tagcloud_size"] . '</value>
</field>
</language>
</sheet>
<sheet index="bib_login">
<language index="lDEF">
<field index="settings.bib_tag_server">
<value index="vDEF">' . $dataArr["server_url"] . '/api</value>
</field>
<field index="settings.bib_tag_login_name">
<value index="vDEF">' . $dataArr["login_name"] . '</value>
</field>
<field index="settings.bib_tag_api_key">
<value index="vDEF">' . $dataArr["api_key"] . '</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>';
} else {
$export = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="bib_general">
<language index="lDEF">
<field index="settings.bib_content_key">
<value index="vDEF">' . $dataArr["content_key"] . '</value>
</field>
<field index="settings.bib_content_value">
<value index="vDEF">' . $dataArr["content_value"] . '</value>
</field>
<field index="settings.bib_tags">
<value index="vDEF"></value>
</field>
<field index="settings.bib_unselect_tags">
<value index="vDEF"></value>
</field>
<field index="settings.bib_search">
<value index="vDEF"></value>
</field>
<field index="settings.bib_maxcount">
<value index="vDEF">' . $dataArr["publication_count"] . '</value>
</field>
<field index="settings.bib_custom_api_query">
<value index="vDEF"></value>
</field>
</language>
</sheet>
<sheet index="bib_ordering">
<language index="lDEF">
<field index="settings.bib_grouping">
<value index="vDEF">none</value>
</field>
<field index="settings.bib_display_anchors">
<value index="vDEF">0</value>
</field>
<field index="settings.bib_sorting">
<value index="vDEF">year</value>
</field>
<field index="settings.bib_sorting_order">
<value index="vDEF">desc</value>
</field>
<field index="settings.bib_type_order">
<value index="vDEF"></value>
</field>
</language>
</sheet>
<sheet index="bib_layout">
<language index="lDEF">
<field index="settings.bib_stylesheet">
<value index="vDEF">http://www.zotero.org/styles/acs-chemical-biology</value>
</field>
<field index="settings.bib_ownstylesheet">
<value index="vDEF"></value>
</field>
<field index="settings.bib_link_abstract">
<value index="vDEF">0</value>
</field>
<field index="settings.bib_link_bibtex">
<value index="vDEF">0</value>
</field>
<field index="settings.bib_link_endnote">
<value index="vDEF">0</value>
</field>
<field index="settings.bib_link_url">
<value index="vDEF">0</value>
</field>
<field index="settings.bib_link_doc">
<value index="vDEF">nothing</value>
</field>
<field index="settings.bib_css_attribute_for_list_item">
<value index="vDEF">
.bibsonomy_publications {
font-size: 1.0em;
}
.bibsonomy_publications span.citeproc-title {
display: block;
text-decoration: none;
font-weight: bold;
font-size: 1.1em;
}
.bibsonomy_publications span.biblink {
display: block;
font-size: 1.1em;
line-height: 2em;
margin-right: 1.5em;
float: left;
}
.citeproc-collection-title {
font-style:italic;
}
</value>
</field>
</language>
</sheet>
<sheet index="bib_login">
<language index="lDEF">
<field index="settings.bib_server">
<value index="vDEF">' . $dataArr["server_url"] . '/</value>
</field>
<field index="settings.bib_login_name">
<value index="vDEF">' . $dataArr["login_name"] . '</value>
</field>
<field index="settings.bib_api_key">
<value index="vDEF">' . $dataArr["api_key"] . '</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>';
/*require_once('publications.php');*/ $typ = 'Publikationsliste'; $newtype = 'extbibsonomycsl_publicationlist';}
$uid = $row['uid'];
$result2 = mysql_query("UPDATE tt_content SET pi_flexform='$export', list_type='$newtype' WHERE uid=$uid") or die('Error: ' . mysql_error());
echo '<textarea readonly cols="110" rows="100">' . $export . '</textarea>';
//1. change extension key in db to the one matching
//2. require_once->flexform
//3. pi_flexform->db
echo "<p>Entry above: $typ.</p>";
}
function copyFromTo($string, $start, $end) {
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
function getMainPart($input) {
return copyFromTo($input, "<data>", "</data>");
}
function getSheet($input, $label) {
return copyFromTo($input, "<sheet index=\"bib_$label\">", "</sheet>");
}
function getField($input, $label) {
return copyFromTo($input, "<field index=\"bib_$label\">", "</field>");
}
function getFieldValue($input) {
return copyFromTo($input, "<value index=\"vDEF\">", "</value>");
}
function removeLang($input) {
return copyFromTo($input, "<language index=\"lDEF\">", "</language>");
}
function Main($source) {
$source = getMainPart($source);
$sheets = removeLang(getSheet($source, "general"));
$sheets .= removeLang(getSheet($source, "tagcloud"));
$sheets .= removeLang(getSheet($source, "layout"));
$sheets .= removeLang(getSheet($source, "login"));
$sheets .= removeLang(getSheet($source, "misc"));
$dataKeys = array('content', 'include_tagcloud', 'publication_count', 'include_publications', 'tagcloud_width', 'publications_width', 'show_relatedtags', 'tagcloud_blacklist', 'layout_type', 'show_quickbar', 'select_entrytype', 'update_layouts', 'login_name', 'user_password' => 'api_key', 'server_url', 'show_metadata', 'decode_iso', 'tagcloud_size',);
foreach($dataKeys as $oldkey => $newkey) {
if (is_numeric($oldkey)) $oldkey = $newkey;
//remove => easy template//$dataArr['settings.bib_' . $newkey] = getFieldValue(getField($sheets, $oldkey));
$dataArr[$newkey] = getFieldValue(getField($sheets, $oldkey));
}
//adjustment for new format
$dataArr["content_key"] = copyFromTo($dataArr["content"], '/', '/');
$dataArr["content_value"] = copyFromTo(getField($sheets, 'content'), $dataArr["content_key"] . '/' , '<');
return $dataArr;
}
?>
</body>
</html>