X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fexternalstore%2FExternalStore.php;h=9cf8e15d838f307988e3b772a958e70638a1abb3;hb=ddb5586c92188119b17c64f56d4948a39f141ff0;hp=3beab29532eab4b4acf6b7361764c037b03f3a70;hpb=917a4fe05af7c1f7fad347bb7c60f5107ba1b140;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/externalstore/ExternalStore.php b/includes/externalstore/ExternalStore.php index 3beab29532..9cf8e15d83 100644 --- a/includes/externalstore/ExternalStore.php +++ b/includes/externalstore/ExternalStore.php @@ -92,6 +92,7 @@ class ExternalStore { * @param array $urls The URLs of the text to get * @return array Map from url to its data. Data is either string when found * or false on failure. + * @throws MWException */ public static function batchFetchFromURLs( array $urls ) { $batches = []; @@ -157,7 +158,7 @@ class ExternalStore { * provided by $wgDefaultExternalStore. * * @param string $data - * @param array $params Associative array of ExternalStoreMedium parameters + * @param array $params Map of ExternalStoreMedium::__construct context parameters * @return string|bool The URL of the stored data item, or false on error * @throws MWException */ @@ -175,7 +176,7 @@ class ExternalStore { * * @param array $tryStores Refer to $wgDefaultExternalStore * @param string $data - * @param array $params Associative array of ExternalStoreMedium parameters + * @param array $params Map of ExternalStoreMedium::__construct context parameters * @return string|bool The URL of the stored data item, or false on error * @throws MWException */ @@ -190,19 +191,25 @@ class ExternalStore { if ( $store === false ) { throw new MWException( "Invalid external storage protocol - $storeUrl" ); } + try { - $url = $store->store( $path, $data ); // Try to save the object + if ( $store->isReadOnly( $path ) ) { + $msg = 'read only'; + } else { + $url = $store->store( $path, $data ); + if ( $url !== false ) { + return $url; // a store accepted the write; done! + } + $msg = 'operation failed'; + } } catch ( Exception $error ) { - $url = false; - } - if ( strlen( $url ) ) { - return $url; // Done! - } else { - unset( $tryStores[$index] ); // Don't try this one again! - $tryStores = array_values( $tryStores ); // Must have consecutive keys - wfDebugLog( 'ExternalStorage', - "Unable to store text to external storage $storeUrl" ); + $msg = 'caught exception'; } + + unset( $tryStores[$index] ); // Don't try this one again! + $tryStores = array_values( $tryStores ); // Must have consecutive keys + wfDebugLog( 'ExternalStorage', + "Unable to store text to external storage $storeUrl ($msg)" ); } // All stores failed if ( $error ) { @@ -212,6 +219,29 @@ class ExternalStore { } } + /** + * @return bool Whether all the default insertion stores are marked as read-only + * @since 1.31 + */ + public static function defaultStoresAreReadOnly() { + global $wgDefaultExternalStore; + + $tryStores = (array)$wgDefaultExternalStore; + if ( !$tryStores ) { + return false; // no stores exists which can be "read only" + } + + foreach ( $tryStores as $storeUrl ) { + list( $proto, $path ) = explode( '://', $storeUrl, 2 ); + $store = self::getStoreObject( $proto, [] ); + if ( !$store->isReadOnly( $path ) ) { + return false; // at least one store is not read-only + } + } + + return true; // all stores are read-only + } + /** * @param string $data * @param string $wiki