68 $dbr = $this->dbProvider->getReplicaDatabase();
70 $res = $dbr->newSelectQueryBuilder()
85 ->orderBy(
'site_global_key' )
86 ->caller( __METHOD__ )->fetchResultSet();
88 foreach ( $res as $row ) {
90 $site->setGlobalId( $row->site_global_key );
91 $site->setInternalId( (
int)$row->site_id );
92 $site->setForward( (
bool)$row->site_forward );
93 $site->setGroup( $row->site_group );
94 $site->setLanguageCode( $row->site_language ===
''
98 $site->setSource( $row->site_source );
99 $site->setExtraData( unserialize( $row->site_data ) );
100 $site->setExtraConfig( unserialize( $row->site_config ) );
101 $this->sites[] = $site;
105 $ids = $dbr->newSelectQueryBuilder()
106 ->select( [
'si_site',
'si_type',
'si_key', ] )
107 ->from(
'site_identifiers' )
108 ->caller( __METHOD__ )->fetchResultSet();
110 foreach ( $ids as $id ) {
111 if ( $this->sites->hasInternalId( $id->si_site ) ) {
112 $site = $this->sites->getSiteByInternalId( $id->si_site );
113 $site->addLocalId( $id->si_type, $id->si_key );
114 $this->sites->setSite( $site );
157 $dbw = $this->dbProvider->getPrimaryDatabase();
159 $dbw->startAtomic( __METHOD__ );
164 foreach (
$sites as $site ) {
165 if ( $site->getInternalId() !==
null ) {
166 $internalIds[] = $site->getInternalId();
171 'site_global_key' => $site->getGlobalId(),
172 'site_type' => $site->getType(),
173 'site_group' => $site->getGroup(),
174 'site_source' => $site->getSource(),
175 'site_language' => $site->getLanguageCode() ??
'',
176 'site_protocol' => $site->getProtocol(),
177 'site_domain' => strrev( $site->getDomain() ??
'' ) .
'.',
178 'site_data' => serialize( $site->getExtraData() ),
181 'site_forward' => $site->shouldForward() ? 1 : 0,
182 'site_config' => serialize( $site->getExtraConfig() ),
185 $rowId = $site->getInternalId();
186 if ( $rowId !==
null ) {
187 $dbw->newUpdateQueryBuilder()
190 ->where( [
'site_id' => $rowId ] )
191 ->caller( __METHOD__ )->execute();
193 $dbw->newInsertQueryBuilder()
194 ->insertInto(
'sites' )
196 ->caller( __METHOD__ )->execute();
197 $rowId = $dbw->insertId();
200 foreach ( $site->getLocalIds() as $idType => $ids ) {
201 foreach ( $ids as $id ) {
202 $localIds[] = [ $rowId, $idType, $id ];
207 if ( $internalIds !== [] ) {
208 $dbw->newDeleteQueryBuilder()
209 ->deleteFrom(
'site_identifiers' )
210 ->where( [
'si_site' => $internalIds ] )
211 ->caller( __METHOD__ )->execute();
214 foreach ( $localIds as $localId ) {
215 $dbw->newInsertQueryBuilder()
216 ->insertInto(
'site_identifiers' )
217 ->row( [
'si_site' => $localId[0],
'si_type' => $localId[1],
'si_key' => $localId[2] ] )
218 ->caller( __METHOD__ )->execute();
221 $dbw->endAtomic( __METHOD__ );
243 $dbw = $this->dbProvider->getPrimaryDatabase();
245 $dbw->startAtomic( __METHOD__ );
246 $dbw->newDeleteQueryBuilder()
247 ->deleteFrom(
'sites' )
248 ->where( IDatabase::ALL_ROWS )
249 ->caller( __METHOD__ )->execute();
250 $dbw->newDeleteQueryBuilder()
251 ->deleteFrom(
'site_identifiers' )
252 ->where( IDatabase::ALL_ROWS )
253 ->caller( __METHOD__ )->execute();
254 $dbw->endAtomic( __METHOD__ );