Made LocalFile avoid duplicate (name,timestamp) pairs
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 13 May 2014 22:03:32 +0000 (15:03 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 13 May 2014 22:03:32 +0000 (15:03 -0700)
* Various bits of code seem to assume uniqueness already

bug: 65264
Change-Id: Ib00fdbe87a79296c640cd69d74928236ce7a4aee

includes/filerepo/file/LocalFile.php

index 73ab04d..e8f70fc 100644 (file)
@@ -1249,7 +1249,17 @@ class LocalFile extends File {
                }
 
                if ( $timestamp === false ) {
-                       $timestamp = $dbw->timestamp();
+                       $ltimestamp = $dbw->selectField( 'image', 'img_timestamp',
+                               array( 'img_name' => $this->getName() ), __METHOD__ );
+                       $ltime = $ltimestamp ? wfTimestamp( TS_UNIX, $ltimestamp ) : false;
+                       $ctime = time();
+                       // Avoid a timestamp that is not newer than the last version
+                       if ( $ctime > $ltime ) {
+                               $timestamp = $dbw->timestamp( $ctime );
+                       } else {
+                               sleep( 1 ); // fast enough uploads will go in to the future otherwise
+                               $timestamp = $dbw->timestamp( $ltime + 1 );
+                       }
                }
 
                $props['description'] = $comment;