*/
private $cacheTimeout = 3600;
+ /**
+ * @var BagOStuff
+ */
+ private $cache;
+
/**
* @since 1.21
*
* @param ORMTable|null $sitesTable
+ * @param BagOStuff|null $cache
*
* @return SiteStore
*/
- public static function newInstance( ORMTable $sitesTable = null ) {
- return new static( $sitesTable );
+ public static function newInstance( ORMTable $sitesTable = null, BagOStuff $cache = null ) {
+ if ( $cache === null ) {
+ $cache = wfGetMainCache();
+ }
+
+ return new static( $cache, $sitesTable );
}
/**
*
* @since 1.21
*
+ * @param BagOStuff $cache
* @param ORMTable|null $sitesTable
*/
- protected function __construct( ORMTable $sitesTable = null ) {
+ protected function __construct( BagOStuff $cache, ORMTable $sitesTable = null ) {
if ( $sitesTable === null ) {
$sitesTable = $this->newSitesTable();
}
+ $this->cache = $cache;
$this->sitesTable = $sitesTable;
}
* @return string The cache key.
*/
protected function getCacheKey() {
- wfProfileIn( __METHOD__ );
if ( $this->cacheKey === null ) {
$type = 'SiteList#' . SiteList::getSerialVersionId();
$this->cacheKey = wfMemcKey( "$source/$type" );
}
- wfProfileOut( __METHOD__ );
return $this->cacheKey;
}
* @return SiteList
*/
public function getSites( $source = 'cache' ) {
- wfProfileIn( __METHOD__ );
if ( $source === 'cache' ) {
if ( $this->sites === null ) {
- $cache = wfGetMainCache();
- $sites = $cache->get( $this->getCacheKey() );
+ $sites = $this->cache->get( $this->getCacheKey() );
if ( is_object( $sites ) ) {
$this->sites = $sites;
$this->loadSites();
}
- wfProfileOut( __METHOD__ );
return $this->sites;
}
* @return Site
*/
protected function siteFromRow( ORMRow $siteRow ) {
- wfProfileIn( __METHOD__ );
$site = Site::newForType( $siteRow->getField( 'type', Site::TYPE_UNKNOWN ) );
$site->setExtraConfig( $siteRow->getField( 'config' ) );
}
- wfProfileOut( __METHOD__ );
return $site;
}
* @since 1.21
*/
protected function loadSites() {
- wfProfileIn( __METHOD__ );
$this->sites = new SiteList();
}
}
- $cache = wfGetMainCache();
- $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
+ $this->cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
- wfProfileOut( __METHOD__ );
}
/**
* @return Site|null
*/
public function getSite( $globalId, $source = 'cache' ) {
- wfProfileIn( __METHOD__ );
$sites = $this->getSites( $source );
- wfProfileOut( __METHOD__ );
return $sites->hasSite( $globalId ) ? $sites->getSite( $globalId ) : null;
}
* @return bool Success indicator
*/
public function saveSites( array $sites ) {
- wfProfileIn( __METHOD__ );
if ( empty( $sites ) ) {
- wfProfileOut( __METHOD__ );
return true;
}
// purge cache
$this->reset();
- wfProfileOut( __METHOD__ );
return $success;
}
* @since 1.21
*/
public function reset() {
- wfProfileIn( __METHOD__ );
// purge cache
- $cache = wfGetMainCache();
- $cache->delete( $this->getCacheKey() );
+ $this->cache->delete( $this->getCacheKey() );
$this->sites = null;
- wfProfileOut( __METHOD__ );
}
/**
* @return bool Success
*/
public function clear() {
- wfProfileIn( __METHOD__ );
$dbw = $this->sitesTable->getWriteDbConnection();
$dbw->startAtomic( __METHOD__ );
$this->reset();
- wfProfileOut( __METHOD__ );
return $ok;
}
}
}
-
-/**
- * @deprecated since 1.21
- */
-class Sites extends SiteSQLStore {
-
- /**
- * Factory for creating new site objects.
- *
- * @since 1.21
- * @deprecated since 1.21
- *
- * @param string|bool $globalId
- *
- * @return Site
- */
- public static function newSite( $globalId = false ) {
- $site = new Site();
-
- if ( $globalId !== false ) {
- $site->setGlobalId( $globalId );
- }
-
- return $site;
- }
-
- /**
- * @deprecated since 1.21
- * @return SiteStore
- */
- public static function singleton() {
- static $singleton;
-
- if ( $singleton === null ) {
- $singleton = new static();
- }
-
- return $singleton;
- }
-
- /**
- * @deprecated since 1.21
- * @param string $group
- * @return SiteList
- */
- public function getSiteGroup( $group ) {
- return $this->getSites()->getGroup( $group );
- }
-}