| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Storage; |
| 22 |
|
| 23 |
use ExternalStoreAccess; |
| 24 |
use MediaWiki\Config\ServiceOptions; |
| 25 |
use MediaWiki\MainConfigNames; |
| 26 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 27 |
use Wikimedia\Rdbms\ILBFactory; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class BlobStoreFactory { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private $lbFactory; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
private $extStoreAccess; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
private $cache; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
private $options; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public const CONSTRUCTOR_OPTIONS = [ |
| 62 |
MainConfigNames::CompressRevisions, |
| 63 |
MainConfigNames::DefaultExternalStore, |
| 64 |
MainConfigNames::LegacyEncoding, |
| 65 |
MainConfigNames::RevisionCacheExpiry, |
| 66 |
]; |
| 67 |
|
| 68 |
public function __construct( |
| 69 |
ILBFactory $lbFactory, |
| 70 |
ExternalStoreAccess $extStoreAccess, |
| 71 |
WANObjectCache $cache, |
| 72 |
ServiceOptions $options |
| 73 |
) { |
| 74 |
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 75 |
|
| 76 |
$this->lbFactory = $lbFactory; |
| 77 |
$this->extStoreAccess = $extStoreAccess; |
| 78 |
$this->cache = $cache; |
| 79 |
$this->options = $options; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public function newBlobStore( $dbDomain = false ) { |
| 90 |
return $this->newSqlBlobStore( $dbDomain ); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public function newSqlBlobStore( $dbDomain = false ) { |
| 101 |
$lb = $this->lbFactory->getMainLB( $dbDomain ); |
| 102 |
$store = new SqlBlobStore( |
| 103 |
$lb, |
| 104 |
$this->extStoreAccess, |
| 105 |
$this->cache, |
| 106 |
$dbDomain |
| 107 |
); |
| 108 |
|
| 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 ); |
| 113 |
|
| 114 |
if ( $this->options->get( MainConfigNames::LegacyEncoding ) ) { |
| 115 |
$store->setLegacyEncoding( $this->options->get( MainConfigNames::LegacyEncoding ) ); |
| 116 |
} |
| 117 |
|
| 118 |
return $store; |
| 119 |
} |
| 120 |
|
| 121 |
} |