A user's contacts are profiles.
authorStéphane Jacob <sj@m4x.org>
Mon, 2 May 2011 15:51:29 +0000 (17:51 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 2 May 2011 15:51:29 +0000 (17:51 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/carnet.php
upgrade/1.1.1/14_contacts.sql [new file with mode: 0644]

index aee2890..b813289 100644 (file)
@@ -280,7 +280,7 @@ class CarnetModule extends PLModule
         }
         switch (Env::v('action')) {
             case 'retirer':
-                if (($contact = User::get(Env::v('user')))) {
+                if (($contact = Profile::get(Env::v('user')))) {
                     if (XDB::execute("DELETE FROM  contacts
                                             WHERE  uid = {?} AND contact = {?}",
                                      $uid, $contact->id())) {
@@ -291,7 +291,7 @@ class CarnetModule extends PLModule
                 break;
 
             case 'ajouter':
-                if (($contact = User::get(Env::v('user')))) {
+                if (($contact = Profile::get(Env::v('user')))) {
                     XDB::execute('INSERT IGNORE INTO  contacts (uid, contact)
                                               VALUES  ({?}, {?})',
                                  $uid, $contact->id());
diff --git a/upgrade/1.1.1/14_contacts.sql b/upgrade/1.1.1/14_contacts.sql
new file mode 100644 (file)
index 0000000..10a965c
--- /dev/null
@@ -0,0 +1,8 @@
+ALTER TABLE contacts DROP FOREIGN KEY contacts_ibfk_2;
+DELETE FROM  contacts
+      WHERE  NOT EXISTS (SELECT  profiles.*
+                           FROM  profiles
+                          WHERE  profiles.pid = contacts.contact);
+ALTER TABLE contacts ADD FOREIGN KEY (contact) REFERENCES profiles (pid) ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- vim:set syntax=mysql: