From: Erik Bernhardson Date: Tue, 6 Aug 2013 21:55:29 +0000 (-0700) Subject: Reusable external store insertion with fallback X-Git-Tag: 1.31.0-rc.0~19005^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=660627f1444888f6b98141a94fc61ff9c770dbe2;p=lhc%2Fweb%2Fwiklou.git Reusable external store insertion with fallback Minor refactor allows insertion to ES from an alternate set of backend servers. Change-Id: I72cf2514265e052b839e0ac31c171e91727fb9af --- diff --git a/includes/externalstore/ExternalStore.php b/includes/externalstore/ExternalStore.php index b5139d644a..aa89add220 100644 --- a/includes/externalstore/ExternalStore.php +++ b/includes/externalstore/ExternalStore.php @@ -156,9 +156,10 @@ class ExternalStore { /** * Like insert() above, but does more of the work for us. * This function does not need a url param, it builds it by - * itself. It also fails-over to the next possible clusters. + * itself. It also fails-over to the next possible clusters + * provided by $wgDefaultExternalStore. * - * @param $data string + * @param string $data * @param array $params Associative array of ExternalStoreMedium parameters * @return string|bool The URL of the stored data item, or false on error * @throws MWException @@ -166,8 +167,23 @@ class ExternalStore { public static function insertToDefault( $data, array $params = array() ) { global $wgDefaultExternalStore; + return self::insertWithFallback( (array) $wgDefaultExternalStore, $data, $params ); + } + + /** + * Like insert() above, but does more of the work for us. + * This function does not need a url param, it builds it by + * itself. It also fails-over to the next possible clusters + * as provided in the first parameter. + * + * @param array $tryStores refer to $wgDefaultExternalStore + * @param string $data + * @param array $params Associative array of ExternalStoreMedium parameters + * @return string|bool The URL of the stored data item, or false on error + * @throws MWException + */ + public static function insertWithFallback( array $tryStores, $data, array $params = array() ) { $error = false; - $tryStores = (array)$wgDefaultExternalStore; while ( count( $tryStores ) > 0 ) { $index = mt_rand( 0, count( $tryStores ) - 1 ); $storeUrl = $tryStores[$index];