Merge "API: Fix description for YAML format"
[lhc/web/wiklou.git] / maintenance / cleanupUploadStash.php
index cc32946..dc03c34 100644 (file)
@@ -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__
                );
 
@@ -68,7 +70,7 @@ class UploadStashCleanup extends Maintenance {
                        array_push( $keys, $row->us_key );
                }
 
-               $this->output( 'Removing ' . count($keys) . " file(s)...\n" );
+               $this->output( 'Removing ' . count( $keys ) . " file(s)...\n" );
                // this could be done some other, more direct/efficient way, but using
                // UploadStash's own methods means it's less likely to fall accidentally
                // out-of-date someday
@@ -82,6 +84,25 @@ 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 ) {
+                       $i++;
+                       if ( wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp( "$dir/$file" ) ) < $cutoff ) {
+                               $tempRepo->quickPurge( "$dir/$file" );
                        }
                        if ( $i % 100 == 0 ) {
                                $this->output( "$i\n" );