]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '2141' into 0.9.x
authorBrion Vibber <brion@status.net>
Mon, 4 Jan 2010 20:02:45 +0000 (12:02 -0800)
committerBrion Vibber <brion@status.net>
Mon, 4 Jan 2010 20:02:45 +0000 (12:02 -0800)
classes/Memcached_DataObject.php
classes/statusnet.ini
plugins/CasAuthentication/CasAuthenticationPlugin.php
plugins/CasAuthentication/README
plugins/MemcachePlugin.php

index 1608720d14072980187db8ba0cfb682a9d2d0334..020d813b2c4787b8a2e6439decd806e8023f9987 100644 (file)
@@ -152,52 +152,69 @@ class Memcached_DataObject extends DB_DataObject
     function encache()
     {
         $c = $this->memcache();
+
         if (!$c) {
             return false;
-        } else {
-            $pkey = array();
-            $pval = array();
-            $types = $this->keyTypes();
-            ksort($types);
-            foreach ($types as $key => $type) {
-                if ($type == 'K') {
-                    $pkey[] = $key;
-                    $pval[] = $this->$key;
-                } else {
-                    $c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
-                }
-            }
-            # XXX: should work for both compound and scalar pkeys
-            $pvals = implode(',', $pval);
-            $pkeys = implode(',', $pkey);
-            $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
+        }
+
+        $keys = $this->_allCacheKeys();
+
+        foreach ($keys as $key) {
+            $c->set($key, $this);
         }
     }
 
     function decache()
     {
         $c = $this->memcache();
+
         if (!$c) {
             return false;
-        } else {
-            $pkey = array();
-            $pval = array();
-            $types = $this->keyTypes();
-            ksort($types);
-            foreach ($types as $key => $type) {
-                if ($type == 'K') {
-                    $pkey[] = $key;
-                    $pval[] = $this->$key;
-                } else {
-                    $c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
+        }
+
+        $keys = $this->_allCacheKeys();
+
+        foreach ($keys as $key) {
+            $c->delete($key, $this);
+        }
+    }
+
+    function _allCacheKeys()
+    {
+        $ckeys = array();
+
+        $types = $this->keyTypes();
+        ksort($types);
+
+        $pkey = array();
+        $pval = array();
+
+        foreach ($types as $key => $type) {
+
+            assert(!empty($key));
+
+            if ($type == 'U') {
+                if (empty($this->$key)) {
+                    continue;
                 }
+                $ckeys[] = $this->cacheKey($this->tableName(), $key, $this->$key);
+            } else if ($type == 'K' || $type == 'N') {
+                $pkey[] = $key;
+                $pval[] = $this->$key;
+            } else {
+                throw new Exception("Unknown key type $key => $type for " . $this->tableName());
             }
-            # should work for both compound and scalar pkeys
-            # XXX: comma works for now but may not be safe separator for future keys
-            $pvals = implode(',', $pval);
-            $pkeys = implode(',', $pkey);
-            $c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
         }
+
+        assert(count($pkey) > 0);
+
+        // XXX: should work for both compound and scalar pkeys
+        $pvals = implode(',', $pval);
+        $pkeys = implode(',', $pkey);
+
+        $ckeys[] = $this->cacheKey($this->tableName(), $pkeys, $pvals);
+
+        return $ckeys;
     }
 
     function multicache($cls, $kv)
index 4077746c47035bcf1c58ca17ef76f193e660f654..ac31148daa723a93b10cf49196bf56c4d4645841 100644 (file)
@@ -572,5 +572,5 @@ created = 142
 modified = 384
 
 [user_location_prefs__keys]
-user_id = U
+user_id = K
 
index 8b6ef54621f28e51430d0299ff0eae5f88125544..8f29c7d2adaf29e17d7de9952faed24b2a83a906 100644 (file)
@@ -40,6 +40,7 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
     public $server;
     public $port = 443;
     public $path = '';
+    public $takeOverLogin = false;
 
     function checkPassword($username, $password)
     {
@@ -62,6 +63,14 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
         }
     }
 
+    function onArgsInitialize(&$args)
+    {
+        if($this->takeOverLogin && $args['action'] == 'login')
+        {
+            $args['action'] = 'caslogin';
+        }
+    }
+
     function onStartInitializeRouter($m)
     {
         $m->connect('main/cas', array('action' => 'caslogin'));
index 2ee54dc057150b631a963b342f5c2d8699709faa..c17a28e54a4097a1488e14ba06f181172988b8ab 100644 (file)
@@ -21,6 +21,9 @@ password_changeable*: must be set to false. This plugin does not support changin
 server*: CAS server to authentication against
 port (443): Port the CAS server listens on. Almost always 443
 path (): Path on the server to CAS. Usually blank.
+takeOverLogin (false): Take over the main login action. If takeOverLogin is
+    set, anytime the standard username/password login form would be shown,
+    a CAS login will be done instead.
 
 * required
 default values are in (parenthesis)
@@ -33,6 +36,7 @@ addPlugin('casAuthentication', array(
     'autoregistration'=>true,
     'server'=>'sso-cas.univ-rennes1.fr',
     'port'=>443,
-    'path'=>''
+    'path'=>'',
+    'takeOverLogin'=>true
 ));
 
index 78e2b24067931e487c373e97aba3f20b7b5693a6..998766313f78dba150b86fb2ac3d6494b01547c8 100644 (file)
@@ -54,6 +54,9 @@ class MemcachePlugin extends Plugin
     private $_conn  = null;
     public $servers = array('127.0.0.1;11211');
 
+    public $compressThreshold = 20480;
+    public $compressMinSaving = 0.2;
+
     /**
      * Initialize the plugin
      *
@@ -156,11 +159,16 @@ class MemcachePlugin extends Plugin
                 }
                 $this->_conn->addServer($host, $port);
             }
-            //Compress items stored in the cache if they're over 2k in size
-            //and the compression would save more than 20%.
-            //Allows the cache to store objects larger than 1MB (if they
-            //compress to less than 1MB), and improves cache memory efficiency.
-            $this->_conn->setCompressThreshold(20000, 0.2);
+
+            // Compress items stored in the cache if they're over threshold in size
+            // (default 2KiB) and the compression would save more than min savings
+            // ratio (default 0.2).
+
+            // Allows the cache to store objects larger than 1MB (if they
+            // compress to less than 1MB), and improves cache memory efficiency.
+
+            $this->_conn->setCompressThreshold($this->compressThreshold,
+                                               $this->compressMinSaving);
         }
     }
 }