/** * 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); } } }
private function newSiteStore(SiteList $sites) { $store = $this->getMock('SiteStore'); $store->expects($this->once())->method('saveSites')->will($this->returnCallback(function ($moreSites) use($sites) { foreach ($moreSites as $site) { $sites->setSite($site); } })); $store->expects($this->any())->method('getSites')->will($this->returnValue(new SiteList())); return $store; }
/** * 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); }
/** * @covers CachingSiteStore::reset */ public function testReset() { $dbSiteStore = $this->getMockBuilder('SiteStore')->disableOriginalConstructor()->getMock(); $dbSiteStore->expects($this->any())->method('getSite')->will($this->returnValue($this->getTestSite())); $dbSiteStore->expects($this->any())->method('getSites')->will($this->returnCallback(function () { $siteList = new SiteList(); $siteList->setSite($this->getTestSite()); return $siteList; })); $store = new CachingSiteStore($dbSiteStore, wfGetMainCache()); // initialize internal cache $this->assertGreaterThan(0, $store->getSites()->count(), 'count sites'); $store->getSite('enwiki')->setLanguageCode('en-ca'); // sanity check: $store should have the new language code for 'enwiki' $this->assertEquals('en-ca', $store->getSite('enwiki')->getLanguageCode(), 'sanity check'); // purge cache $store->reset(); // the internal cache of $store should be updated, and now pulling // the site from the 'fallback' DBSiteStore with the original language code. $this->assertEquals('en', $store->getSite('enwiki')->getLanguageCode(), 'reset'); }