Index: trunk/extensions/Wikidata/util/copy.php |
— | — | @@ -36,49 +36,44 @@ |
37 | 37 | return ((float)$usec + (float)$sec); |
38 | 38 | } |
39 | 39 | |
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 | +} |
47 | 45 | |
48 | | - $result = mysql_query($query)or die ("error ".mysql_error()); |
49 | 46 | |
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); |
52 | 51 | } |
53 | 52 | |
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; |
59 | 55 | $result = mysql_query($query)or die ("error ".mysql_error()); |
60 | | - echo "bla\n"; |
61 | 56 | $data= mysql_fetch_assoc($result); |
62 | | - var_dump($data); |
63 | | - return $data["maxdm"]+1; |
| 57 | + return $data; |
64 | 58 | } |
65 | 59 | |
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) { |
70 | 61 | $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; |
74 | 67 | } |
75 | 68 | |
| 69 | + |
| 70 | +function expression($expression_id, $dc1) { |
| 71 | + return getrow($dc1, "expression_ns", "WHERE expression_id=$expression_id"); |
| 72 | +} |
| 73 | + |
76 | 74 | function readobject($id, $dc1) { |
77 | 75 | $objects=mysql_real_escape_string("${dc1}_objects"); |
78 | 76 | $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"); |
83 | 78 | } |
84 | 79 | |
85 | 80 | function writeobject($object,$dc2,$table) { |
— | — | @@ -94,8 +89,6 @@ |
95 | 90 | $newid=writeobject($object,$dc2, $table); |
96 | 91 | return $newid; |
97 | 92 | } |
98 | | - |
99 | | - |
100 | 93 | /** |
101 | 94 | * inverse of mysql_fetch_assoc |
102 | 95 | /* see: http://www.php.net/mysql_fetch_assoc (Comment by R. Bradly, 14-Sep-2006) |
— | — | @@ -136,12 +129,7 @@ |
137 | 130 | } |
138 | 131 | |
139 | 132 | 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"); |
146 | 134 | } |
147 | 135 | |
148 | 136 | function writeSyntrans($syntrans, $newdmid, $newexpid, $dc2) { |
— | — | @@ -160,17 +148,10 @@ |
161 | 149 | } |
162 | 150 | |
163 | 151 | 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"); |
173 | 153 | } |
174 | 154 | |
| 155 | + |
175 | 156 | /* some coy&paste happening here, might want to tidy even before we |
176 | 157 | * toss this throwaway code*/ |
177 | 158 | function write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2) { |
— | — | @@ -193,7 +174,7 @@ |
194 | 175 | |
195 | 176 | function write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2) { |
196 | 177 | var_dump($syntranses); |
197 | | - print "<br>\nExpressions:"; |
| 178 | + print "<br>\nExpressions:"; |
198 | 179 | foreach ($syntranses as $syntrans) { |
199 | 180 | $expression=expression($syntrans["expression_id"],$dc1); |
200 | 181 | print $expression["spelling"].";"; |
— | — | @@ -207,6 +188,49 @@ |
208 | 189 | write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2); |
209 | 190 | } |
210 | 191 | |
| 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 | + |
211 | 235 | $start=stopwatch(); |
212 | 236 | |
213 | 237 | $dmid=$_REQUEST['dmid']; |
— | — | @@ -247,9 +271,10 @@ |
248 | 272 | $save_expression=$defining_expression; |
249 | 273 | $save_expression["expression_id"]=$target_expid1; |
250 | 274 | 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"]); |
251 | 278 | |
252 | | -# and insert that info into the dm +save it |
253 | | -$save_meaning["expression_id"]=$target_expid1; |
254 | 279 | mysql_insert_assoc($dm_target_table, $save_meaning); |
255 | 280 | |
256 | 281 | # the defining expression is also in syntrans, |
— | — | @@ -282,6 +307,7 @@ |
283 | 308 | $dc2 |
284 | 309 | ); |
285 | 310 | |
| 311 | + |
286 | 312 | echo" |
287 | 313 | <hr> |
288 | 314 | <div align=\"right\"> |