88 $batches = $this->storeFactory->getUrlsByProtocol( $urls );
90 foreach ( $batches as $proto => $batchedUrls ) {
91 $store = $this->storeFactory->getStore( $proto, $params );
92 $retval += $store->batchFetchFromURLs( $batchedUrls );
95 $missing = array_diff( $urls, array_keys( $retval ) );
96 foreach ( $missing as
$url ) {
97 $retval[
$url] =
false;
118 public function insert( $data, array $params = [], ?array $tryStores =
null ) {
119 $tryStores ??= $this->storeFactory->getWriteBaseUrls();
126 while ( count( $tryStores ) > 0 ) {
127 $index = mt_rand( 0, count( $tryStores ) - 1 );
128 $storeUrl = $tryStores[$index];
130 $this->logger->debug( __METHOD__ .
": trying $storeUrl" );
132 $store = $this->storeFactory->getStoreForUrl( $storeUrl, $params );
133 if ( $store ===
false ) {
137 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
139 if ( $store->isReadOnly( $location ) ) {
143 $url = $store->store( $location, $data );
144 if (
$url !==
false &&
$url !==
'' ) {
149 "No URL returned by storage medium ($storeUrl)"
152 }
catch ( TimeoutException $e ) {
154 }
catch ( Exception $ex ) {
156 $msg =
'caught ' . get_class( $error ) .
' exception: ' . $error->getMessage();
159 unset( $tryStores[$index] );
160 $tryStores = array_values( $tryStores );
161 $this->logger->error(
162 "Unable to store text to external storage {store_path} ({failure})",
163 [
'store_path' => $storeUrl,
'failure' => $msg ]
171 } elseif ( $readOnlyCount ) {
178 throw new LogicException(
"Unexpected failure to store text to external store" );
188 if ( $storeUrls ===
null ) {
189 $storeUrls = $this->storeFactory->getWriteBaseUrls();
191 $storeUrls = is_array( $storeUrls ) ? $storeUrls : [ $storeUrls ];
198 foreach ( $storeUrls as $storeUrl ) {
199 $store = $this->storeFactory->getStoreForUrl( $storeUrl );
200 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
201 if ( $store !==
false && !$store->isReadOnly( $location ) ) {