r25395 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25394‎ | r25395 | r25396 >
Date:22:42, 1 September 2007
Author:kim
Status:old
Tags:
Comment:

Hmph, copying definitions was trickier than I thought.
This DB is byzantine :-P
Modified paths:
  • /trunk/extensions/Wikidata/util/copy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/util/copy.php
@@ -36,49 +36,44 @@
3737 return ((float)$usec + (float)$sec);
3838 }
3939
40 -function expression($expression_id, $dc1) {
41 - $expression=mysql_real_escape_string("${dc1}_expression_ns");
42 - $query=
43 - "SELECT *
44 - FROM $expression
45 - WHERE expression_id=$expression_id";
46 - echo $query;
 40+function getrow($dc, $table, $where) {
 41+ $target_table=mysql_real_escape_string("${dc}_${table}");
 42+ $query="SELECT * FROM $target_table ".$where;
 43+ return doquery($query);
 44+}
4745
48 - $result = mysql_query($query)or die ("error ".mysql_error());
4946
50 - $dmdata= mysql_fetch_assoc($result);
51 - return $dmdata;
 47+function getrows($dc, $table, $where) {
 48+ $target_table=mysql_real_escape_string("${dc}_${table}");
 49+ $query="SELECT * FROM $target_table ".$where;
 50+ return do_multirow_query($query);
5251 }
5352
54 -/**@deprecated , use dupobject*/
55 -function new_dm_id($dc2) {
56 - $defined_meaning=mysql_real_escape_string("${dc2}_defined_meaning");
57 - $query="SELECT max(defined_meaning_id) as maxdm from $defined_meaning";
58 - echo "$query\n";
 53+function doquery($query) {
 54+ echo $query;
5955 $result = mysql_query($query)or die ("error ".mysql_error());
60 - echo "bla\n";
6156 $data= mysql_fetch_assoc($result);
62 - var_dump($data);
63 - return $data["maxdm"]+1;
 57+ return $data;
6458 }
6559
66 -/**@deprecated , use dupobject*/
67 -function new_exp_id($dc2) {
68 - $expression_ns=mysql_real_escape_string("${dc2}_expression_ns");
69 - $query="SELECT max(expression_id) as maxexp from $expression_ns";
 60+function do_multirow_query($query) {
7061 $result = mysql_query($query)or die ("error ".mysql_error());
71 - $data= mysql_fetch_assoc($result);
72 - var_dump($data);
73 - return $data["maxexp"]+1;
 62+ $items=array();
 63+ while ($nextexp=mysql_fetch_assoc($result)) {
 64+ $items[]=$nextexp;
 65+ }
 66+ return $items;
7467 }
7568
 69+
 70+function expression($expression_id, $dc1) {
 71+ return getrow($dc1, "expression_ns", "WHERE expression_id=$expression_id");
 72+}
 73+
7674 function readobject($id, $dc1) {
7775 $objects=mysql_real_escape_string("${dc1}_objects");
7876 $query="SELECT * from $objects where object_id=$id";
79 - $result = mysql_query($query)or die ("error ".mysql_error());
80 - $data= mysql_fetch_assoc($result);
81 - var_dump($data);
82 - return $data;
 77+ return getrow($dc1, "objects", "WHERE object_id=$id");
8378 }
8479
8580 function writeobject($object,$dc2,$table) {
@@ -94,8 +89,6 @@
9590 $newid=writeobject($object,$dc2, $table);
9691 return $newid;
9792 }
98 -
99 -
10093 /**
10194 * inverse of mysql_fetch_assoc
10295 /* see: http://www.php.net/mysql_fetch_assoc (Comment by R. Bradly, 14-Sep-2006)
@@ -136,12 +129,7 @@
137130 }
138131
139132 function getOldSyntrans($dc1, $dmid, $expid) {
140 - $syntrans_table=mysql_real_escape_string("${dc1}_syntrans");
141 - $query="SELECT * from $syntrans_table where defined_meaning_id=$dmid and expression_id=$expid";
142 - $result = mysql_query($query)or die ("error ".mysql_error());
143 - $data= mysql_fetch_assoc($result);
144 - var_dump($data);
145 - return $data;
 133+ return getrow($dc1, "syntrans", "where defined_meaning_id=$dmid and expression_id=$expid");
146134 }
147135
148136 function writeSyntrans($syntrans, $newdmid, $newexpid, $dc2) {
@@ -160,17 +148,10 @@
161149 }
162150
163151 function get_syntranses($dmid, $dc1) {
164 - $syntranses=array();
165 - $syntrans_table=mysql_real_escape_string("${dc1}_syntrans");
166 - $query="SELECT * from $syntrans_table where defined_meaning_id=$dmid";
167 - $result = mysql_query($query)or die ("error ".mysql_error());
168 - var_dump($result);
169 - while ($nextexp=mysql_fetch_assoc($result)) {
170 - $syntranses[]=$nextexp;
171 - }
172 - return $syntranses;
 152+ return getrows($dc1, "syntrans", "where defined_meaning_id=$dmid");
173153 }
174154
 155+
175156 /* some coy&paste happening here, might want to tidy even before we
176157 * toss this throwaway code*/
177158 function write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2) {
@@ -193,7 +174,7 @@
194175
195176 function write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2) {
196177 var_dump($syntranses);
197 - print "<br>\nExpressions:";
 178+ print "<br>\nExpressions:";
198179 foreach ($syntranses as $syntrans) {
199180 $expression=expression($syntrans["expression_id"],$dc1);
200181 print $expression["spelling"].";";
@@ -207,6 +188,49 @@
208189 write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2);
209190 }
210191
 192+function read_translated_content($dc1,$tcid) {
 193+ return getrows($dc1,"translated_content","where translated_content_id=$tcid");
 194+}
 195+
 196+function write_translated_content($dc1, $dc2, $tcid, $content) {
 197+ $target_table=mysql_real_escape_string("${dc2}_translated_content");
 198+ var_dump($content);
 199+ $content["translated_content_id"]=$tcid;
 200+ $content["text_id"]=dup_text($dc1, $dc2, $content["text_id"]);
 201+ var_dump($content);
 202+ mysql_insert_assoc($target_table, $content);
 203+}
 204+
 205+
 206+function dup_translated_content($dc1, $dc2, $tcid) {
 207+ $translated_content=read_translated_content($dc1, $tcid);
 208+ $target_table=mysql_real_escape_string("${dc2}_translated_content");
 209+ $new_tcid=dupobject($tcid, $target_table, $dc1, $dc2);
 210+ foreach ($translated_content as $item) {
 211+ write_translated_content($dc1, $dc2, $new_tcid, $item);
 212+ }
 213+ return $new_tcid;
 214+}
 215+
 216+function read_text($dc1,$text_id) {
 217+ return getrow($dc1,"text","where text_id=$text_id");
 218+}
 219+
 220+function write_text($dc2,$text) {
 221+ unset($text["text_id"]);
 222+ # inconsistent, insert_assoc should accept dc, table
 223+ $target_table=mysql_real_escape_string("${dc2}_text");
 224+ mysql_insert_assoc($target_table,$text);
 225+ return mysql_insert_id();
 226+}
 227+
 228+function dup_text($dc1, $dc2, $text_id) {
 229+ $text=read_text($dc1, $text_id);
 230+ $id=write_text($dc2, $text);
 231+ return $id;
 232+}
 233+
 234+
211235 $start=stopwatch();
212236
213237 $dmid=$_REQUEST['dmid'];
@@ -247,9 +271,10 @@
248272 $save_expression=$defining_expression;
249273 $save_expression["expression_id"]=$target_expid1;
250274 mysql_insert_assoc($target_table,$save_expression);
 275+# and insert that info into the dm
 276+$save_meaning["expression_id"]=$target_expid1;
 277+$save_meaning["meaning_text_tcid"]=dup_translated_content($dc1, $dc2, $defined_meaning["meaning_text_tcid"]);
251278
252 -# and insert that info into the dm +save it
253 -$save_meaning["expression_id"]=$target_expid1;
254279 mysql_insert_assoc($dm_target_table, $save_meaning);
255280
256281 # the defining expression is also in syntrans,
@@ -282,6 +307,7 @@
283308 $dc2
284309 );
285310
 311+
286312 echo"
287313 <hr>
288314 <div align=\"right\">

Status & tagging log