* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class SiteSQLStore implements SiteStore {
-
/**
* @since 1.21
*
*/
private $cacheKey = null;
+ /**
+ * @var int
+ */
+ private $cacheTimeout = 3600;
+
/**
* @since 1.21
*
*
* @see SiteList::getSerialVersionId
*
- * @return String The cache key.
+ * @return string The cache key.
*/
protected function getCacheKey() {
wfProfileIn( __METHOD__ );
*
* @since 1.21
*
- * @param string $source either 'cache' or 'recache'
+ * @param string $source Either 'cache' or 'recache'
*
* @return SiteList
*/
}
if ( $siteRow->hasField( 'language' ) ) {
- $site->setLanguageCode( $siteRow->getField( 'language' ) === '' ? null : $siteRow->getField( 'language' ) );
+ $site->setLanguageCode( $siteRow->getField( 'language' ) === ''
+ ? null
+ : $siteRow->getField( 'language' )
+ );
}
if ( $siteRow->hasField( 'source' ) ) {
return $site;
}
+ /**
+ * Get a new ORMRow from a Site object
+ *
+ * @since 1.22
+ *
+ * @param Site $site
+ *
+ * @return ORMRow
+ */
+ protected function getRowFromSite( Site $site ) {
+ $fields = array(
+ // Site data
+ 'global_key' => $site->getGlobalId(), // TODO: check not null
+ 'type' => $site->getType(),
+ 'group' => $site->getGroup(),
+ 'source' => $site->getSource(),
+ 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(),
+ 'protocol' => $site->getProtocol(),
+ 'domain' => strrev( $site->getDomain() ) . '.',
+ 'data' => $site->getExtraData(),
+
+ // Site config
+ 'forward' => $site->shouldForward(),
+ 'config' => $site->getExtraConfig(),
+ );
+
+ if ( $site->getInternalId() !== null ) {
+ $fields['id'] = $site->getInternalId();
+ }
+
+ return new ORMRow( $this->sitesTable, $fields );
+ }
+
/**
* Fetches the site from the database and loads them into the sites field.
*
}
$cache = wfGetMainCache();
- $cache->set( $this->getCacheKey(), $this->sites );
+ $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
wfProfileOut( __METHOD__ );
}
*
* @param Site $site
*
- * @return boolean Success indicator
+ * @return bool Success indicator
*/
public function saveSite( Site $site ) {
return $this->saveSites( array( $site ) );
*
* @param Site[] $sites
*
- * @return boolean Success indicator
+ * @return bool Success indicator
*/
public function saveSites( array $sites ) {
wfProfileIn( __METHOD__ );
$localIds = array();
foreach ( $sites as $site ) {
- $fields = array(
- // Site data
- 'global_key' => $site->getGlobalId(), // TODO: check not null
- 'type' => $site->getType(),
- 'group' => $site->getGroup(),
- 'source' => $site->getSource(),
- 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(),
- 'protocol' => $site->getProtocol(),
- 'domain' => strrev( $site->getDomain() ) . '.',
- 'data' => $site->getExtraData(),
-
- // Site config
- 'forward' => $site->shouldForward(),
- 'config' => $site->getExtraConfig(),
- );
-
if ( $site->getInternalId() !== null ) {
- $fields['id'] = $site->getInternalId();
$internalIds[] = $site->getInternalId();
}
- $siteRow = new ORMRow( $this->sitesTable, $fields );
+ $siteRow = $this->getRowFromSite( $site );
$success = $siteRow->save( __METHOD__ ) && $success;
foreach ( $site->getLocalIds() as $idType => $ids ) {
*
* @see SiteStore::clear()
*
- * @return bool success
+ * @return bool Success
*/
public function clear() {
wfProfileIn( __METHOD__ );
* @since 1.21
* @deprecated
*
- * @param string|boolean false $globalId
+ * @param string|bool $globalId
*
* @return Site
*/
/**
* @deprecated
+ * @param string $group
* @return SiteList
*/
public function getSiteGroup( $group ) {
return $this->getSites()->getGroup( $group );
}
-
}