Allow to disable specific groups in $wgDebugLogGroups
[lhc/web/wiklou.git] / includes / site / SiteSQLStore.php
index a79c8c5..11141e0 100644 (file)
@@ -47,6 +47,11 @@ class SiteSQLStore implements SiteStore {
         */
        private $cacheKey = null;
 
+       /**
+        * @var int
+        */
+       private $cacheTimeout = 3600;
+
        /**
         * @since 1.21
         *
@@ -183,6 +188,39 @@ class SiteSQLStore implements SiteStore {
                return $site;
        }
 
+       /**
+        * Get a new ORMRow from a Site object
+        *
+        * @since 1.22
+        *
+        * @param 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.
         *
@@ -218,7 +256,7 @@ class SiteSQLStore implements SiteStore {
                }
 
                $cache = wfGetMainCache();
-               $cache->set( $this->getCacheKey(), $this->sites );
+               $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
 
                wfProfileOut( __METHOD__ );
        }
@@ -286,28 +324,11 @@ class SiteSQLStore implements SiteStore {
                $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 ) {
@@ -466,7 +487,13 @@ class Sites extends SiteSQLStore {
         * @return SiteStore
         */
        public static function singleton() {
-               return new static();
+               static $singleton;
+
+               if ( $singleton === null ) {
+                       $singleton = new static();
+               }
+
+               return $singleton;
        }
 
        /**