jenkins-bot has submitted this change and it was merged.

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, 19 insertions(+), 3 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  Parent5446: Looks good to me, but someone else must approve
  Matthias Mullie: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/externalstore/ExternalStore.php 
b/includes/externalstore/ExternalStore.php
index b5139d6..aa89add 100644
--- a/includes/externalstore/ExternalStore.php
+++ b/includes/externalstore/ExternalStore.php
@@ -156,9 +156,10 @@
        /**
         * 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 @@
        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];

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I72cf2514265e052b839e0ac31c171e91727fb9af
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson (WMF) <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: EBernhardson (WMF) <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Werdna <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to