EBernhardson (WMF) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77979


Change subject: Reusable external store insertion with fallback
......................................................................

Reusable external store insertion with fallback

Minor refactor allows insertion to ES from an alternate set of backend servers.

Change-Id: I72cf2514265e052b839e0ac31c171e91727fb9af
---
M includes/externalstore/ExternalStore.php
1 file changed, 18 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/79/77979/1

diff --git a/includes/externalstore/ExternalStore.php 
b/includes/externalstore/ExternalStore.php
index b5139d6..e587fb4 100644
--- a/includes/externalstore/ExternalStore.php
+++ b/includes/externalstore/ExternalStore.php
@@ -156,7 +156,8 @@
        /**
         * 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 array $params Associative array of ExternalStoreMedium 
parameters
@@ -166,8 +167,23 @@
        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 $tryStores array refer to $wgDefaultExternalStore
+        * @param $data string
+        * @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];

-- 
To view, visit https://gerrit.wikimedia.org/r/77979
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I72cf2514265e052b839e0ac31c171e91727fb9af
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson (WMF) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to