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.
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.
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
21 namespace MediaWiki\Storage
;
23 use ExternalStoreAccess
;
24 use MediaWiki\Config\ServiceOptions
;
25 use MediaWiki\MainConfigNames
;
27 use Wikimedia\Rdbms\ILBFactory
;
30 * Service for instantiating BlobStores
32 * This can be used to create BlobStore objects for other wikis.
36 class BlobStoreFactory
{
44 * @var ExternalStoreAccess
46 private $extStoreAccess;
59 * @internal For use by ServiceWiring
61 public const CONSTRUCTOR_OPTIONS
= [
62 MainConfigNames
::CompressRevisions
,
63 MainConfigNames
::DefaultExternalStore
,
64 MainConfigNames
::LegacyEncoding
,
65 MainConfigNames
::RevisionCacheExpiry
,
68 public function __construct(
69 ILBFactory
$lbFactory,
70 ExternalStoreAccess
$extStoreAccess,
71 WANObjectCache
$cache,
72 ServiceOptions
$options
74 $options->assertRequiredOptions( self
::CONSTRUCTOR_OPTIONS
);
76 $this->lbFactory
= $lbFactory;
77 $this->extStoreAccess
= $extStoreAccess;
78 $this->cache
= $cache;
79 $this->options
= $options;
85 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
89 public function newBlobStore( $dbDomain = false ) {
90 return $this->newSqlBlobStore( $dbDomain );
94 * @internal Please call newBlobStore and use the BlobStore interface.
96 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
98 * @return SqlBlobStore
100 public function newSqlBlobStore( $dbDomain = false ) {
101 $lb = $this->lbFactory
->getMainLB( $dbDomain );
102 $store = new SqlBlobStore(
104 $this->extStoreAccess
,
109 $store->setCompressBlobs( $this->options
->get( MainConfigNames
::CompressRevisions
) );
110 $store->setCacheExpiry( $this->options
->get( MainConfigNames
::RevisionCacheExpiry
) );
111 $store->setUseExternalStore(
112 $this->options
->get( MainConfigNames
::DefaultExternalStore
) !== false );
114 if ( $this->options
->get( MainConfigNames
::LegacyEncoding
) ) {
115 $store->setLegacyEncoding( $this->options
->get( MainConfigNames
::LegacyEncoding
) );