Index: trunk/extensions/Wikidata/util/copy.php |
— | — | @@ -1,4 +1,13 @@ |
2 | 2 | <?php |
| 3 | + |
| 4 | +# (C) 2007 Alan Smithee (licensed under the GPL v. 3, or any later version, though you're not likely to care) |
| 5 | +# throwaway rapid prototype to copy defined meanings between tables. |
| 6 | +# I didn't write this, nobody saw me, you can't prove a thing! |
| 7 | +# Actually somewhat easier than fighting through multiple layers of |
| 8 | +# code in the recordsets for now. |
| 9 | +# probably will refactor this code into ulta-pretty helpers or |
| 10 | +# other recordset improvements. |
| 11 | +# |
3 | 12 | header("Content-type: text/html; charset=UTF-8"); |
4 | 13 | |
5 | 14 | define('MEDIAWIKI', true ); |
— | — | @@ -150,12 +159,62 @@ |
151 | 160 | writeSyntrans($syntrans, $newdmid, $newexpid, $dc2); |
152 | 161 | } |
153 | 162 | |
| 163 | +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; |
| 173 | +} |
154 | 174 | |
| 175 | +/* some coy&paste happening here, might want to tidy even before we |
| 176 | +* toss this throwaway code*/ |
| 177 | +function write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2) { |
| 178 | + $target_table=mysql_real_escape_string("${dc2}_expression_ns"); |
| 179 | + $target_expid1=dupobject($expression["expression_id"], $target_table, $dc1, $dc2); |
| 180 | + var_dump($target_expid1); |
| 181 | + $save_expression=$expression; |
| 182 | + $save_expression["expression_id"]=$target_expid1; |
| 183 | + mysql_insert_assoc($target_table,$save_expression); |
| 184 | + dupsyntrans( |
| 185 | + $dc1, |
| 186 | + $dc2, |
| 187 | + $src_dmid, |
| 188 | + $expression["expression_id"], |
| 189 | + $dst_dmid, |
| 190 | + $save_expression["expression_id"] |
| 191 | + ); |
| 192 | + |
| 193 | +} |
| 194 | + |
| 195 | +function write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2) { |
| 196 | + var_dump($syntranses); |
| 197 | + print "<br>\nExpressions:"; |
| 198 | + foreach ($syntranses as $syntrans) { |
| 199 | + $expression=expression($syntrans["expression_id"],$dc1); |
| 200 | + print $expression["spelling"].";"; |
| 201 | + write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2); |
| 202 | + # ^- which incidentally also dups the syntrans |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | +function dup_syntranses($src_dmid, $dst_dmid, $dc1, $dc2) { |
| 207 | + $syntranses=get_syntranses($src_dmid, $dc1); |
| 208 | + write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2); |
| 209 | +} |
| 210 | + |
155 | 211 | $start=stopwatch(); |
156 | 212 | |
157 | 213 | $dmid=$_REQUEST['dmid']; |
158 | 214 | $dc1=$_REQUEST['dc1']; |
159 | 215 | $dc2=$_REQUEST['dc2']; |
| 216 | + |
| 217 | + |
| 218 | +# dm |
160 | 219 | $dmid_esc=mysql_real_escape_string($dmid); |
161 | 220 | |
162 | 221 | echo $dmid_esc; |
— | — | @@ -171,6 +230,7 @@ |
172 | 231 | $defined_meaning=mysql_fetch_assoc($result); |
173 | 232 | var_dump($defined_meaning); |
174 | 233 | |
| 234 | +# bit of exp here too (defnitely need to tidy) |
175 | 235 | $defining_expression=expression($defined_meaning["expression_id"], $dc1); |
176 | 236 | var_dump($defining_expression); |
177 | 237 | |
— | — | @@ -180,6 +240,7 @@ |
181 | 241 | $save_meaning=$defined_meaning; |
182 | 242 | $save_meaning["defined_meaning_id"]=$target_dmid; |
183 | 243 | |
| 244 | +# exp |
184 | 245 | $target_table=mysql_real_escape_string("${dc2}_expression_ns"); |
185 | 246 | $target_expid1=dupobject($defining_expression["expression_id"], $target_table, $dc1, $dc2); |
186 | 247 | var_dump($target_expid1); |
— | — | @@ -187,9 +248,12 @@ |
188 | 249 | $save_expression["expression_id"]=$target_expid1; |
189 | 250 | mysql_insert_assoc($target_table,$save_expression); |
190 | 251 | |
| 252 | +# and insert that info into the dm +save it |
191 | 253 | $save_meaning["expression_id"]=$target_expid1; |
192 | 254 | mysql_insert_assoc($dm_target_table, $save_meaning); |
193 | 255 | |
| 256 | +# the defining expression is also in syntrans, |
| 257 | +# so this might be redundant. |
194 | 258 | dupsyntrans( |
195 | 259 | $dc1, |
196 | 260 | $dc2, |
— | — | @@ -211,6 +275,13 @@ |
212 | 276 | ); |
213 | 277 | createConceptMapping($concepts); |
214 | 278 | |
| 279 | +dup_syntranses( |
| 280 | + $defined_meaning["defined_meaning_id"], |
| 281 | + $save_meaning["defined_meaning_id"], |
| 282 | + $dc1, |
| 283 | + $dc2 |
| 284 | +); |
| 285 | + |
215 | 286 | echo" |
216 | 287 | <hr> |
217 | 288 | <div align=\"right\"> |