76 $batches = $this->storeFactory->getUrlsByProtocol( $urls );
78 foreach ( $batches as $proto => $batchedUrls ) {
79 $store = $this->storeFactory->getStore( $proto, $params );
80 $retval += $store->batchFetchFromURLs( $batchedUrls );
83 $missing = array_diff( $urls, array_keys( $retval ) );
84 foreach ( $missing as
$url ) {
85 $retval[
$url] =
false;
106 public function insert( $data, array $params = [], ?array $tryStores =
null ) {
107 $tryStores ??= $this->storeFactory->getWriteBaseUrls();
114 while ( count( $tryStores ) > 0 ) {
115 $index = mt_rand( 0, count( $tryStores ) - 1 );
116 $storeUrl = $tryStores[$index];
118 $this->logger->debug( __METHOD__ .
": trying $storeUrl" );
120 $store = $this->storeFactory->getStoreForUrl( $storeUrl, $params );
121 if ( $store ===
false ) {
125 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
127 if ( $store->isReadOnly( $location ) ) {
131 $url = $store->store( $location, $data );
132 if (
$url !==
false &&
$url !==
'' ) {
137 "No URL returned by storage medium ($storeUrl)"
142 $msg =
'caught ' . get_class( $error ) .
' exception: ' . $error->getMessage();
145 unset( $tryStores[$index] );
146 $tryStores = array_values( $tryStores );
147 $this->logger->error(
148 "Unable to store text to external storage {store_path} ({failure})",
149 [
'store_path' => $storeUrl,
'failure' => $msg ]
157 } elseif ( $readOnlyCount ) {
164 throw new LogicException(
"Unexpected failure to store text to external store" );
174 if ( $storeUrls ===
null ) {
175 $storeUrls = $this->storeFactory->getWriteBaseUrls();
177 $storeUrls = is_array( $storeUrls ) ? $storeUrls : [ $storeUrls ];
184 foreach ( $storeUrls as $storeUrl ) {
185 $store = $this->storeFactory->getStoreForUrl( $storeUrl );
186 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
187 if ( $store !==
false && !$store->isReadOnly( $location ) ) {