3 * Service for loading and storing data blobs.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Storage
;
28 * Service for loading and storing data blobs.
30 * @note This was written to act as a drop-in replacement for the corresponding
31 * static methods in Revision.
38 * Hint key for use with storeBlob, indicating the general role the block
39 * takes in the application. For instance, it should be "page-content" if
40 * the blob represents a Content object.
42 const DESIGNATION_HINT
= 'designation';
45 * Hint key for use with storeBlob, indicating the page the blob is associated with.
46 * This may be used for sharding.
48 const PAGE_HINT
= 'page_id';
51 * Hint key for use with storeBlob, indicating the slot the blob is associated with.
52 * May be relevant for reference counting.
54 const ROLE_HINT
= 'role_name';
57 * Hint key for use with storeBlob, indicating the revision the blob is associated with.
58 * This may be used for differential storage and reference counting.
60 const REVISION_HINT
= 'rev_id';
63 * Hint key for use with storeBlob, indicating the parent revision of the revision
64 * the blob is associated with. This may be used for differential storage.
66 const PARENT_HINT
= 'rev_parent_id';
69 * Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the
70 * method. This can be used to avoid re-calculating the hash if it is needed by the BlobStore.
72 const SHA1_HINT
= 'cont_sha1';
75 * Hint key for use with storeBlob, indicating the model of the content encoded in the
76 * given blob. May be used to implement optimized storage for some well known models.
78 const MODEL_HINT
= 'cont_model';
81 * Hint key for use with storeBlob, indicating the serialization format used to create
82 * the blob, as a MIME type. May be used for optimized storage in the underlying database.
84 const FORMAT_HINT
= 'cont_format';
87 * Retrieve a blob, given an address.
89 * MCR migration note: this replaces Revision::loadText
91 * @param string $blobAddress The blob address as returned by storeBlob(),
92 * such as "tt:12345" or "ex:DB://s16/456/9876".
93 * @param int $queryFlags See IDBAccessObject.
95 * @throws BlobAccessException
96 * @return string binary blob data
98 public function getBlob( $blobAddress, $queryFlags = 0 );
101 * A batched version of BlobStore::getBlob.
103 * @param string[] $blobAddresses An array of blob addresses.
104 * @param int $queryFlags See IDBAccessObject.
105 * @throws BlobAccessException
106 * @return StatusValue A status with a map of blobAddress => binary blob data or null
107 * if fetching the blob has failed. Fetch failures errors are the
108 * warnings in the status object.
111 public function getBlobBatch( $blobAddresses, $queryFlags = 0 );
114 * Stores an arbitrary blob of data and returns an address that can be used with
115 * getBlob() to retrieve the same blob of data,
117 * @param string $data raw binary data
118 * @param array $hints An array of hints. Implementations may use the hints to optimize storage.
119 * All hints are optional, supported hints depend on the implementation. Hint names by
120 * convention correspond to the names of fields in the database. Callers are encouraged to
121 * provide the well known hints as defined by the XXX_HINT constants.
123 * @throws BlobAccessException
124 * @return string an address that can be used with getBlob() to retrieve the data.
126 public function storeBlob( $data, $hints = [] );
129 * Check if the blob metadata or backing blob data store is read-only
133 public function isReadOnly();