diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index 73c7bf72741..587af72b4df 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -386,22 +386,22 @@ class JobQueueDB extends JobQueue { } } - if ( $row ) { // claim the job - $dbw->update( 'job', // update by PK - [ - 'job_token' => $uuid, - 'job_token_timestamp' => $dbw->timestamp(), - 'job_attempts = job_attempts+1' ], - [ 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ], - __METHOD__ - ); - // This might get raced out by another runner when claiming the previously - // selected row. The use of job_random should minimize this problem, however. - if ( !$dbw->affectedRows() ) { - $row = false; // raced out - } - } else { - break; // nothing to do + if ( !$row ) { + break; + } + + $dbw->update( 'job', // update by PK + [ + 'job_token' => $uuid, + 'job_token_timestamp' => $dbw->timestamp(), + 'job_attempts = job_attempts+1' ], + [ 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ], + __METHOD__ + ); + // This might get raced out by another runner when claiming the previously + // selected row. The use of job_random should minimize this problem, however. + if ( !$dbw->affectedRows() ) { + $row = false; // raced out } } while ( !$row ); @@ -455,16 +455,17 @@ class JobQueueDB extends JobQueue { __METHOD__ ); } + + if ( !$dbw->affectedRows() ) { + break; + } + // Fetch any row that we just reserved... - if ( $dbw->affectedRows() ) { - $row = $dbw->selectRow( 'job', self::selectFields(), - [ 'job_cmd' => $this->type, 'job_token' => $uuid ], __METHOD__ - ); - if ( !$row ) { // raced out by duplicate job removal - wfDebug( "Row deleted as duplicate by another process." ); - } - } else { - break; // nothing to do + $row = $dbw->selectRow( 'job', self::selectFields(), + [ 'job_cmd' => $this->type, 'job_token' => $uuid ], __METHOD__ + ); + if ( !$row ) { // raced out by duplicate job removal + wfDebug( "Row deleted as duplicate by another process." ); } } while ( !$row ); diff --git a/includes/libs/filebackend/SwiftFileBackend.php b/includes/libs/filebackend/SwiftFileBackend.php index d0fbae5ba50..deee125d9b4 100644 --- a/includes/libs/filebackend/SwiftFileBackend.php +++ b/includes/libs/filebackend/SwiftFileBackend.php @@ -207,19 +207,14 @@ class SwiftFileBackend extends FileBackendStore { $contentHeaders[$name] = $value; } // By default, Swift has annoyingly low maximum header value limits - if ( isset( $contentHeaders['content-disposition'] ) ) { - $disposition = ''; - // @note: assume FileBackend::makeContentDisposition() already used - foreach ( explode( ';', $contentHeaders['content-disposition'] ) as $part ) { - $part = trim( $part ); - $new = ( $disposition === '' ) ? $part : "{$disposition};{$part}"; - if ( strlen( $new ) <= 255 ) { - $disposition = $new; - } else { - break; // too long; sigh - } - } - $contentHeaders['content-disposition'] = $disposition; + $maxLength = 255; + // @note: assume FileBackend::makeContentDisposition() already used + $offset = $maxLength - strlen( $contentHeaders['content-disposition'] ); + if ( $offset < 0 ) { + $pos = strrpos( $contentHeaders['content-disposition'], ';', $offset ); + $contentHeaders['content-disposition'] = $pos === false + ? '' + : trim( substr( $contentHeaders['content-disposition'], 0, $pos ) ); } return $contentHeaders; diff --git a/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php b/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php index 5492deca182..676dc58cc7e 100644 --- a/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php +++ b/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php @@ -73,7 +73,7 @@ class SwiftFileBackendTest extends MediaWikiIntegrationTestCase { ], [ 'content-type' => 'image+bitmap/jpeg', - 'content-disposition' => 'inline;filename=xxx', + 'content-disposition' => 'inline; filename=xxx', 'content-duration' => 35.6363, 'content-custom' => 'hello', 'x-content-custom' => 'hello'