Fixed spacing
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 4edcebf..2cd4f90 100644 (file)
@@ -539,7 +539,7 @@ class LocalFile extends File {
                                'img_media_type' => $this->media_type,
                                'img_major_mime' => $major,
                                'img_minor_mime' => $minor,
-                               'img_metadata' => $this->metadata,
+                               'img_metadata' => $dbw->encodeBlob( $this->metadata ),
                                'img_sha1' => $this->sha1,
                        ),
                        array( 'img_name' => $this->getName() ),
@@ -788,10 +788,12 @@ class LocalFile extends File {
 
                $backend = $this->repo->getBackend();
                $files = array( $dir );
-               $iterator = $backend->getFileList( array( 'dir' => $dir ) );
-               foreach ( $iterator as $file ) {
-                       $files[] = $file;
-               }
+               try {
+                       $iterator = $backend->getFileList( array( 'dir' => $dir ) );
+                       foreach ( $iterator as $file ) {
+                               $files[] = $file;
+                       }
+               } catch ( FileBackendError $e ) {} // suppress (bug 54674)
 
                return $files;
        }
@@ -1223,7 +1225,7 @@ class LocalFile extends File {
                                'img_description' => $comment,
                                'img_user' => $user->getId(),
                                'img_user_text' => $user->getName(),
-                               'img_metadata' => $this->metadata,
+                               'img_metadata' => $dbw->encodeBlob( $this->metadata ),
                                'img_sha1' => $this->sha1
                        ),
                        __METHOD__,
@@ -1274,7 +1276,7 @@ class LocalFile extends File {
                                        'img_description' => $comment,
                                        'img_user'        => $user->getId(),
                                        'img_user_text'   => $user->getName(),
-                                       'img_metadata'    => $this->metadata,
+                                       'img_metadata'    => $dbw->encodeBlob( $this->metadata ),
                                        'img_sha1'        => $this->sha1
                                ),
                                array( 'img_name' => $this->getName() ),
@@ -1369,7 +1371,6 @@ class LocalFile extends File {
                        $dbw->commit( __METHOD__ ); // commit before anything bad can happen
                }
 
-
                wfProfileOut( __METHOD__ . '-edit' );
 
                # Save to cache and purge the squid
@@ -1505,18 +1506,27 @@ class LocalFile extends File {
 
                wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
 
-               $this->purgeEverything();
-               foreach ( $archiveNames as $archiveName ) {
-                       $this->purgeOldThumbnails( $archiveName );
-               }
+               // Purge the source and target files...
+               $oldTitleFile = wfLocalFile( $this->title );
+               $newTitleFile = wfLocalFile( $target );
+               // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
+               // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
+               $this->getRepo()->getMasterDB()->onTransactionIdle(
+                       function() use ( $oldTitleFile, $newTitleFile, $archiveNames ) {
+                               $oldTitleFile->purgeEverything();
+                               foreach ( $archiveNames as $archiveName ) {
+                                       $oldTitleFile->purgeOldThumbnails( $archiveName );
+                               }
+                               $newTitleFile->purgeEverything();
+                       }
+               );
+
                if ( $status->isOK() ) {
                        // Now switch the object
                        $this->title = $target;
                        // Force regeneration of the name and hashpath
                        unset( $this->name );
                        unset( $this->hashPath );
-                       // Purge the new image
-                       $this->purgeEverything();
                }
 
                return $status;
@@ -1762,6 +1772,16 @@ class LocalFile extends File {
                                $this->lockedOwnTrx = true;
                        }
                        $this->locked++;
+                       // Bug 54736: use simple lock to handle when the file does not exist.
+                       // SELECT FOR UPDATE only locks records not the gaps where there are none.
+                       $cache = wfGetMainCache();
+                       $key = $this->getCacheKey();
+                       if ( !$cache->lock( $key, 60 ) ) {
+                               throw new MWException( "Could not acquire lock for '{$this->getName()}.'" );
+                       }
+                       $dbw->onTransactionIdle( function() use ( $cache, $key ) {
+                               $cache->unlock( $key ); // release on commit
+                       } );
                }
 
                return $dbw->selectField( 'image', '1',