Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/87607
Change subject: Added an expiry field to upload stash table
......................................................................
Added an expiry field to upload stash table
* This is useful for things that need to stay in the stash
zone for days instead of just a few hours.
* Changed the cleaner script to not expire things before this
value if it is set. Other files still use $wgUploadStashMaxAge alone.
The sanity purge run to kill untracked files now waits at least a week.
* Added a parameter to stashFile() to set this expiry.
Change-Id: I92599e5a508491a456b4edf32e2d43f4a44fed01
---
M includes/installer/MysqlUpdater.php
M includes/upload/UploadStash.php
A maintenance/archives/patch-uploadstash-us_expiry.sql
M maintenance/cleanupUploadStash.php
M maintenance/tables.sql
5 files changed, 14 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/07/87607/1
diff --git a/includes/installer/MysqlUpdater.php
b/includes/installer/MysqlUpdater.php
index 02faf7c..96860e6 100644
--- a/includes/installer/MysqlUpdater.php
+++ b/includes/installer/MysqlUpdater.php
@@ -231,6 +231,7 @@
// 1.22
array( 'doIwlinksIndexNonUnique' ),
array( 'addIndex', 'iwlinks', 'iwl_prefix_from_title',
'patch-iwlinks-from-title-index.sql' ),
+ array( 'addField', 'uploadstash', 'us_expiry',
'patch-uploadstash-us_expiry.sql' ),
);
}
diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php
index ebeb9c1..8c3d4c4 100644
--- a/includes/upload/UploadStash.php
+++ b/includes/upload/UploadStash.php
@@ -179,12 +179,13 @@
*
* @param string $path path to file you want stashed
* @param string $sourceType the type of upload that generated this
file (currently, I believe, 'file' or null)
+ * @param array $opts Options (includes 'expiry' timestamp)
* @throws UploadStashBadPathException
* @throws UploadStashFileException
* @throws UploadStashNotLoggedInException
* @return UploadStashFile: file, or null on failure
*/
- public function stashFile( $path, $sourceType = null ) {
+ public function stashFile( $path, $sourceType = null, array $opts =
array() ) {
if ( !is_file( $path ) ) {
wfDebug( __METHOD__ . " tried to stash file at '$path',
but it doesn't exist\n" );
throw new UploadStashBadPathException( "path doesn't
exist" );
@@ -270,7 +271,8 @@
'us_image_bits' => $fileProps['bits'],
'us_source_type' => $sourceType,
'us_timestamp' => $dbw->timestamp(),
- 'us_status' => 'finished'
+ 'us_status' => 'finished',
+ 'us_expiry' => isset( $opts['expiry'] ) ?
$dbw->timestamp( $opts['expiry'] ) : null
);
$dbw->insert(
diff --git a/maintenance/archives/patch-uploadstash-us_expiry.sql
b/maintenance/archives/patch-uploadstash-us_expiry.sql
new file mode 100644
index 0000000..b4f0f68
--- /dev/null
+++ b/maintenance/archives/patch-uploadstash-us_expiry.sql
@@ -0,0 +1,2 @@
+ALTER TABLE /*$wgDBprefix*/uploadstash
+ ADD COLUMN us_expiry varbinary(14) NULL default NULL;
diff --git a/maintenance/cleanupUploadStash.php
b/maintenance/cleanupUploadStash.php
index c2ba555..b56daa1 100644
--- a/maintenance/cleanupUploadStash.php
+++ b/maintenance/cleanupUploadStash.php
@@ -56,6 +56,7 @@
'uploadstash',
'us_key',
'us_timestamp < ' . $dbr->addQuotes( $dbr->timestamp(
$cutoff ) ),
+ 'us_expiry IS NULL OR us_expiry < ' . $dbr->addQuotes(
$dbr->timestamp() ),
__METHOD__
);
@@ -112,6 +113,7 @@
$this->output( "$i done\n" );
// Apparently lots of stash files are not registered in the
DB...
+ $sanityCutoff = min( $cutoff, time() - 7*86400 );
$dir = $tempRepo->getZonePath( 'public' );
$iterator = $tempRepo->getBackend()->getFileList( array( 'dir'
=> $dir, 'adviseStat' => 1 ) );
$this->output( "Deleting orphaned temp files...\n" );
@@ -125,7 +127,8 @@
$this->output( "Skipped non-stash $file\n" );
continue;
}
- if ( wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
+ $lastModified = wfTimestamp( TS_UNIX,
$tempRepo->getFileTimestamp( "$dir/$file" ) );
+ if ( $lastModified < $sanityCutoff ) {
$status = $tempRepo->quickPurge( "$dir/$file" );
if ( !$status->isOK() ) {
$this->error( print_r(
$status->getErrorsArray(), true ) );
diff --git a/maintenance/tables.sql b/maintenance/tables.sql
index d37ca47..616c2f0 100644
--- a/maintenance/tables.sql
+++ b/maintenance/tables.sql
@@ -1000,8 +1000,10 @@
-- image-specific properties
us_image_width int unsigned,
us_image_height int unsigned,
- us_image_bits smallint unsigned
+ us_image_bits smallint unsigned,
+ -- Custom time at which the file will expire
+ us_expiry varbinary(14) NULL default NULL,
) /*$wgDBTableOptions*/;
-- sometimes there's a delete for all of a user's stuff.
--
To view, visit https://gerrit.wikimedia.org/r/87607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I92599e5a508491a456b4edf32e2d43f4a44fed01
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits