35 private $dbLoadBalancer;
42 $this->dbLoadBalancer = $dbLoadBalancer;
84 [
'ORDER BY' =>
'site_global_key' ]
87 foreach (
$res as $row ) {
89 $site->setGlobalId( $row->site_global_key );
90 $site->setInternalId( (
int)$row->site_id );
91 $site->setForward( (
bool)$row->site_forward );
92 $site->setGroup( $row->site_group );
93 $site->setLanguageCode( $row->site_language ===
''
97 $site->setSource( $row->site_source );
98 $site->setExtraData( unserialize( $row->site_data ) );
99 $site->setExtraConfig( unserialize( $row->site_config ) );
100 $this->sites[] = $site;
115 foreach ( $ids as $id ) {
116 if ( $this->sites->hasInternalId( $id->si_site ) ) {
117 $site = $this->sites->getSiteByInternalId( $id->si_site );
118 $site->addLocalId( $id->si_type, $id->si_key );
119 $this->sites->setSite( $site );
132 if ( $this->sites ===
null ) {
136 return $this->sites->hasSite( $globalId ) ? $this->sites->getSite( $globalId ) :
null;
162 $dbw = $this->dbLoadBalancer->getConnectionRef(
DB_PRIMARY );
164 $dbw->startAtomic( __METHOD__ );
171 foreach (
$sites as $site ) {
172 if ( $site->getInternalId() !==
null ) {
173 $internalIds[] = $site->getInternalId();
178 'site_global_key' => $site->getGlobalId(),
179 'site_type' => $site->getType(),
180 'site_group' => $site->getGroup(),
181 'site_source' => $site->getSource(),
182 'site_language' => $site->getLanguageCode() ??
'',
183 'site_protocol' => $site->getProtocol(),
184 'site_domain' => strrev( $site->getDomain() ??
'' ) .
'.',
185 'site_data' => serialize( $site->getExtraData() ),
188 'site_forward' => $site->shouldForward() ? 1 : 0,
189 'site_config' => serialize( $site->getExtraConfig() ),
192 $rowId = $site->getInternalId();
193 if ( $rowId !==
null ) {
195 'sites', $fields, [
'site_id' => $rowId ], __METHOD__
199 $rowId = $dbw->insertId();
202 foreach ( $site->getLocalIds() as $idType => $ids ) {
203 foreach ( $ids as $id ) {
204 $localIds[] = [ $rowId, $idType, $id ];
209 if ( $internalIds !== [] ) {
212 [
'si_site' => $internalIds ],
217 foreach ( $localIds as $localId ) {
221 'si_site' => $localId[0],
222 'si_type' => $localId[1],
223 'si_key' => $localId[2],
229 $dbw->endAtomic( __METHOD__ );
253 $dbw = $this->dbLoadBalancer->getConnectionRef(
DB_PRIMARY );
255 $dbw->startAtomic( __METHOD__ );
256 $ok = $dbw->delete(
'sites',
'*', __METHOD__ );
257 $ok = $dbw->delete(
'site_identifiers',
'*', __METHOD__ ) && $ok;
258 $dbw->endAtomic( __METHOD__ );
Holds a list of sites stored in the database.
__construct(ILoadBalancer $dbLoadBalancer)
reset()
Resets the SiteList.
loadSites()
Fetches the site from the database and loads them into the sites field.
clear()
Clears the list of sites stored in the database.
Collection of Site objects.
Represents a single site.
static newForType( $siteType)
Interface for storing and retreiving Site objects.