From 660627f1444888f6b98141a94fc61ff9c770dbe2 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Tue, 6 Aug 2013 14:55:29 -0700 Subject: [PATCH] Reusable external store insertion with fallback Minor refactor allows insertion to ES from an alternate set of backend servers. Change-Id: I72cf2514265e052b839e0ac31c171e91727fb9af --- includes/externalstore/ExternalStore.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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]; -- 2.20.1