From: Tim Starling Date: Sat, 16 Apr 2005 12:19:29 +0000 (+0000) Subject: Conversion from 1.4 schema, zero downtime X-Git-Tag: 1.5.0alpha1~251 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=f289929d785e3cafc1b6befbd306b1012a9dff8b;p=lhc%2Fweb%2Fwiklou.git Conversion from 1.4 schema, zero downtime --- diff --git a/includes/Image.php b/includes/Image.php index 0b5ac62673..5824da8aa8 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -237,6 +237,10 @@ class Image $this->fileExists = true; $this->loadFromRow( $row ); $this->imagePath = $this->getFullPath(); + // Check for rows from a previous schema, quietly upgrade them + if ( $this->type == -1 ) { + $this->upgradeRow(); + } } elseif ( $wgUseSharedUploads && $wgSharedUploadDBname ) { # In case we're on a wgCapitalLinks=false wiki, we # capitalize the first letter of the filename before @@ -252,6 +256,11 @@ class Image $this->imagePath = $this->getFullPath(true); $this->name = $name; $this->loadFromRow( $row ); + + // Check for rows from a previous schema, quietly upgrade them + if ( $this->type == -1 ) { + $this->upgradeRow(); + } } } @@ -299,6 +308,38 @@ class Image } } + /** + * Metadata was loaded from the database, but the row had a marker indicating it needs to be + * upgraded from the 1.4 schema, which had no width, height, bits or type. Upgrade the row. + */ + function upgradeRow() { + global $wgDBname, $wgSharedUploadDBname; + $fname = 'Image::upgradeRow'; + $this->loadFromFile(); + $dbw =& wfGetDB( DB_MASTER ); + + if ( $this->fromSharedDirectory ) { + if ( !$wgSharedUploadDBname ) { + return; + } + + // Write to the other DB using selectDB, not database selectors + // This avoids breaking replication in MySQL + $dbw->selectDB( $wgSharedUploadDBname ); + } + $dbw->update( '`image`', + array( + 'img_width' => $this->width, + 'img_height' => $this->height, + 'img_bits' => $this->bits, + 'img_type' => $this->type, + ), array( 'img_name' => $this->name ), $fname + ); + if ( $this->fromSharedDirectory ) { + $dbw->selectDB( $wgDBname ); + } + } + /** * Return the name of this image * @access public diff --git a/maintenance/archives/patch-img_width.sql b/maintenance/archives/patch-img_width.sql index 5531259cea..9dc233f26e 100644 --- a/maintenance/archives/patch-img_width.sql +++ b/maintenance/archives/patch-img_width.sql @@ -1,10 +1,10 @@ -- Extra image metadata, added for 1.5 ALTER TABLE /*$wgDBprefix*/image ADD ( - img_width int(5) NOT NULL default '0', - img_height int(5) NOT NULL default '0', - img_bits int(5) NOT NULL default '0', - img_type int(5) NOT NULL default '0' + img_width int(5) NOT NULL default 0, + img_height int(5) NOT NULL default 0, + img_bits int(5) NOT NULL default 0, + img_type int(5) NOT NULL default -1 ); ALTER TABLE /*$wgDBprefix*/oldimage ADD (