r25943 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25942‎ | r25943 | r25944 >
Date:17:28, 19 September 2007
Author:kim
Status:old
Tags:
Comment:
some refactoring, still runs without notices, so I'll commit for now
Modified paths:
  • /trunk/extensions/Wikidata/util/copy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/util/copy.php
@@ -57,8 +57,6 @@
5858 startNewTransaction(0, "127.0.0.1", "copying from $dc1 to $dc2", $dc2);
5959 }
6060
61 -
62 -
6361 /** retrieve a single row from the database as an associative array
6462 * @param $dc the dataset prefix we need
6563 * @param $table the name of the table (minus dataset prefix)
@@ -70,7 +68,7 @@
7169 $target_table=mysql_real_escape_string("${dc}_${table}");
7270 $query="SELECT * FROM $target_table ".$where;
7371 print $query."<br>\n";
74 - return doquery($query);
 72+ return doQuery($query);
7573 }
7674
7775
@@ -96,7 +94,7 @@
9795 * keys=column headers, values = row contents
9896 *
9997 */
100 -function doquery($query) {
 98+function doQuery($query) {
10199 echo $query;
102100 $result = mysql_query($query)or die ("error ".mysql_error());
103101 $data= mysql_fetch_assoc($result);
@@ -178,13 +176,23 @@
179177 return getrow($dc2, "objects", "WHERE `UUID`='$uuid'");
180178 }
181179
 180+ /** Write copy of object into the objects table,taking into account
 181+ * necessary changes.
 182+ * possible TODO: Currently induces the target table from the original
 183+ * destination table name.
 184+ * Perhaps would be wiser to get the target table as an (override) parameter.
 185+ */
182186 function write() {
183 - $dc2=$this->dc2;
184 - $objects_table=mysql_real_escape_string("${dc2}_objects");
185 - $object=$this->object;
 187+ $dc2 = $this->dc2;
 188+ $object = $this->object;
186189 unset($object["object_id"]);
187 - $object["table"]=$objects_table;
188 - mysql_insert_assoc($objects_table,$object);
 190+
 191+ $tableName_exploded = explode("_", $object["table"]);
 192+ $tableName_exploded[0] = $dc2;
 193+ $tableName = implode("_", $tableName_exploded);
 194+ $object["table"]=$tableName;
 195+
 196+ dc_insert_assoc($dc2,"objects",$object);
189197 return mysql_insert_id();
190198 }
191199
@@ -276,8 +284,7 @@
277285 function writeSyntrans($syntrans, $newdmid, $newexpid, $dc2) {
278286 $syntrans["defined_meaning_id"]=$newdmid;
279287 $syntrans["expression_id"]=$newexpid;
280 - $syntrans_table=mysql_real_escape_string("${dc2}_syntrans");
281 - mysql_insert_assoc($syntrans_table,$syntrans);
 288+ dc_insert_assoc($dc2,"syntrans",$syntrans);
282289 }
283290
284291 function dupSyntrans($dc1, $dc2, $olddmid, $oldexpid, $newdmid, $newexpid) {
@@ -304,9 +311,8 @@
305312 $target_expid1=$copier->dup();
306313 $save_expression=$expression;
307314 $save_expression["expression_id"]=$target_expid1;
308 - $target_table=mysql_real_escape_string("${dc2}_expression_ns");
309315 if (!($copier->already_there())) {
310 - mysql_insert_assoc($target_table,$save_expression);
 316+ dc_insert_assoc($dc,"expression_ns",$save_expression);
311317 }
312318 dupsyntrans(
313319 $dc1,
@@ -340,12 +346,10 @@
341347 }
342348
343349 function write_translated_content($dc1, $dc2, $tcid, $content) {
344 - $target_table=mysql_real_escape_string("${dc2}_translated_content");
345 - var_dump($content);
346350 $content["translated_content_id"]=$tcid;
347351 $content["text_id"]=dup_text($dc1, $dc2, $content["text_id"]);
348352 var_dump($content);
349 - mysql_insert_assoc($target_table, $content);
 353+ dc_insert_assoc($dc2, "translated_content", $content);
350354 }
351355
352356
@@ -373,7 +377,7 @@
374378 unset($text["text_id"]);
375379 # inconsistent, insert_assoc should accept dc, table
376380 $target_table=mysql_real_escape_string("${dc2}_text");
377 - mysql_insert_assoc($target_table,$text);
 381+ dc_insert_assoc($dc2, "text", $text);
378382 return mysql_insert_id();
379383 }
380384
@@ -407,7 +411,6 @@
408412 }
409413
410414 function write_single($relation) {
411 - echo "RELATION";
412415 var_dump($relation);
413416 $dc1=$this->dc1;
414417 $dc2=$this->dc2;
@@ -424,17 +427,13 @@
425428 # Typically checks same values each time. Accelerated by query_cache:
426429 $rtcopier=new defined_meaning_copier($relation["relationtype_mid"],$dc1, $dc2);
427430 $relation["relationtype_mid"]=$rtcopier->dup();
428 - echo ">>PRE!<br>\n";
429431 var_dump($relation);
430432 $copier=new ObjectCopier($relation["relation_id"], $dc1, $dc2);
431433 $relation["relation_id"]=$copier->dup();
432434 if ($copier->already_there()) {
433435 return;
434436 }
435 - echo ">>POST!<br>\n";
436 - var_dump($relation);
437 - $target_table=mysql_real_escape_string("${dc2}_meaning_relations");
438 - mysql_insert_assoc($target_table,$relation);
 437+ dc_insert_assoc($dc2,"meaning_relations",$relation);
439438
440439 }
441440
@@ -585,7 +584,14 @@
586585 return $this->already_there;
587586 }
588587
589 - function dup (){
 588+ public function dup() {
 589+ $this->dup_stub();
 590+ $this->dup_rest();
 591+ return $this->save_meaning["defined_meaning_id"];
 592+ }
 593+
 594+
 595+ function dup_stub (){
590596 $dmid=$this->dmid;
591597 $dc1=$this->dc1;
592598 $dc2=$this->dc2;
@@ -611,21 +617,27 @@
612618 var_dump($target_expid1);
613619 $save_expression=$defining_expression;
614620 $save_expression["expression_id"]=$target_expid1;
615 - mysql_insert_assoc($target_table,$save_expression);
 621+ dc_insert_assoc($dc2, "expression_ns", $save_expression);
616622 # and insert that info into the dm
617623 $this->save_meaning["expression_id"]=$target_expid1;
618624 }
619625 $this->save_meaning["meaning_text_tcid"]=dup_translated_content($dc1, $dc2, $this->defined_meaning["meaning_text_tcid"]);
620626
621627 if (!($copier->already_there())) {
622 - mysql_insert_assoc($dm_target_table, $this->save_meaning);
 628+ dc_insert_assoc($dc2, "defined_meaning", $this->save_meaning);
623629
624630 $title_name=$defining_expression["spelling"];
625631 $title_number=$target_dmid;
626632 $title=str_replace(" ","_",$title_name)."_(".$title_number.")";
627 - $pagedata=array("page_namespace"=>24, "page_title"=>$title);
628 - mysql_insert_assoc("page",$pagedata);
 633+ CopyTools::createPage($title);
629634 }
 635+ return $this->save_meaning["defined_meaning_id"];
 636+ }
 637+
 638+ function dup_rest() {
 639+ $dmid=$this->dmid;
 640+ $dc1=$this->dc1;
 641+ $dc2=$this->dc2;
630642
631643 $concepts=array(
632644 $dc1 => $this->defined_meaning["defined_meaning_id"],
@@ -658,9 +670,21 @@
659671 $collectionCopier->dup();
660672 }
661673
662 - return $this->save_meaning["defined_meaning_id"];
663674 }
664675 }
 676+
 677+class CopyTools {
 678+ /** create a relevant entry in the `page` table. */
 679+ public static function createPage($title) {
 680+ # page is not a Wikidata table, so it needs to be treated differently (yet again :-/)
 681+ $escTitle=mysql_real_escape_string($title);
 682+ $existing_page_data=doQuery("SELECT * FROM page WHERE page_namespace=24 AND page_title=\"$escTitle\"");
 683+ if (count($existing_page_data)==0) {
 684+ $pagedata=array("page_namespace"=>24, "page_title"=>$title);
 685+ mysql_insert_assoc("page",$pagedata);
 686+ }
 687+ }
 688+}
665689
666690
667691 $start=stopwatch();

Status & tagging log