Switches to 'opt-out' mode for IMAP backend storage.
authorVincent Zanotti <vincent.zanotti@polytechnique.org>
Fri, 22 Feb 2008 10:04:11 +0000 (11:04 +0100)
committerVincent Zanotti <vincent.zanotti@polytechnique.org>
Fri, 22 Feb 2008 10:04:11 +0000 (11:04 +0100)
Fixes code consistency mistakes in last commit.

Signed-off-by: Vincent Zanotti <vincent.zanotti@polytechnique.org>
include/emails.inc.php
templates/emails/index.tpl
upgrade/0.9.16/03_mail_storage.sql

index 35b76d3..bf1ba1a 100644 (file)
@@ -413,34 +413,33 @@ class Redirect
 class MailStorage {
     protected $uid;
     protected $name;
+    protected $storage;
 
     public function __construct($_uid, $_name)
     {
         $this->uid = $_uid;
         $this->name = $_name;
-    }
 
-    public function disable()
-    {
         $res = XDB::query("SELECT  mail_storage
                              FROM  auth_user_md5
                             WHERE  user_id = {?}", $this->uid);
-        $storages = explode(',', $res->fetchOneCell());
+        $this->storages = new FlagSet($res->fetchOneCell());
+    }
 
-        if (in_array($this->name, $storages)) {
-            array_splice($storages, array_search($this->name, $storages), 1);
-            XDB::execute("UPDATE  auth_user_md5
-                             SET  mail_storage = {?}
-                           WHERE  user_id = {?}", implode(',', $storages), $this->uid);
-        }
+    public function disable()
+    {
+        $this->storages->rmFlag($this->name);
+        XDB::execute("UPDATE  auth_user_md5
+                         SET  mail_storage = {?}
+                       WHERE  user_id = {?}", $this->storages->flags(), $this->uid);
     }
 
     public function enable()
     {
+        $this->storages->addFlag($this->name);
         XDB::execute("UPDATE  auth_user_md5
-                         SET  mail_storage = CONCAT_WS(',', IF(mail_storage = '', NULL, mail_storage), {?})
-                       WHERE  user_id = {?} AND
-                              FIND_IN_SET({?}, mail_storage) = 0", $this->name, $this->uid, $this->name);
+                         SET  mail_storage = {?}
+                       WHERE  user_id = {?}", $this->storages->flags(), $this->uid);
     }
 }
 
index a5312c8..4d7c07c 100644 (file)
@@ -102,17 +102,16 @@ ton homonyme et toi-même ne disposeraient plus que des adresses de la forme pre
       {if count($storage) neq 0}
       Ton courrier est également stocké sur {if count($storage) eq 1}le compte suivant{else} les comptes suivants{/if}&nbsp;:
       <ul>
-        {foreach from=$storage item=s}
         {if in_array('googleapps', $storage)}
         <li><a href="https://www.polytechnique.org/Xorg/GoogleApps">
           <strong>Compte Google Apps / GMail de Polytechnique.org</strong>
         </a></li>
-        {elseif in_array('imap', $storage)}
+        {/if}
+        {if in_array('imap', $storage)}
         <li><a href="https://www.polytechnique.org/Xorg/IMAP">
           <strong>Accès de secours aux emails (IMAP)</strong>
         </a></li>
         {/if}
-        {/foreach}
       </ul>
       {/if}
       {test_email}
index 7739c95..4774a53 100644 (file)
@@ -1,4 +1,3 @@
-ALTER TABLE auth_user_md5 ADD COLUMN mail_storage SET('imap', 'googleapps') DEFAULT '' NOT NULL AFTER smtppass;
-UPDATE auth_user_md5 SET mail_storage = 'imap' WHERE mail_storage = '';
+ALTER TABLE auth_user_md5 ADD COLUMN mail_storage SET('imap', 'googleapps') DEFAULT 'imap' NOT NULL AFTER smtppass;
 
 # vim:set syntax=mysql: