/** * Fetches the site from the database and loads them into the sites field. * * @since 1.25 */ protected function loadSites() { $this->sites = new SiteList(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('sites', array('site_id', 'site_global_key', 'site_type', 'site_group', 'site_source', 'site_language', 'site_protocol', 'site_domain', 'site_data', 'site_forward', 'site_config'), '', __METHOD__, array('ORDER BY' => 'site_global_key')); foreach ($res as $row) { $site = Site::newForType($row->site_type); $site->setGlobalId($row->site_global_key); $site->setInternalId((int) $row->site_id); $site->setForward((bool) $row->site_forward); $site->setGroup($row->site_group); $site->setLanguageCode($row->site_language === '' ? null : $row->site_language); $site->setSource($row->site_source); $site->setExtraData(unserialize($row->site_data)); $site->setExtraConfig(unserialize($row->site_config)); $this->sites[] = $site; } // Batch load the local site identifiers. $ids = $dbr->select('site_identifiers', array('si_site', 'si_type', 'si_key'), array(), __METHOD__); foreach ($ids as $id) { if ($this->sites->hasInternalId($id->si_site)) { $site = $this->sites->getSiteByInternalId($id->si_site); $site->addLocalId($id->si_type, $id->si_key); $this->sites->setSite($site); } } }
/** * Fetches the site from the database and loads them into the sites field. * * @since 1.25 */ protected function loadSites() { $this->sites = new SiteList(); foreach ($this->sitesTable->select() as $siteRow) { $this->sites[] = $this->siteFromRow($siteRow); } // Batch load the local site identifiers. $ids = wfGetDB($this->sitesTable->getReadDb())->select('site_identifiers', array('si_site', 'si_type', 'si_key'), array(), __METHOD__); foreach ($ids as $id) { if ($this->sites->hasInternalId($id->si_site)) { $site = $this->sites->getSiteByInternalId($id->si_site); $site->addLocalId($id->si_type, $id->si_key); $this->sites->setSite($site); } } }
/** * Fetches the site from the database and loads them into the sites field. * * @since 1.21 */ protected function loadSites() { $this->sites = new SiteArray(SitesTable::singleton()->select()); // Batch load the local site identifiers. $dbr = wfGetDB(SitesTable::singleton()->getReadDb()); $ids = $dbr->select('site_identifiers', array('si_site', 'si_type', 'si_key'), array(), __METHOD__); foreach ($ids as $id) { if ($this->sites->hasInternalId($id->si_site)) { $site = $this->sites->getSiteByInternalId($id->si_site); $site->addLocalId($id->si_type, $id->si_key); $this->sites->setSite($site); } } $cache = wfGetMainCache(); $cache->set('sites-cache', $this->sites); }
/** * @dataProvider siteListProvider * @param SiteList $sites * @covers SiteList::hasInternalId */ public function testHasInternallId($sites) { /** * @var Site $site */ foreach ($sites as $site) { if (is_integer($site->getInternalId())) { $this->assertTrue($site, $sites->hasInternalId($site->getInternalId())); } } $this->assertFalse($sites->hasInternalId(-1)); }