r9614 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r9613‎ | r9614 | r9615 >
Date:07:17, 24 June 2005
Author:vibber
Status:old
Tags:
Comment:
oldimage table:
* UTF8 conversion of fields
* grab width/height/bits and insert into the new fields
* move files for UTF8 conversion, leave redirects
Moved table cleanup into a separate step.
Modified paths:
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -34,7 +34,9 @@
3535 $this->upgradeLinks();
3636 $this->upgradeUser();
3737 $this->upgradeImage();
38 - #$this->upgradeOldImage();
 38+ $this->upgradeOldImage();
 39+
 40+ $this->upgradeCleanup();
3941 }
4042
4143
@@ -383,11 +385,8 @@
384386 }
385387 $this->lastChunk( $add );
386388 $this->dbr->freeResult( $result );
387 -
388 - $this->log( "......Renaming old." );
389 - $this->dbw->query( "ALTER TABLE $old RENAME TO $text", $fname );
390389
391 - $this->log( "...done." );
 390+ $this->log( "...done with cur/old -> page/revision." );
392391 }
393392
394393 function upgradeLinks() {
@@ -540,10 +539,6 @@
541540 }
542541 $this->lastChunk( $add );
543542 $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" );
548543 }
549544
550545 function upgradeImage() {
@@ -613,15 +608,13 @@
614609 }
615610 $this->lastChunk( $add );
616611
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 -
621612 $this->log( 'done with image table.' );
622613 }
623614
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;
626619 $info = array(
627620 'width' => 0,
628621 'height' => 0,
@@ -672,18 +665,20 @@
673666 * leaving a symlink for URL compatibility.
674667 *
675668 * @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
677670 * @access private
678671 */
679 - function renameFile( $oldname, $subdirCallback ) {
 672+ function renameFile( $oldname, $subdirCallback='wfImageDir', $basename=null ) {
680673 $newname = $this->conv( $oldname );
681674 if( $newname == $oldname ) {
682675 // No need to rename; another field triggered this row.
683676 return;
684677 }
685678
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;
688683
689684 $this->log( "$oldpath -> $newpath" );
690685 if( rename( $oldpath, $newpath ) ) {
@@ -728,7 +723,98 @@
729724 return implode( '/', $pieces );
730725 }
731726
 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 '',
732751
 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+
733819 }
734820
735821 ?>
\ No newline at end of file

Status & tagging log