Changed stash age parameter from a constant to a config option, switched to seconds...
authorIan Baker <raindrift@users.mediawiki.org>
Fri, 29 Jul 2011 18:46:24 +0000 (18:46 +0000)
committerIan Baker <raindrift@users.mediawiki.org>
Fri, 29 Jul 2011 18:46:24 +0000 (18:46 +0000)
followup to r92030

includes/DefaultSettings.php
includes/upload/UploadStash.php
maintenance/cleanupUploadStash.php

index 0e79603..f75d3ec 100644 (file)
@@ -179,6 +179,11 @@ $wgArticlePath      = false;
  */
 $wgUploadPath       = false;
 
+/**
+ * The maximum age of temporary (incomplete) uploaded files
+ */
+$wgUploadStashMaxAge = 6 * 3600; // 6 hours
+
 /**
  * The filesystem path of the images directory. Defaults to "{$IP}/images".
  */
index 9304ce5..d86933a 100644 (file)
@@ -23,9 +23,6 @@ class UploadStash {
        // behind, throw an exception instead. (at what point is broken better than slow?)
        const MAX_LAG = 30;
 
-       // Age of the repository in hours.  That is, after how long will files be assumed abandoned and deleted?
-       const REPO_AGE = 6;
-
        /**
         * repository that this uses to store temp files
         * public because we sometimes need to get a LocalFile within the same repo.
@@ -69,6 +66,12 @@ class UploadStash {
                        $this->userId = $this->user->getId();
                        $this->isLoggedIn = $this->user->isLoggedIn();
                }
+
+               // Age of the repository in seconds.  That is, after how long will files be assumed abandoned and deleted?
+               global $wgUploadStashMaxAge;
+               if( $wgUploadStashMaxAge === null ) {
+                       $wgUploadStashMaxAge = 6 * 3600; // default: 6 hours.
+               }
        }
 
        /**
@@ -263,10 +266,10 @@ class UploadStash {
 
                // The current user can't have this key if:
                // - the key is owned by someone else and
-               // - the age of the key is less than REPO_AGE
+               // - the age of the key is less than $wgUploadStashMaxAge
                if ( is_object( $row ) ) {
                        if ( $row->us_user != $this->userId &&
-                               $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - UploadStash::REPO_AGE * 3600
+                               $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - $wgUploadStashMaxAge
                        ) {
                                $dbw->rollback();
                                throw new UploadStashWrongOwnerException( "Attempting to upload a duplicate of a file that someone else has stashed" );
index 4b47f39..4e85472 100644 (file)
@@ -38,12 +38,18 @@ class UploadStashCleanup extends Maintenance {
                $repo = RepoGroup::singleton()->getLocalRepo();
        
                $dbr = $repo->getSlaveDb();
+
+               // how far back should this look for files to delete?
+               global $wgUploadStashMaxAge;
+               if( $wgUploadStashMaxAge === null ) {
+                       $wgUploadStashMaxAge = 6 * 3600; // default: 6 hours.
+               }
                
                $this->output( "Getting list of files to clean up...\n" );
                $res = $dbr->select(
                        'uploadstash',
                        'us_key',
-                       'us_timestamp < ' . $dbr->timestamp( time() - UploadStash::REPO_AGE * 3600 ),
+                       'us_timestamp < ' . $dbr->timestamp( time() - $wgUploadStashMaxAge ),
                        __METHOD__
                );