26 return 'external-domains';
31 return [
'VirtualDomains',
'services' ];
36 $status = $this->createVirtualDomains();
37 $status->merge( $this->createExternalStoreDomains() );
46 private function createVirtualDomains():
Status {
47 $status =
Status::newGood();
48 foreach ( $this->getVirtualDomains() as $virtualDomain ) {
49 if ( !$this->shouldDoShared()
50 && $this->lbFactory->isSharedVirtualDomain( $virtualDomain )
52 $status->
warning(
'config-skip-shared-domain', $virtualDomain );
56 if ( $this->lbFactory->isLocalDomain( $virtualDomain ) ) {
60 $lb = $this->lbFactory->getLoadBalancer( $virtualDomain );
61 $realDomainId = $this->lbFactory->getMappedDomain( $virtualDomain );
62 $status->merge( $this->maybeCreateDomain( $lb, $realDomainId ) );
68 private function createExternalStoreDomains(): Status {
69 $status = Status::newGood();
70 $localDomainId = $this->lbFactory->getLocalDomainID();
71 foreach ( $this->esFactory->getWriteBaseUrls() as
$url ) {
72 $store = $this->esFactory->getStoreForUrl(
$url );
73 if ( $store instanceof ExternalStoreDB ) {
74 $cluster = $store->getClusterForUrl(
$url );
75 if ( $cluster ===
null ) {
76 throw new \RuntimeException(
"Invalid store url \"$url\"" );
78 $lb = $this->lbFactory->getExternalLB( $cluster );
79 $domainId = $store->getDomainIdForCluster( $cluster );
80 if ( $domainId !==
false && $domainId !== $localDomainId && !$this->shouldDoShared() ) {
82 $status->warning(
'config-skip-shared-domain',
"$cluster/$domainId" );
85 $status->merge( $this->maybeCreateDomain( $lb, $domainId ) );
87 $conn = $lb->getMaintenanceConnectionRef(
DB_PRIMARY, [], $domainId );
88 $conn->setSchemaVars( $this->
getContext()->getSchemaVars() );
89 if ( !$conn->tableExists( $store->getTable( $cluster ), __METHOD__ ) ) {
90 $store->initializeTable( $cluster );
107 private function maybeCreateDomain( $lb, $domainId ) {
108 $databaseCreator = $this->getDatabaseCreator();
109 if ( $domainId ===
false ) {
110 $domainId = $this->lbFactory->getLocalDomainID();
112 $database = DatabaseDomain::newFromId( $domainId )->getDatabase();
113 if ( !$databaseCreator->existsInLoadBalancer( $lb, $database ) ) {
114 return $databaseCreator->createInLoadBalancer( $lb, $database );
116 return Status::newGood();
124 private function shouldDoShared() {
125 return (
bool)$this->getOption(
'Shared' );