From 17f27fef9149b0759e2bc741a9e987ccbbaca8db Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 25 Sep 2012 14:49:36 -0700 Subject: [PATCH] Made stash cleaning script also remove the old thumbnails. Change-Id: I3dd5cc927bbbfb0f06eac9170107b17fabe39168 --- maintenance/cleanupUploadStash.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/maintenance/cleanupUploadStash.php b/maintenance/cleanupUploadStash.php index cc329461b9..99985b5e3a 100644 --- a/maintenance/cleanupUploadStash.php +++ b/maintenance/cleanupUploadStash.php @@ -41,18 +41,20 @@ class UploadStashCleanup extends Maintenance { } public function execute() { + global $wgUploadStashMaxAge; + $repo = RepoGroup::singleton()->getLocalRepo(); $dbr = $repo->getSlaveDb(); // how far back should this look for files to delete? - global $wgUploadStashMaxAge; + $cutoff = time() - $wgUploadStashMaxAge; $this->output( "Getting list of files to clean up...\n" ); $res = $dbr->select( 'uploadstash', 'us_key', - 'us_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - $wgUploadStashMaxAge ) ), + 'us_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $cutoff ) ), __METHOD__ ); @@ -88,6 +90,22 @@ class UploadStashCleanup extends Maintenance { } } $this->output( "$i done\n" ); + + $tempRepo = $repo->getTempRepo(); + $dir = $tempRepo->getZonePath( 'thumb' ); + $iterator = $tempRepo->getBackend()->getFileList( array( 'dir' => $dir ) ); + + $this->output( "Deleting old thumbnails...\n" ); + $i = 0; + foreach ( $iterator as $file ) { + if ( wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp( "$dir/$file" ) ) < $cutoff ) { + $tempRepo->quickPurge( "$dir/$file" ); + } + if ( $i % 100 == 0 ) { + $this->output( "$i\n" ); + } + } + $this->output( "$i done\n" ); } } -- 2.20.1