Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
21.74% |
5 / 23 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
ExternalStore | |
21.74% |
5 / 23 |
|
14.29% |
1 / 7 |
57.93 | |
0.00% |
0 / 1 |
getStoreObject | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
fetchFromURL | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
insert | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
batchFetchFromURLs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
insertToDefault | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
insertWithFallback | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
insertToForeignDefault | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\MediaWikiServices; |
22 | |
23 | /** |
24 | * @ingroup ExternalStorage |
25 | * @deprecated since 1.34 Use the ExternalStoreAccess service instead. |
26 | */ |
27 | class ExternalStore { |
28 | /** |
29 | * Get an external store object of the given type, with the given parameters |
30 | * |
31 | * @param string $proto Type of external storage, should be a value in $wgExternalStores |
32 | * @param array $params Associative array of ExternalStoreMedium parameters |
33 | * @return ExternalStoreMedium|bool The store class or false on error |
34 | * @deprecated since 1.34 |
35 | */ |
36 | public static function getStoreObject( $proto, array $params = [] ) { |
37 | try { |
38 | return MediaWikiServices::getInstance() |
39 | ->getExternalStoreFactory() |
40 | ->getStore( $proto, $params ); |
41 | } catch ( ExternalStoreException $e ) { |
42 | return false; |
43 | } |
44 | } |
45 | |
46 | /** |
47 | * Fetch data from given URL |
48 | * |
49 | * @param string $url The URL of the text to get |
50 | * @param array $params Associative array of ExternalStoreMedium parameters |
51 | * @return string|bool The text stored or false on error |
52 | * @deprecated since 1.34 |
53 | */ |
54 | public static function fetchFromURL( $url, array $params = [] ) { |
55 | try { |
56 | return MediaWikiServices::getInstance() |
57 | ->getExternalStoreAccess() |
58 | ->fetchFromURL( $url, $params ); |
59 | } catch ( ExternalStoreException $e ) { |
60 | return false; |
61 | } |
62 | } |
63 | |
64 | /** |
65 | * Store a data item to an external store, identified by a partial URL |
66 | * The protocol part is used to identify the class, the rest is passed to the |
67 | * class itself as a parameter. |
68 | * |
69 | * @param string $url A partial external store URL ("<store type>://<location>") |
70 | * @param string $data |
71 | * @param array $params Associative array of ExternalStoreMedium parameters |
72 | * @return string|bool The URL of the stored data item, or false on error |
73 | * @deprecated since 1.34 |
74 | */ |
75 | public static function insert( $url, $data, array $params = [] ) { |
76 | try { |
77 | $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); |
78 | $location = $esFactory->getStoreLocationFromUrl( $url ); |
79 | |
80 | return $esFactory->getStoreForUrl( $url, $params )->store( $location, $data ); |
81 | } catch ( ExternalStoreException $e ) { |
82 | return false; |
83 | } |
84 | } |
85 | |
86 | /** |
87 | * Fetch data from multiple URLs with a minimum of round trips |
88 | * |
89 | * @param array $urls The URLs of the text to get |
90 | * @return array Map from url to its data. Data is either string when found |
91 | * or false on failure. |
92 | * @throws ExternalStoreException |
93 | * @deprecated since 1.34 |
94 | */ |
95 | public static function batchFetchFromURLs( array $urls ) { |
96 | return MediaWikiServices::getInstance()->getExternalStoreAccess()->fetchFromURLs( $urls ); |
97 | } |
98 | |
99 | /** |
100 | * Like insert() above, but does more of the work for us. |
101 | * This function does not need a url param, it builds it by |
102 | * itself. It also fails-over to the next possible clusters |
103 | * provided by $wgDefaultExternalStore. |
104 | * |
105 | * @param string $data |
106 | * @param array $params Map of ExternalStoreMedium::__construct context parameters |
107 | * @return string The URL of the stored data item |
108 | * @throws ExternalStoreException |
109 | * @deprecated since 1.34 |
110 | */ |
111 | public static function insertToDefault( $data, array $params = [] ) { |
112 | return MediaWikiServices::getInstance()->getExternalStoreAccess()->insert( $data, $params ); |
113 | } |
114 | |
115 | /** |
116 | * Like insert() above, but does more of the work for us. |
117 | * This function does not need a url param, it builds it by |
118 | * itself. It also fails-over to the next possible clusters |
119 | * as provided in the first parameter. |
120 | * |
121 | * @param array $tryStores Refer to $wgDefaultExternalStore |
122 | * @param string $data |
123 | * @param array $params Map of ExternalStoreMedium::__construct context parameters |
124 | * @return string The URL of the stored data item |
125 | * @throws ExternalStoreException |
126 | * @deprecated since 1.34 |
127 | */ |
128 | public static function insertWithFallback( array $tryStores, $data, array $params = [] ) { |
129 | return MediaWikiServices::getInstance() |
130 | ->getExternalStoreAccess() |
131 | ->insert( $data, $params, $tryStores ); |
132 | } |
133 | |
134 | /** |
135 | * @param string $data |
136 | * @param string $wiki |
137 | * @return string The URL of the stored data item |
138 | * @throws ExternalStoreException |
139 | * @deprecated since 1.34 Use insertToDefault() with 'wiki' set |
140 | */ |
141 | public static function insertToForeignDefault( $data, $wiki ) { |
142 | return MediaWikiServices::getInstance() |
143 | ->getExternalStoreAccess() |
144 | ->insert( $data, [ 'domain' => $wiki ] ); |
145 | } |
146 | } |