Пример #1
0
 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;
 }
Пример #2
0
 /**
  * @see SiteStore::getSite
  *
  * @since 1.25
  *
  * @param string $globalId
  *
  * @return Site|null
  */
 public function getSite($globalId)
 {
     if ($this->sites === null) {
         $this->sites = $this->getSites();
     }
     return $this->sites->hasSite($globalId) ? $this->sites->getSite($globalId) : null;
 }
Пример #3
0
 /**
  * Returns the site with provided global id, or false if there is no such site.
  *
  * @since 1.21
  *
  * @param string $globalId
  * @param string $source
  *
  * @return Site|false
  */
 public function getSite($globalId, $source = 'cache')
 {
     if ($source === 'cache' && $this->sites !== false) {
         return $this->sites->hasSite($globalId) ? $this->sites->getSite($globalId) : false;
     }
     return SitesTable::singleton()->selectRow(null, array('global_key' => $globalId));
 }
 /**
  * Constructs a cache key to use for caching the list of sites.
  *
  * This includes the concrete class name of the site list as well as a version identifier
  * for the list's serialization, to avoid problems when unserializing site lists serialized
  * by an older version, e.g. when reading from a cache.
  *
  * The cache key also includes information about where the sites were loaded from, e.g.
  * the name of a database table.
  *
  * @see SiteList::getSerialVersionId
  *
  * @return string The cache key.
  */
 private function getCacheKey()
 {
     if ($this->cacheKey === null) {
         $type = 'SiteList#' . SiteList::getSerialVersionId();
         $this->cacheKey = wfMemcKey("sites/{$type}");
     }
     return $this->cacheKey;
 }
Пример #5
0
 /**
  * @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');
 }
Пример #6
0
 /**
  * Fetches the site from the database and loads them into the sites field.
  *
  * @since 1.21
  */
 protected function loadSites()
 {
     wfProfileIn(__METHOD__);
     $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);
         }
     }
     $cache = wfGetMainCache();
     $cache->set($this->getCacheKey(), $this->sites, $this->cacheTimeout);
     wfProfileOut(__METHOD__);
 }
Пример #7
0
 /**
  * @dataProvider siteListProvider
  * @param SiteList $sites
  * @covers SiteList::getGlobalIdentifiers
  */
 public function testGetGlobalIdentifiers(SiteList $sites)
 {
     $identifiers = $sites->getGlobalIdentifiers();
     $this->assertTrue(is_array($identifiers));
     $expected = array();
     /**
      * @var Site $site
      */
     foreach ($sites as $site) {
         $expected[] = $site->getGlobalId();
     }
     $this->assertArrayEquals($expected, $identifiers);
 }