73 $batches = $this->storeFactory->getUrlsByProtocol( $urls );
75 foreach ( $batches as $proto => $batchedUrls ) {
76 $store = $this->storeFactory->getStore( $proto, $params );
77 $retval += $store->batchFetchFromURLs( $batchedUrls );
80 $missing = array_diff( $urls, array_keys( $retval ) );
81 foreach ( $missing as
$url ) {
82 $retval[
$url] =
false;
103 public function insert( $data, array $params = [], ?array $tryStores =
null ) {
104 $tryStores ??= $this->storeFactory->getWriteBaseUrls();
111 while ( count( $tryStores ) > 0 ) {
112 $index = mt_rand( 0, count( $tryStores ) - 1 );
113 $storeUrl = $tryStores[$index];
115 $this->logger->debug( __METHOD__ .
": trying $storeUrl" );
117 $store = $this->storeFactory->getStoreForUrl( $storeUrl, $params );
118 if ( $store ===
false ) {
122 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
124 if ( $store->isReadOnly( $location ) ) {
128 $url = $store->store( $location, $data );
129 if (
$url !==
false &&
$url !==
'' ) {
134 "No URL returned by storage medium ($storeUrl)"
139 $msg =
'caught ' . get_class( $error ) .
' exception: ' . $error->getMessage();
142 unset( $tryStores[$index] );
143 $tryStores = array_values( $tryStores );
144 $this->logger->error(
145 "Unable to store text to external storage {store_path} ({failure})",
146 [
'store_path' => $storeUrl,
'failure' => $msg ]
154 } elseif ( $readOnlyCount ) {
161 throw new LogicException(
"Unexpected failure to store text to external store" );
171 if ( $storeUrls ===
null ) {
172 $storeUrls = $this->storeFactory->getWriteBaseUrls();
174 $storeUrls = is_array( $storeUrls ) ? $storeUrls : [ $storeUrls ];
181 foreach ( $storeUrls as $storeUrl ) {
182 $store = $this->storeFactory->getStoreForUrl( $storeUrl );
183 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
184 if ( $store !==
false && !$store->isReadOnly( $location ) ) {