r25535 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25534‎ | r25535 | r25536 >
Date:10:29, 5 September 2007
Author:kim
Status:old
Tags:
Comment:
Copy safety implemented, same UUID won't be copied twice.

> Recursive copying should now be safe-ish, so can expect new functionalities
wrt recursive copying to appear soon.

!flaws:
* Translated content is treated as a set, so won't do merging
* I'm stealing conceptmapping from the wikidataapi version.
Ideally that code should be made copy-safe too, though there
is little harm per-se (copies <100 bytes of superfluous data)

!! Not tested. sent on the basis of "if it runs, ship it"
Modified paths:
  • /trunk/extensions/Wikidata/util/copy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/util/copy.php
@@ -203,6 +203,9 @@
204204 function dupSyntrans($dc1, $dc2, $olddmid, $oldexpid, $newdmid, $newexpid) {
205205 $syntrans=getOldSyntrans($dc1, $olddmid, $oldexpid);
206206 $copier=new ObjectCopier($syntrans["syntrans_sid"], "syntrans", $dc1, $dc2);
 207+ if ($copier->already_there()) {
 208+ return;
 209+ }
207210 $newid=$copier->dup();
208211 $syntrans["syntrans_sid"]=$newid;
209212 writeSyntrans($syntrans, $newdmid, $newexpid, $dc2);
@@ -219,11 +222,12 @@
220223
221224 $copier=new ObjectCopier($expression["expression_id"], "expression_ns", $dc1, $dc2);
222225 $target_expid1=$copier->dup();
223 - var_dump($target_expid1);
224226 $save_expression=$expression;
225227 $save_expression["expression_id"]=$target_expid1;
226228 $target_table=mysql_real_escape_string("${dc2}_expression_ns");
227 - mysql_insert_assoc($target_table,$save_expression);
 229+ if (!($copier->already_there())) {
 230+ mysql_insert_assoc($target_table,$save_expression);
 231+ }
228232 dupsyntrans(
229233 $dc1,
230234 $dc2,
@@ -270,6 +274,12 @@
271275 $target_table=mysql_real_escape_string("translated_content");
272276 $copier=new ObjectCopier($tcid, $target_table, $dc1, $dc2);
273277 $new_tcid=$copier->dup();
 278+ # note the issue where translated content is added later:
 279+ # since all translated content for a single dm
 280+ # shares one UUID, we can't check for that eventuality.
 281+ if ($copier->already_there()) {
 282+ return;
 283+ }
274284 foreach ($translated_content as $item) {
275285 write_translated_content($dc1, $dc2, $new_tcid, $item);
276286 }
@@ -301,6 +311,9 @@
302312 function write_meaning_relation($dc1, $dc2, $new_dmid, $relation) {
303313 $copier=new ObjectCopier($relation["relation_id"], "meaning_relations", $dc1, $dc2);
304314 $relation["relation_id"]=$copier->dup;
 315+ if ($copier->already_there()) {
 316+ return;
 317+ }
305318 $relation["meaning1_mid"]=$new_dmid;
306319 $relation["meaning2_mid"]=dup_defined_meaning($relation["meaning2_mid"],$dc1, $dc2);
307320 }
@@ -352,25 +365,29 @@
353366 $this->save_meaning=$this->defined_meaning;
354367 $this->save_meaning["defined_meaning_id"]=$target_dmid;
355368
356 - # exp
357 - $target_table=mysql_real_escape_string("${dc2}_expression_ns");
358 - $exp_copier=new ObjectCopier($defining_expression["expression_id"], $target_table, $dc1, $dc2);
359 - $target_expid1=$exp_copier->dup();
360 - var_dump($target_expid1);
361 - $save_expression=$defining_expression;
362 - $save_expression["expression_id"]=$target_expid1;
363 - mysql_insert_assoc($target_table,$save_expression);
364 - # and insert that info into the dm
365 - $this->save_meaning["expression_id"]=$target_expid1;
 369+ if (!($copier->already_there())) {
 370+ # exp
 371+ $target_table=mysql_real_escape_string("${dc2}_expression_ns");
 372+ $exp_copier=new ObjectCopier($defining_expression["expression_id"], $target_table, $dc1, $dc2);
 373+ $target_expid1=$exp_copier->dup();
 374+ var_dump($target_expid1);
 375+ $save_expression=$defining_expression;
 376+ $save_expression["expression_id"]=$target_expid1;
 377+ mysql_insert_assoc($target_table,$save_expression);
 378+ # and insert that info into the dm
 379+ $this->save_meaning["expression_id"]=$target_expid1;
 380+ }
366381 $this->save_meaning["meaning_text_tcid"]=dup_translated_content($dc1, $dc2, $this->defined_meaning["meaning_text_tcid"]);
367382
368 - mysql_insert_assoc($dm_target_table, $this->save_meaning);
 383+ if (!($copier->already_there())) {
 384+ mysql_insert_assoc($dm_target_table, $this->save_meaning);
369385
370 - $title_name=$defining_expression["spelling"];
371 - $title_number=$target_dmid;
372 - $title=str_replace(" ","_",$title_name)."_(".$title_number.")";
373 - $pagedata=array("page_namespace"=>24, "page_title"=>$title);
374 - mysql_insert_assoc("page",$pagedata);
 386+ $title_name=$defining_expression["spelling"];
 387+ $title_number=$target_dmid;
 388+ $title=str_replace(" ","_",$title_name)."_(".$title_number.")";
 389+ $pagedata=array("page_namespace"=>24, "page_title"=>$title);
 390+ mysql_insert_assoc("page",$pagedata);
 391+ }
375392
376393 $concepts=array(
377394 $dc1 => $this->defined_meaning["defined_meaning_id"],

Status & tagging log