From 6997632877f5326e10de19ef7c40a9cd01476a72 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 25 Aug 2007 13:54:12 +0000 Subject: [PATCH] Update img_sha1 only when it's really needed, instead of in maybeUpgradeRow(). --- includes/filerepo/LocalFile.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 581142d869..cff948de4e 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -261,8 +261,7 @@ class LocalFile extends File return; } if ( is_null($this->media_type) || - $this->mime == 'image/svg' || - $this->sha1 == '' + $this->mime == 'image/svg' ) { $this->upgradeRow(); $this->upgraded = true; @@ -972,6 +971,19 @@ class LocalFile extends File function getSha1() { $this->load(); + // Initialise now if necessary + if ( $this->sha1 == '' && $this->fileExists ) { + $this->sha1 = File::sha1Base36( $this->getPath() ); + if ( strval( $this->sha1 ) != '' ) { + $dbw = $this->repo->getMasterDB(); + $dbw->update( 'image', + array( 'img_sha1' => $this->sha1 ), + array( 'img_name' => $this->getName() ), + __METHOD__ ); + $this->saveToCache(); + } + } + return $this->sha1; } -- 2.20.1