Port a small part of include/notifs.inc.php
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 29 Dec 2008 21:35:17 +0000 (22:35 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 29 Dec 2008 21:35:17 +0000 (22:35 +0100)
This code have to be rewritten from scratch.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
core
include/notifs.inc.php
upgrade/account/01_profiles.sql
upgrade/account/99_insertion.sql

diff --git a/core b/core
index 80d0423..697c955 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 80d0423e13a1fbf932fa8b27f323af0d504a7873
+Subproject commit 697c955db0a0cb1c68826e033966dcb13fea4977
index 26eea44..5c2349b 100644 (file)
@@ -28,7 +28,9 @@ define('WATCH_BIRTH', 4);
 
 function inscription_notifs_base($uid)
 {
-    XDB::execute('REPLACE INTO  watch_sub (uid,cid) SELECT {?},id FROM watch_cat', $uid);
+    XDB::execute('REPLACE INTO  watch_sub (uid, cid)
+                        SELECT  {?}, id
+                          FROM  watch_cat', $uid);
 }
 
 // }}}
@@ -36,23 +38,29 @@ function inscription_notifs_base($uid)
 
 function register_watch_op($uid, $cid, $date='', $info='')
 {
+    // XXX
+    // TODO: Find out whether uid is a user or a profile!!!
+    // XXX
     if (empty($date)) {
         $date = date('Y-m-d');
-    };
-    XDB::execute('REPLACE INTO  watch_ops (uid,cid,known,date,info)
+    }
+    XDB::execute('REPLACE INTO  watch_ops (uid, cid, known, date, info)
                         VALUES  ({?}, {?}, NOW(), {?}, {?})',
                  $uid, $cid, $date, $info);
     if($cid == WATCH_FICHE) {
         if ($info) {
             register_profile_update($uid, $info);
         }
-        XDB::execute('UPDATE auth_user_md5 SET DATE=NOW() WHERE user_id={?}', $uid);
+        XDB::execute('UPDATE  profiles
+                         SET  last_change = NOW()
+                       WHERE  pid = {?}', $uid);
     } elseif($cid == WATCH_INSCR) {
         XDB::execute('REPLACE INTO  contacts (uid,contact)
-                            SELECT  uid,ni_id
+                            SELECT  uid, ni_id
                               FROM  watch_nonins
-                             WHERE  ni_id={?}', $uid);
-        XDB::execute('DELETE FROM watch_nonins WHERE ni_id={?}', $uid);
+                             WHERE  ni_id = {?}', $uid);
+        XDB::execute('DELETE FROM watch_nonins
+                            WHERE ni_id = {?}', $uid);
     }
     Platal::session()->updateNbNotifs();
 }
@@ -244,7 +252,9 @@ class Notifs
         }
 
         if($up) {
-            XDB::execute('UPDATE auth_user_quick SET watch_last=NOW() WHERE user_id={?}', $uid);
+            XDB::execute('UPDATE  watch
+                             SET  last = NOW()
+                           WHERE  uid = {?}', $uid);
         }
     }
 }
@@ -268,26 +278,24 @@ class Watch
         $this->_promos = new PromoNotifs($uid);
         $this->_nonins = new NoninsNotifs($uid);
         $this->_subs = new WatchSub($uid);
-        $res = XDB::query("SELECT  FIND_IN_SET('contacts',watch_flags),FIND_IN_SET('mail',watch_flags)
-                             FROM  auth_user_quick
-                            WHERE  user_id={?}", $uid);
-        list($this->watch_contacts,$this->watch_mail) = $res->fetchOneRow();
+        $res = XDB::query('SELECT  FIND_IN_SET(\'contacts\', flags),
+                                   FIND_IN_SET(\'mail\', flags)
+                             FROM  watch
+                            WHERE  uid = {?}', $uid);
+        list($this->watch_contacts, $this->watch_mail) = $res->fetchOneRow();
 
-        $res = XDB::iterator("SELECT * FROM watch_cat");
-        while($tmp = $res->next()) {
-            $this->_cats[$tmp['id']] = $tmp;
-        }
+        $this->_cats = XDB::fetchAllAssoc('id', 'SELECT * FROM watch_cat');
     }
 
     public function saveFlags()
     {
-        $flags = "";
-        if ($this->watch_contacts)
-            $flags = "contacts";
-        if ($this->watch_mail)
-            $flags .= ($flags ? ',' : '')."mail";
-        XDB::execute('UPDATE auth_user_quick SET watch_flags={?} WHERE user_id={?}',
-            $flags, $this->_uid);
+        $flags = new PlFlagSet();
+        $flags->addFlag('contacts', $this->watch_contacts);
+        $flags->addFlag('mail',     $this->watch_mail);
+        XDB::execute('UPDATE  watch
+                         SET  flags = {?}
+                       WHERE  uid = {?}',
+                     $flags, $this->_uid);
     }
 
     public function cats()
@@ -449,7 +457,7 @@ class NoninsNotifs
     public function add($p)
     {
         XDB::execute('INSERT INTO  watch_nonins (uid,ni_id) VALUES({?},{?})', $this->_uid, $p);
-        $res = XDB::query('SELECT  prenom,IF(nom_usage="",nom,nom_usage) AS nom,promo,user_id
+        $res = XDB::query('SELECT  prenom, IF(nom_usage="",nom,nom_usage) AS nom,promo,user_id
                              FROM  auth_user_md5
                             WHERE  user_id={?}', $p);
         $this->_data["$p"] = $res->fetchOneAssoc();
index 294026c..5f0e555 100644 (file)
@@ -13,6 +13,9 @@ create table profiles (
   birthdate_ref date default null,
   deathdate date default null,
 
+  # Last modification date (for notifications)
+  last_change date not null,
+
   primary key pid (pid),
   unique key hrpid (hrpid),
   unique key xorg_id (xorg_id),
index f4cfd89..311e3c4 100644 (file)
@@ -38,7 +38,8 @@ insert into carvas
 insert into profiles
      select user_id AS pid, hruid AS hrpid, matricule AS xorg_id,
             matricule_ax AS ax_id, naissance AS birthdate, naissance_ini AS birthdate_ref,
-            IF(deces = 0, NULL, deces) AS deathdate
+            IF(deces = 0, NULL, deces) AS deathdate,
+            date AS last_change
        from auth_user_md5
       where hruid is not null;