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();
103 while ( count( $tryStores ) > 0 ) {
104 $index = mt_rand( 0, count( $tryStores ) - 1 );
105 $storeUrl = $tryStores[$index];
107 $this->logger->debug( __METHOD__ .
": trying $storeUrl\n" );
109 $store = $this->storeFactory->getStoreForUrl( $storeUrl, $params );
110 if ( $store ===
false ) {
114 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
116 if ( $store->isReadOnly( $location ) ) {
119 $url = $store->store( $location, $data );
120 if ( strlen( $url ) ) {
123 $msg =
'operation failed';
125 }
catch ( Exception $error ) {
126 $msg =
'caught ' . get_class( $error ) .
' exception: ' . $error->getMessage();
129 unset( $tryStores[$index] );
130 $tryStores = array_values( $tryStores );
131 $this->logger->error(
132 "Unable to store text to external storage {store_path} ({failure})",
133 [
'store_path' => $storeUrl,
'failure' => $msg ]
150 if ( $storeUrls ===
null ) {
151 $storeUrls = $this->storeFactory->getWriteBaseUrls();
153 $storeUrls = is_array( $storeUrls ) ? $storeUrls : [ $storeUrls ];
160 foreach ( $storeUrls as $storeUrl ) {
161 $store = $this->storeFactory->getStoreForUrl( $storeUrl );
162 $location = $this->storeFactory->getStoreLocationFromUrl( $storeUrl );
163 if ( $store !==
false && !$store->isReadOnly( $location ) ) {