97 [
'ORDER BY' =>
'site_global_key' ]
100 foreach (
$res as $row ) {
102 $site->setGlobalId( $row->site_global_key );
103 $site->setInternalId( (
int)$row->site_id );
104 $site->setForward( (
bool)$row->site_forward );
105 $site->setGroup( $row->site_group );
106 $site->setLanguageCode( $row->site_language ===
''
108 : $row->site_language
110 $site->setSource( $row->site_source );
111 $site->setExtraData(
unserialize( $row->site_data ) );
112 $site->setExtraConfig(
unserialize( $row->site_config ) );
113 $this->sites[] = $site;
128 foreach ( $ids as $id ) {
129 if ( $this->sites->hasInternalId( $id->si_site ) ) {
130 $site = $this->sites->getSiteByInternalId( $id->si_site );
131 $site->addLocalId( $id->si_type, $id->si_key );
132 $this->sites->setSite( $site );
147 if ( $this->sites ===
null ) {
151 return $this->sites->hasSite( $globalId ) ? $this->sites->getSite( $globalId ) :
null;
181 $dbw = $this->dbLoadBalancer->getConnectionRef(
DB_MASTER );
183 $dbw->startAtomic( __METHOD__ );
190 foreach (
$sites as $site ) {
191 if ( $site->getInternalId() !== null ) {
192 $internalIds[] = $site->getInternalId();
197 'site_global_key' => $site->getGlobalId(),
198 'site_type' => $site->getType(),
199 'site_group' => $site->getGroup(),
200 'site_source' => $site->getSource(),
201 'site_language' => $site->getLanguageCode() ??
'',
202 'site_protocol' => $site->getProtocol(),
203 'site_domain' => strrev( $site->getDomain() ) .
'.',
204 'site_data' =>
serialize( $site->getExtraData() ),
207 'site_forward' => $site->shouldForward() ? 1 : 0,
208 'site_config' =>
serialize( $site->getExtraConfig() ),
211 $rowId = $site->getInternalId();
212 if ( $rowId !==
null ) {
214 'sites', $fields, [
'site_id' => $rowId ], __METHOD__
218 $rowId = $dbw->insertId();
221 foreach ( $site->getLocalIds() as $idType => $ids ) {
222 foreach ( $ids as $id ) {
223 $localIds[] = [ $rowId, $idType, $id ];
228 if ( $internalIds !== [] ) {
231 [
'si_site' => $internalIds ],
236 foreach ( $localIds as $localId ) {
240 'si_site' => $localId[0],
241 'si_type' => $localId[1],
242 'si_key' => $localId[2],
248 $dbw->endAtomic( __METHOD__ );
272 $dbw = $this->dbLoadBalancer->getConnectionRef(
DB_MASTER );
274 $dbw->startAtomic( __METHOD__ );
275 $ok = $dbw->delete(
'sites',
'*', __METHOD__ );
276 $ok = $dbw->delete(
'site_identifiers',
'*', __METHOD__ ) && $ok;
277 $dbw->endAtomic( __METHOD__ );