r93476 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93475‎ | r93476 | r93477 >
Date:18:46, 29 July 2011
Author:raindrift
Status:resolved (Comments)
Tags:
Comment:
Changed stash age parameter from a constant to a config option, switched to seconds for consistency.
followup to r92030
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadStash.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupUploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadStash.php
@@ -23,9 +23,6 @@
2424 // behind, throw an exception instead. (at what point is broken better than slow?)
2525 const MAX_LAG = 30;
2626
27 - // Age of the repository in hours. That is, after how long will files be assumed abandoned and deleted?
28 - const REPO_AGE = 6;
29 -
3027 /**
3128 * repository that this uses to store temp files
3229 * public because we sometimes need to get a LocalFile within the same repo.
@@ -69,6 +66,12 @@
7067 $this->userId = $this->user->getId();
7168 $this->isLoggedIn = $this->user->isLoggedIn();
7269 }
 70+
 71+ // Age of the repository in seconds. That is, after how long will files be assumed abandoned and deleted?
 72+ global $wgUploadStashMaxAge;
 73+ if( $wgUploadStashMaxAge === null ) {
 74+ $wgUploadStashMaxAge = 6 * 3600; // default: 6 hours.
 75+ }
7376 }
7477
7578 /**
@@ -263,10 +266,10 @@
264267
265268 // The current user can't have this key if:
266269 // - the key is owned by someone else and
267 - // - the age of the key is less than REPO_AGE
 270+ // - the age of the key is less than $wgUploadStashMaxAge
268271 if ( is_object( $row ) ) {
269272 if ( $row->us_user != $this->userId &&
270 - $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - UploadStash::REPO_AGE * 3600
 273+ $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - $wgUploadStashMaxAge
271274 ) {
272275 $dbw->rollback();
273276 throw new UploadStashWrongOwnerException( "Attempting to upload a duplicate of a file that someone else has stashed" );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -180,6 +180,11 @@
181181 $wgUploadPath = false;
182182
183183 /**
 184+ * The maximum age of temporary (incomplete) uploaded files
 185+ */
 186+$wgUploadStashMaxAge = 6 * 3600; // 6 hours
 187+
 188+/**
184189 * The filesystem path of the images directory. Defaults to "{$IP}/images".
185190 */
186191 $wgUploadDirectory = false;
Index: trunk/phase3/maintenance/cleanupUploadStash.php
@@ -38,12 +38,18 @@
3939 $repo = RepoGroup::singleton()->getLocalRepo();
4040
4141 $dbr = $repo->getSlaveDb();
 42+
 43+ // how far back should this look for files to delete?
 44+ global $wgUploadStashMaxAge;
 45+ if( $wgUploadStashMaxAge === null ) {
 46+ $wgUploadStashMaxAge = 6 * 3600; // default: 6 hours.
 47+ }
4248
4349 $this->output( "Getting list of files to clean up...\n" );
4450 $res = $dbr->select(
4551 'uploadstash',
4652 'us_key',
47 - 'us_timestamp < ' . $dbr->timestamp( time() - UploadStash::REPO_AGE * 3600 ),
 53+ 'us_timestamp < ' . $dbr->timestamp( time() - $wgUploadStashMaxAge ),
4854 __METHOD__
4955 );
5056

Follow-up revisions

RevisionCommit summaryAuthorDate
r93919Fixed bug where global wgUploadStashMaxAge wasn't used, removed redundant def...raindrift21:19, 4 August 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92030Added maintenance script for cleaning up abandoned uploads...raindrift00:11, 13 July 2011

Comments

#Comment by Platonides (talk | contribs)   18:29, 3 August 2011

Instance of $wgUploadStashMaxAge inside function stashFile (line 276) is a local variable, not the global. in DefaultSettings.php

You shouldn't initialise variables in UploadStash.php or cleanupUploadStash.php. The default in DefaultSettings.php is enough and more sane. If $wgUploadStashMaxAge wasn't set when you use it, that would be a bug with or without that duplicated code.

#Comment by Raindrift (talk | contribs)   21:20, 4 August 2011

Thanks for catching that, and I see your point. Fixed.

Status & tagging log