Index: trunk/phase3/maintenance/upgrade1_5.php |
— | — | @@ -34,7 +34,9 @@ |
35 | 35 | $this->upgradeLinks(); |
36 | 36 | $this->upgradeUser(); |
37 | 37 | $this->upgradeImage(); |
38 | | - #$this->upgradeOldImage(); |
| 38 | + $this->upgradeOldImage(); |
| 39 | + |
| 40 | + $this->upgradeCleanup(); |
39 | 41 | } |
40 | 42 | |
41 | 43 | |
— | — | @@ -383,11 +385,8 @@ |
384 | 386 | } |
385 | 387 | $this->lastChunk( $add ); |
386 | 388 | $this->dbr->freeResult( $result ); |
387 | | - |
388 | | - $this->log( "......Renaming old." ); |
389 | | - $this->dbw->query( "ALTER TABLE $old RENAME TO $text", $fname ); |
390 | 389 | |
391 | | - $this->log( "...done." ); |
| 390 | + $this->log( "...done with cur/old -> page/revision." ); |
392 | 391 | } |
393 | 392 | |
394 | 393 | function upgradeLinks() { |
— | — | @@ -540,10 +539,6 @@ |
541 | 540 | } |
542 | 541 | $this->lastChunk( $add ); |
543 | 542 | $this->dbr->freeResult( $result ); |
544 | | - |
545 | | - $this->log( 'Renaming user to user_old and user_temp to user...' ); |
546 | | - $this->dbw->query( "ALTER TABLE $user RENAME TO $user_old" ); |
547 | | - $this->dbw->query( "ALTER TABLE $user_temp RENAME TO $user" ); |
548 | 543 | } |
549 | 544 | |
550 | 545 | function upgradeImage() { |
— | — | @@ -613,15 +608,13 @@ |
614 | 609 | } |
615 | 610 | $this->lastChunk( $add ); |
616 | 611 | |
617 | | - $this->log( 'Renaming image to image_old and image_temp to image...' ); |
618 | | - $this->dbw->query( "ALTER TABLE $image RENAME TO $image_old" ); |
619 | | - $this->dbw->query( "ALTER TABLE $image_temp RENAME TO $image" ); |
620 | | - |
621 | 612 | $this->log( 'done with image table.' ); |
622 | 613 | } |
623 | 614 | |
624 | | - function imageInfo( $name ) { |
625 | | - $filename = wfImageDir( $name ) . '/' . $name; |
| 615 | + function imageInfo( $name, $subdirCallback='wfImageDir', $basename = null ) { |
| 616 | + if( is_null( $basename ) ) $basename = $name; |
| 617 | + $dir = call_user_func( $subdirCallback, $basename ); |
| 618 | + $filename = $dir . '/' . $name; |
626 | 619 | $info = array( |
627 | 620 | 'width' => 0, |
628 | 621 | 'height' => 0, |
— | — | @@ -672,18 +665,20 @@ |
673 | 666 | * leaving a symlink for URL compatibility. |
674 | 667 | * |
675 | 668 | * @param string $oldname pre-conversion filename |
676 | | - * @param callable $subdirCallback a function to generate hashed directories |
| 669 | + * @param string $basename pre-conversion base filename for dir hashing, if an archive |
677 | 670 | * @access private |
678 | 671 | */ |
679 | | - function renameFile( $oldname, $subdirCallback ) { |
| 672 | + function renameFile( $oldname, $subdirCallback='wfImageDir', $basename=null ) { |
680 | 673 | $newname = $this->conv( $oldname ); |
681 | 674 | if( $newname == $oldname ) { |
682 | 675 | // No need to rename; another field triggered this row. |
683 | 676 | return; |
684 | 677 | } |
685 | 678 | |
686 | | - $oldpath = call_user_func( $subdirCallback, $oldname ) . '/' . $oldname; |
687 | | - $newpath = call_user_func( $subdirCallback, $newname ) . '/' . $newname; |
| 679 | + if( is_null( $basename ) ) $basename = $oldname; |
| 680 | + $ubasename = $this->conv( $basename ); |
| 681 | + $oldpath = call_user_func( $subdirCallback, $basename ) . '/' . $oldname; |
| 682 | + $newpath = call_user_func( $subdirCallback, $ubasename ) . '/' . $newname; |
688 | 683 | |
689 | 684 | $this->log( "$oldpath -> $newpath" ); |
690 | 685 | if( rename( $oldpath, $newpath ) ) { |
— | — | @@ -728,7 +723,98 @@ |
729 | 724 | return implode( '/', $pieces ); |
730 | 725 | } |
731 | 726 | |
| 727 | + function upgradeOldImage() { |
| 728 | + $fname = 'FiveUpgrade::upgradeOldImage'; |
| 729 | + $chunksize = 100; |
| 730 | + |
| 731 | + extract( $this->dbw->tableNames( 'oldimage', 'oldimage_temp', 'oldimage_old' ) ); |
| 732 | + $this->log( 'Creating temporary oldimage_temp to merge into...' ); |
| 733 | + $this->dbw->query( <<<END |
| 734 | +CREATE TABLE $oldimage_temp ( |
| 735 | + -- Base filename: key to image.img_name |
| 736 | + oi_name varchar(255) binary NOT NULL default '', |
| 737 | + |
| 738 | + -- Filename of the archived file. |
| 739 | + -- This is generally a timestamp and '!' prepended to the base name. |
| 740 | + oi_archive_name varchar(255) binary NOT NULL default '', |
| 741 | + |
| 742 | + -- Other fields as in image... |
| 743 | + oi_size int(8) unsigned NOT NULL default 0, |
| 744 | + oi_width int(5) NOT NULL default 0, |
| 745 | + oi_height int(5) NOT NULL default 0, |
| 746 | + oi_bits int(3) NOT NULL default 0, |
| 747 | + oi_description tinyblob NOT NULL default '', |
| 748 | + oi_user int(5) unsigned NOT NULL default '0', |
| 749 | + oi_user_text varchar(255) binary NOT NULL default '', |
| 750 | + oi_timestamp char(14) binary NOT NULL default '', |
732 | 751 | |
| 752 | + INDEX oi_name (oi_name(10)) |
| 753 | + |
| 754 | +) TYPE=InnoDB; |
| 755 | +END |
| 756 | + , $fname); |
| 757 | + |
| 758 | + $numimages = $this->dbw->selectField( 'oldimage', 'count(*)', '', $fname ); |
| 759 | + $result = $this->dbr->select( 'oldimage', |
| 760 | + array( |
| 761 | + 'oi_name', |
| 762 | + 'oi_archive_name', |
| 763 | + 'oi_size', |
| 764 | + 'oi_description', |
| 765 | + 'oi_user', |
| 766 | + 'oi_user_text', |
| 767 | + 'oi_timestamp' ), |
| 768 | + '', |
| 769 | + $fname ); |
| 770 | + $add = array(); |
| 771 | + $this->setChunkScale( $chunksize, $numimages, 'oldimage_temp', $fname ); |
| 772 | + while( $row = $this->dbr->fetchObject( $result ) ) { |
| 773 | + // Fill in the new image info fields |
| 774 | + $info = $this->imageInfo( $row->oi_archive_name, 'wfImageArchiveDir', $row->oi_name ); |
| 775 | + |
| 776 | + // Update and convert encoding |
| 777 | + $add[] = array( |
| 778 | + 'oi_name' => $this->conv( $row->oi_name ), |
| 779 | + 'oi_archive_name' => $this->conv( $row->oi_archive_name ), |
| 780 | + 'oi_size' => $row->oi_size, |
| 781 | + 'oi_width' => $info['width'], |
| 782 | + 'oi_height' => $info['height'], |
| 783 | + 'oi_bits' => $info['bits'], |
| 784 | + 'oi_description' => $this->conv( $row->oi_description ), |
| 785 | + 'oi_user' => $row->oi_user, |
| 786 | + 'oi_user_text' => $this->conv( $row->oi_user_text ), |
| 787 | + 'oi_timestamp' => $row->oi_timestamp ); |
| 788 | + |
| 789 | + // If doing UTF8 conversion the file must be renamed |
| 790 | + $this->renameFile( $row->oi_archive_name, 'wfImageArchiveDir', $row->oi_name ); |
| 791 | + } |
| 792 | + $this->lastChunk( $add ); |
| 793 | + |
| 794 | + $this->log( 'done with oldimage table.' ); |
| 795 | + } |
| 796 | + |
| 797 | + /** |
| 798 | + * Rename all our temporary tables into final place. |
| 799 | + * We've left things in place so a read-only wiki can continue running |
| 800 | + * on the old code during all this. |
| 801 | + */ |
| 802 | + function upgradeCleanup() { |
| 803 | + $this->log( "Renaming old to text..." ); |
| 804 | + $this->dbw->query( "ALTER TABLE $old RENAME TO $text", $fname ); |
| 805 | + |
| 806 | + $this->log( 'Renaming user to user_old and user_temp to user...' ); |
| 807 | + $this->dbw->query( "ALTER TABLE $user RENAME TO $user_old" ); |
| 808 | + $this->dbw->query( "ALTER TABLE $user_temp RENAME TO $user" ); |
| 809 | + |
| 810 | + $this->log( 'Renaming image to image_old and image_temp to image...' ); |
| 811 | + $this->dbw->query( "ALTER TABLE $image RENAME TO $image_old" ); |
| 812 | + $this->dbw->query( "ALTER TABLE $image_temp RENAME TO $image" ); |
| 813 | + |
| 814 | + $this->log( 'Renaming oldimage to oldimage_old and oldimage_temp to oldimage...' ); |
| 815 | + $this->dbw->query( "ALTER TABLE $oldimage RENAME TO $oldimage_old" ); |
| 816 | + $this->dbw->query( "ALTER TABLE $oldimage_temp RENAME TO $oldimage" ); |
| 817 | + } |
| 818 | + |
733 | 819 | } |
734 | 820 | |
735 | 821 | ?> |
\ No newline at end of file |