// Once the second operation goes through, then the current version was
// updated and we must therefore update the DB too.
$oldver = $status->value;
- if ( !$this->recordUpload2( $oldver, $comment, $pageText, $props, $timestamp, $user, $tags ) ) {
- $status->fatal( 'filenotfound', $srcPath );
+ $uploadStatus = $this->recordUpload2(
+ $oldver,
+ $comment,
+ $pageText,
+ $props,
+ $timestamp,
+ $user,
+ $tags
+ );
+ if ( !$uploadStatus->isOK() ) {
+ if ( $uploadStatus->hasMessage( 'filenotfound' ) ) {
+ // update filenotfound error with more specific path
+ $status->fatal( 'filenotfound', $srcPath );
+ } else {
+ $status->merge( $uploadStatus );
+ }
}
}
$pageText = SpecialUpload::getInitialPageText( $desc, $license, $copyStatus, $source );
- if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp, $user ) ) {
+ if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp, $user )->isOK() ) {
return false;
}
* @param string|bool $timestamp
* @param null|User $user
* @param string[] $tags
- * @return bool
+ * @return Status
*/
function recordUpload2(
$oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = []
if ( !$this->fileExists ) {
wfDebug( __METHOD__ . ": File " . $this->getRel() . " went missing!\n" );
- return false;
+ return Status::newFatal( 'filenotfound', $this->getRel() );
}
$dbw->startAtomic( __METHOD__ );
$reupload = ( $dbw->affectedRows() == 0 );
if ( $reupload ) {
+ $row = $dbw->selectRow(
+ 'image',
+ [ 'img_timestamp', 'img_sha1' ],
+ [ 'img_name' => $this->getName() ],
+ __METHOD__,
+ [ 'LOCK IN SHARE MODE' ]
+ );
+
+ if ( $row && $row->img_sha1 === $this->sha1 ) {
+ $dbw->endAtomic( __METHOD__ );
+ wfDebug( __METHOD__ . ": File " . $this->getRel() . " already exists!\n" );
+ $title = Title::newFromText( $this->getName(), NS_FILE );
+ return Status::newFatal( 'fileexists-no-change', $title->getPrefixedText() );
+ }
+
if ( $allowTimeKludge ) {
# Use LOCK IN SHARE MODE to ignore any transaction snapshotting
- $ltimestamp = $dbw->selectField(
- 'image',
- 'img_timestamp',
- [ 'img_name' => $this->getName() ],
- __METHOD__,
- [ 'LOCK IN SHARE MODE' ]
- );
- $lUnixtime = $ltimestamp ? wfTimestamp( TS_UNIX, $ltimestamp ) : false;
+ $lUnixtime = $row ? wfTimestamp( TS_UNIX, $row->img_timestamp ) : false;
# Avoid a timestamp that is not newer than the last version
# TODO: the image/oldimage tables should be like page/revision with an ID field
if ( $lUnixtime && wfTimestamp( TS_UNIX, $timestamp ) <= $lUnixtime ) {
# Invalidate cache for all pages using this file
DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' ) );
- return true;
+ return Status::newGood();
}
/**