Closes #713: add a parameter to run the site in a degraded mode
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 15 Sep 2007 13:53:59 +0000 (15:53 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 15 Sep 2007 13:53:59 +0000 (15:53 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
ChangeLog
classes/platal.php
classes/platalpage.php
classes/xdb.php
include/globals.inc.php.in

index 393725f..2540e3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ Bug/Wish:
 
     * Carnet:
         - #682: Can quick search in contact list                           -FRU
+        - #713: Can run the site in a degraded mode                        -FRU
 
     * Core:
         - #665: Fix text alignment                                         -FRU
index 24a0066..7524b21 100644 (file)
@@ -51,6 +51,11 @@ class Platal
             $this->__mods[$module] = $m = PLModule::factory($module);
             $this->__hooks += $m->handlers();
         }
+
+        global $globals;
+        if ($globals->mode == '') {
+            pl_redirect('index.html');
+        }
     }
 
     public function pl_self($n = null)
index 47e1da6..950f73e 100644 (file)
@@ -52,6 +52,10 @@ abstract class PlatalPage extends Smarty
         $this->_jsonVars  = array();
         $this->_failure   = false;
 
+        if ($globals->mode != 'rw') {
+            $this->_errors[] = "En raison d'une maintenance, une partie des fonctionnalités du site sont actuellement"
+                             . " désactivée, en particuliers aucune donnée ne sera sauvegardée";
+        }
         $this->register_prefilter('at_to_globals');
         $this->addJsLink('xorg.js');
     }
index a431882..91b0d19 100644 (file)
@@ -110,7 +110,12 @@ class XDB
 
     public static function execute()
     {
-        return XDB::_query(XDB::_prepare(func_get_args()));
+        global $globals;
+        $args = func_get_args();
+        if ($globals->mode != 'rw' && !strpos($args[0], 'logger')) {
+            return;
+        }
+        return XDB::_query(XDB::_prepare($args));
     }
 
     public static function iterator()
index 6ad5a3c..e7f9f55 100644 (file)
@@ -26,6 +26,9 @@ class PlatalGlobals
     /** The x.org version */
     public $version = '@VERSION@';
     public $debug   = 0;
+    public $mode    = 'rw';    // 'rw' => read/write,
+                               // 'r'  => read/only
+                               // ''   => site down
 
     /** db params */
     public $dbdb               = 'x4dat';