Cleans up watch_nonins when someone dies (Closes #975).
authorStéphane Jacob <sj@m4x.org>
Thu, 22 Oct 2009 21:02:35 +0000 (23:02 +0200)
committerStéphane Jacob <sj@m4x.org>
Thu, 29 Oct 2009 18:38:42 +0000 (19:38 +0100)
ChangeLog
include/notifs.inc.php
upgrade/0.10.2/01_watch_nonins.sql [new file with mode: 0644]

index 48d2ad8..e60dd09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,9 @@ Bug/Wish:
     * AXLetter:
         - #980: Adds option to invert a subset definition                  -XEL
 
+    * Carnet:
+        - #975: Cleans up watch_nonins when someone dies                   -JAC
+
     * Core:
         - #984: Properly upper/lowercases accented letters when necessary  -JAC
 
index eb70cc8..58d214c 100644 (file)
@@ -34,25 +34,33 @@ function inscription_notifs_base($uid)
 // }}}
 // {{{ function register_watch_op
 
-function register_watch_op($uid, $cid, $date='', $info='')
+function register_watch_op($uid, $cid, $date = '', $info = '')
 {
     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 ($cid == WATCH_FICHE) {
         if ($info) {
             register_profile_update($uid, $info);
         }
-        XDB::execute('UPDATE auth_user_md5 SET DATE=NOW() WHERE user_id={?}', $uid);
-    } elseif($cid == WATCH_INSCR) {
-        XDB::execute('REPLACE INTO  contacts (uid,contact)
-                            SELECT  uid,ni_id
+        XDB::execute('UPDATE  auth_user_md5
+                         SET  DATE = NOW()
+                       WHERE  user_id = {?}', $uid);
+    } elseif ($cid == WATCH_INSCR) {
+        XDB::execute('REPLACE INTO  contacts (uid, contact)
+                            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);
+    } elseif ($cid == WATCH_DEATH) {
+        // We delete nonins watches both for the dead (if non registered), and
+        // for people watched by the dead.
+        XDB::execute('DELETE FROM  watch_nonins
+                            WHERE  ni_id = {?} OR uid = {?}', $uid);
     }
     Platal::session()->updateNbNotifs();
 }
diff --git a/upgrade/0.10.2/01_watch_nonins.sql b/upgrade/0.10.2/01_watch_nonins.sql
new file mode 100644 (file)
index 0000000..13e1d9f
--- /dev/null
@@ -0,0 +1,6 @@
+    DELETE  w.*
+      FROM  watch_nonins  AS w
+INNER JOIN  auth_user_md5 AS a ON (w.uid = a.user_id OR w.ni_id = a.user_id)
+     WHERE  a.deces != '0000-00-00';
+
+-- vim:set syntax=mysql: