X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FrefreshImageMetadata.php;h=f6e9e9c35f8ba93d4864a4ea9cec7009f37a41f8;hb=c16f2ef0853f8cdc344ed2a89a5d0a27ef0e3e63;hp=bdbb3478999614eecb27fefae3006fa14247a406;hpb=0d0059d36e7494792378c020f5de6033985c3637;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/refreshImageMetadata.php b/maintenance/refreshImageMetadata.php index bdbb347899..f6e9e9c35f 100644 --- a/maintenance/refreshImageMetadata.php +++ b/maintenance/refreshImageMetadata.php @@ -29,6 +29,9 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script to refresh image metadata fields. * @@ -37,7 +40,7 @@ require_once __DIR__ . '/Maintenance.php'; class RefreshImageMetadata extends Maintenance { /** - * @var DatabaseBase + * @var IMaintainableDatabase */ protected $dbw; @@ -132,51 +135,58 @@ class RefreshImageMetadata extends Maintenance { if ( $res->numRows() > 0 ) { $row1 = $res->current(); - $this->output( "Processing next {$this->mBatchSize} rows starting with {$row1->img_name}.\n" ); + $this->output( "Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" ); $res->rewind(); - } else { - $this->error( "No images to process.", 4 ); } foreach ( $res as $row ) { - $file = $repo->newFileFromRow( $row ); - if ( $file->getUpgraded() ) { - // File was upgraded. - $upgraded++; - $newLength = strlen( $file->getMetadata() ); - $oldLength = strlen( $row->img_metadata ); - if ( $newLength < $oldLength - 5 ) { - // If after updating, the metadata is smaller then - // what it was before, that's probably not a good thing - // because we extract more data with time, not less. - // Thus this probably indicates an error of some sort, - // or at the very least is suspicious. Have the - 5 just - // to weed out any inconsequential changes. - $error++; - $this->output( "Warning: File:{$row->img_name} used to have " . - "$oldLength bytes of metadata but now has $newLength bytes.\n" ); - } elseif ( $verbose ) { - $this->output( "Refreshed File:{$row->img_name}.\n" ); - } - } else { - $leftAlone++; - if ( $force ) { - $file->upgradeRow(); + try { + // LocalFile will upgrade immediately here if obsolete + $file = $repo->newFileFromRow( $row ); + if ( $file->getUpgraded() ) { + // File was upgraded. + $upgraded++; $newLength = strlen( $file->getMetadata() ); $oldLength = strlen( $row->img_metadata ); if ( $newLength < $oldLength - 5 ) { + // If after updating, the metadata is smaller then + // what it was before, that's probably not a good thing + // because we extract more data with time, not less. + // Thus this probably indicates an error of some sort, + // or at the very least is suspicious. Have the - 5 just + // to weed out any inconsequential changes. $error++; - $this->output( "Warning: File:{$row->img_name} used to have " . - "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n" ); - } - if ( $verbose ) { - $this->output( "Forcibly refreshed File:{$row->img_name}.\n" ); + $this->output( + "Warning: File:{$row->img_name} used to have " . + "$oldLength bytes of metadata but now has $newLength bytes.\n" + ); + } elseif ( $verbose ) { + $this->output( "Refreshed File:{$row->img_name}.\n" ); } } else { - if ( $verbose ) { - $this->output( "Skipping File:{$row->img_name}.\n" ); + $leftAlone++; + if ( $force ) { + $file->upgradeRow(); + $newLength = strlen( $file->getMetadata() ); + $oldLength = strlen( $row->img_metadata ); + if ( $newLength < $oldLength - 5 ) { + $error++; + $this->output( + "Warning: File:{$row->img_name} used to have " . + "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n" + ); + } + if ( $verbose ) { + $this->output( "Forcibly refreshed File:{$row->img_name}.\n" ); + } + } else { + if ( $verbose ) { + $this->output( "Skipping File:{$row->img_name}.\n" ); + } } } + } catch ( Exception $e ) { + $this->output( "{$row->img_name} failed. {$e->getMessage()}\n" ); } } $conds2 = [ 'img_name > ' . $dbw->addQuotes( $row->img_name ) ]; @@ -196,7 +206,7 @@ class RefreshImageMetadata extends Maintenance { } /** - * @param DatabaseBase $dbw + * @param IDatabase $dbw * @return array */ function getConditions( $dbw ) {