Merge "[search] Fix method call on null value"
[lhc/web/wiklou.git] / includes / filebackend / SwiftFileBackend.php
index 6a0f2ee..83c1da1 100644 (file)
@@ -136,15 +136,15 @@ class SwiftFileBackend extends FileBackendStore {
                // Cache auth token information to avoid RTTs
                if ( !empty( $config['cacheAuthInfo'] ) ) {
                        if ( PHP_SAPI === 'cli' ) {
-                               $this->srvCache = wfGetMainCache(); // preferrably memcached
+                               // Preferrably memcached
+                               $this->srvCache = ObjectCache::getLocalClusterInstance();
                        } else {
-                               try { // look for APC, XCache, WinCache, ect...
-                                       $this->srvCache = ObjectCache::newAccelerator( array() );
-                               } catch ( Exception $e ) {
-                               }
+                               // Look for APC, XCache, WinCache, ect...
+                               $this->srvCache = ObjectCache::newAccelerator( CACHE_NONE );
                        }
+               } else {
+                       $this->srvCache = new EmptyBagOStuff();
                }
-               $this->srvCache = $this->srvCache ?: new EmptyBagOStuff();
        }
 
        public function getFeatures() {
@@ -262,7 +262,9 @@ class SwiftFileBackend extends FileBackendStore {
                }
 
                $sha1Hash = wfBaseConvert( sha1( $params['content'] ), 16, 36, 31 );
-               $contentType = $this->getContentType( $params['dst'], $params['content'], null );
+               $contentType = isset( $params['headers']['content-type'] )
+                       ? $params['headers']['content-type']
+                       : $this->getContentType( $params['dst'], $params['content'], null );
 
                $reqs = array( array(
                        'method' => 'PUT',
@@ -318,7 +320,9 @@ class SwiftFileBackend extends FileBackendStore {
                        return $status;
                }
                $sha1Hash = wfBaseConvert( $sha1Hash, 16, 36, 31 );
-               $contentType = $this->getContentType( $params['dst'], null, $params['src'] );
+               $contentType = isset( $params['headers']['content-type'] )
+                       ? $params['headers']['content-type']
+                       : $this->getContentType( $params['dst'], null, $params['src'] );
 
                $handle = fopen( $params['src'], 'rb' );
                if ( $handle === false ) { // source doesn't exist?
@@ -716,6 +720,11 @@ class SwiftFileBackend extends FileBackendStore {
                        return $objHdrs; // failed
                }
 
+               // Find prior custom HTTP headers
+               $postHeaders = $this->getCustomHeaders( $objHdrs );
+               // Find prior metadata headers
+               $postHeaders += $this->getMetadataHeaders( $objHdrs );
+
                $status = Status::newGood();
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scopeLockS = $this->getScopedFileLocks( array( $path ), LockManager::LOCK_UW, $status );
@@ -725,11 +734,13 @@ class SwiftFileBackend extends FileBackendStore {
                                $hash = $tmpFile->getSha1Base36();
                                if ( $hash !== false ) {
                                        $objHdrs['x-object-meta-sha1base36'] = $hash;
+                                       // Merge new SHA1 header into the old ones
+                                       $postHeaders['x-object-meta-sha1base36'] = $hash;
                                        list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $path );
-                                       list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->http->run( array(
+                                       list( $rcode ) = $this->http->run( array(
                                                'method' => 'POST',
                                                'url' => $this->storageUrl( $auth, $srcCont, $srcRel ),
-                                               'headers' => $this->authTokenHeaders( $auth ) + $objHdrs
+                                               'headers' => $this->authTokenHeaders( $auth ) + $postHeaders
                                        ) );
                                        if ( $rcode >= 200 && $rcode <= 299 ) {
                                                $this->deleteFileCache( $path );