Index: trunk/extensions/Wikidata/util/copy.php |
— | — | @@ -26,7 +26,13 @@ |
27 | 27 | # * CopyTools::getRow(...); # comment |
28 | 28 | # Wrappers around PHP functions or extensions to PHP function set: Same style as the wrapped function |
29 | 29 | # * mysql_insert_assoc(...); # comment |
| 30 | +# |
| 31 | +# TODO: |
| 32 | +# * Change to library |
| 33 | +# some read/write/dup functions are still main namespace, should get their own |
| 34 | +# classes |
30 | 35 | |
| 36 | + |
31 | 37 | header("Content-type: text/html; charset=UTF-8"); |
32 | 38 | |
33 | 39 | define('MEDIAWIKI', true ); |
— | — | @@ -559,6 +565,9 @@ |
560 | 566 | } |
561 | 567 | } |
562 | 568 | |
| 569 | +/** provide a namespace for copying tools (so we don't clutter up the main namespace with |
| 570 | + * all our utility and tool functions) All functions here are public+static. |
| 571 | + */ |
563 | 572 | class CopyTools { |
564 | 573 | /** create a relevant entry in the `page` table. */ |
565 | 574 | public static function createPage($title) { |
— | — | @@ -579,9 +588,31 @@ |
580 | 589 | } |
581 | 590 | |
582 | 591 | /** start a new copy transaction |
| 592 | + * Gets a virtual user id from the wikidata_sets table, if available |
| 593 | + * (else uses user 0) |
| 594 | + * There's still some issues with transactions especially wrt with user assignment |
| 595 | + * where we intersect with the (old) "WikiDataAPI". |
583 | 596 | */ |
584 | 597 | public static function newCopyTransaction($dc1, $dc2) { |
585 | | - startNewTransaction(0, "127.0.0.1", "copying from $dc1 to $dc2", $dc2); |
| 598 | + |
| 599 | + $datasets=CopyTools::getRow_noDC("wikidata_sets", "WHERE set_prefix=\"$dc2\""); |
| 600 | + if ( $datasets == false ) { |
| 601 | + throw new Exception("Dataset info for $dc2 not found."); |
| 602 | + } |
| 603 | + |
| 604 | + if ( array_key_exists("virtual_user_id", $datasets) ) { |
| 605 | + $virtual_user_id=$datasets["virtual_user_id"]; |
| 606 | + } else { |
| 607 | + $virtual_user_id=0; |
| 608 | + } |
| 609 | + |
| 610 | + print " VUID: $virtual_user_id"; |
| 611 | + startNewTransaction( |
| 612 | + $virtual_user_id, |
| 613 | + "0.0.0.0", |
| 614 | + "copying from $dc1 to $dc2", |
| 615 | + $dc2 ); |
| 616 | + print " UTID: ".getUpdateTransactionId(); |
586 | 617 | } |
587 | 618 | |
588 | 619 | /** retrieve a single row from the database as an associative array |
— | — | @@ -594,10 +625,14 @@ |
595 | 626 | public static function getRow($dc, $table, $where) { |
596 | 627 | $target_table=mysql_real_escape_string("${dc}_${table}"); |
597 | 628 | $query="SELECT * FROM $target_table ".$where; |
598 | | - print $query."<br>\n"; |
599 | 629 | return CopyTools::doQuery($query); |
600 | 630 | } |
601 | 631 | |
| 632 | + public static function getRow_noDC($table, $where) { |
| 633 | + $target_table=mysql_real_escape_string("${table}"); |
| 634 | + $query="SELECT * FROM $target_table ".$where; |
| 635 | + return CopyTools::doQuery($query); |
| 636 | + } |
602 | 637 | |
603 | 638 | /** retrieve multiple rows from the database, as an array of associative arrays. |
604 | 639 | * @param $dc the dataset prefix we need |