Adds a distinct flag for ax snail mails.
authorStéphane Jacob <sj@m4x.org>
Mon, 30 Apr 2012 16:23:57 +0000 (18:23 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 30 Apr 2012 16:23:57 +0000 (18:23 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
upgrade/1.1.5/09_addresses.sql [new file with mode: 0644]
upgrade/1.1.5/README [new file with mode: 0644]

index e5f677c..47ce17c 100644 (file)
@@ -726,6 +726,32 @@ class Address
                 $req = new AddressReq(S::user(), $this->toFormArray(), $this->pid, $this->jobid, $this->groupid, $this->type, $this->id);
                 $req->submit();
             }
+
+            if ($this->pid != 0) {
+                $this->updateAxMail();
+            }
+        }
+    }
+
+    private function updateAxMail()
+    {
+        XDB::execute("UPDATE  profile_addresses
+                         SET  flags = REPLACE(flags, 'ax_mail', '')
+                       WHERE  pid = {?}",
+                     $this->pid);
+
+        $ax_mail = XDB::fetchOneAssoc("SELECT  pid, jobid, groupid, type, id
+                                         FROM  profile_addresses
+                                        WHERE  pub IN ('public', 'ax') AND FIND_IN_SET('mail', flags) AND pid = {?}
+                                     ORDER BY  NOT FIND_IN_SET('current', flags),
+                                               FIND_IN_SET('secondary', flags), type = 'job'",
+                                      $this->pid);
+
+        if ($ax_mail) {
+            XDB::execute("UPDATE  profile_addresses
+                             SET  flags = CONCAT(flags, ',ax_mail')
+                           WHERE  pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}",
+                         $ax_mail['pid'], $ax_mail['jobid'], $ax_mail['groupid'], $ax_mail['type'], $ax_mail['id']);
         }
     }
 
diff --git a/upgrade/1.1.5/09_addresses.sql b/upgrade/1.1.5/09_addresses.sql
new file mode 100644 (file)
index 0000000..1ee3aa0
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE profile_addresses MODIFY COLUMN flags SET('current','temporary','secondary','mail','cedex','deliveryIssue', 'ax_mail') DEFAULT NULL;
+
+-- vim:set syntax=mysql:
diff --git a/upgrade/1.1.5/README b/upgrade/1.1.5/README
new file mode 100644 (file)
index 0000000..ef75029
--- /dev/null
@@ -0,0 +1,2 @@
+Please run (in bin/): ./formatAddresses.php -t p -r a
+