66 $batches = $this->storeFactory->getUrlsByProtocol( $urls );
68 foreach ( $batches as $proto => $batchedUrls ) {
69 $store = $this->storeFactory->getStore( $proto, $params );
70 $retval += $store->batchFetchFromURLs( $batchedUrls );
73 $missing = array_diff( $urls, array_keys( $retval ) );
74 foreach ( $missing as $url ) {
75 $retval[$url] =
false;
96 public function insert( $data, array $params = [], array $tryStores =
null ) {
97 $tryStores = $tryStores ?? $this->storeFactory->getWriteBaseUrls();
104 while ( count( $tryStores ) > 0 ) {
105 $index = mt_rand( 0, count( $tryStores ) - 1 );
106 $storeUrl = $tryStores[$index];
108 $this->logger->debug( __METHOD__ .
": trying $storeUrl" );
110 $store = $this->storeFactory->getStoreForUrl( $storeUrl, $params );
111 if ( $store ===
false ) {
115 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
117 if ( $store->isReadOnly( $location ) ) {
121 $url = $store->store( $location, $data );
122 if ( strlen( $url ) ) {
127 "No URL returned by storage medium ($storeUrl)"
130 }
catch ( Exception $ex ) {
132 $msg =
'caught ' . get_class( $error ) .
' exception: ' . $error->getMessage();
135 unset( $tryStores[$index] );
136 $tryStores = array_values( $tryStores );
137 $this->logger->error(
138 "Unable to store text to external storage {store_path} ({failure})",
139 [
'store_path' => $storeUrl,
'failure' => $msg ]
147 } elseif ( $readOnlyCount ) {
154 throw new LogicException(
"Unexpected failure to store text to external store" );
164 if ( $storeUrls ===
null ) {
165 $storeUrls = $this->storeFactory->getWriteBaseUrls();
167 $storeUrls = is_array( $storeUrls ) ? $storeUrls : [ $storeUrls ];
174 foreach ( $storeUrls as $storeUrl ) {
175 $store = $this->storeFactory->getStoreForUrl( $storeUrl );
176 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
177 if ( $store !==
false && !$store->isReadOnly( $location ) ) {