X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcleanupUploadStash.php;h=6afe9e11e0a595de06bca8b81486d799af9bb0a5;hb=1162a32ef22973ba3c92b7b91c146deef217be10;hp=cc329461b98881ed095bb271141b055045cf98e5;hpb=a7722e6131520142ee40e36e2f937292d0f90544;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupUploadStash.php b/maintenance/cleanupUploadStash.php index cc329461b9..6afe9e11e0 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__ ); @@ -82,6 +84,24 @@ class UploadStashCleanup extends Maintenance { $stash->removeFileNoAuth( $key ); } catch ( UploadStashBadPathException $ex ) { $this->output( "Failed removing stashed upload with key: $key\n" ); + } catch ( UploadStashZeroLengthFileException $ex ) { + $this->output( "Failed removing stashed upload with key: $key\n" ); + } + if ( $i % 100 == 0 ) { + $this->output( "$i\n" ); + } + } + $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" );