From 26036eb601bba1b77db2f80c84205dedd958e03a Mon Sep 17 00:00:00 2001 From: Ian Baker Date: Fri, 29 Jul 2011 18:46:24 +0000 Subject: [PATCH] Changed stash age parameter from a constant to a config option, switched to seconds for consistency. followup to r92030 --- includes/DefaultSettings.php | 5 +++++ includes/upload/UploadStash.php | 13 ++++++++----- maintenance/cleanupUploadStash.php | 8 +++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0e796035af..f75d3ec309 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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". */ diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 9304ce5fc4..d86933a172 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -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" ); diff --git a/maintenance/cleanupUploadStash.php b/maintenance/cleanupUploadStash.php index 4b47f39753..4e85472f53 100644 --- a/maintenance/cleanupUploadStash.php +++ b/maintenance/cleanupUploadStash.php @@ -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__ ); -- 2.20.1