Do not reinsert private data if one can one insert ax or public data.
authorStéphane Jacob <sj@m4x.org>
Fri, 11 Feb 2011 12:50:45 +0000 (13:50 +0100)
committerStéphane Jacob <sj@m4x.org>
Fri, 11 Feb 2011 12:50:45 +0000 (13:50 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
modules/profile/addresses.inc.php
modules/profile/jobs.inc.php

index 07f310b..3be8b91 100644 (file)
@@ -767,22 +767,24 @@ class Address
      * @param $data: an array of form formatted addresses.
      * @param $pid, $type, $linkid: pid, type and id concerned by the update.
      */
-    static public function saveFromArray(array $data, $pid, $type = self::LINK_PROFILE, $linkid = null)
+    static public function saveFromArray(array $data, $pid, $type = self::LINK_PROFILE, $linkid = null, $savePrivate = true)
     {
         foreach ($data as $id => $value) {
-            if (!is_null($linkid)) {
-                $value['id'] = $linkid;
-            } else {
-                $value['id'] = $id;
-            }
-            if (!is_null($pid)) {
-                $value['pid'] = $pid;
-            }
-            if (!is_null($type)) {
-                $value['type'] = $type;
+            if ($value['pub'] != 'private' || $savePrivate) {
+                if (!is_null($linkid)) {
+                    $value['id'] = $linkid;
+                } else {
+                    $value['id'] = $id;
+                }
+                if (!is_null($pid)) {
+                    $value['pid'] = $pid;
+                }
+                if (!is_null($type)) {
+                    $value['type'] = $type;
+                }
+                $address = new Address($value);
+                $address->save();
             }
-            $address = new Address($value);
-            $address->save();
         }
     }
 
index de92fda..ca02810 100644 (file)
@@ -43,9 +43,11 @@ class ProfileSettingAddresses implements ProfileSetting
 
     public function save(ProfilePage &$page, $field, $value)
     {
-        Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, S::user()->isMe($page->owner) || S::admin());
-        Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, S::user()->isMe($page->owner) || S::admin());
-        Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE);
+        $deletePrivate = S::user()->isMe($page->owner) || S::admin();
+
+        Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, $deletePrivate);
+        Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
+        Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
         if (S::user()->isMe($page->owner) && count($value) > 1) {
             Platal::page()->trigWarning('Attention, tu as plusieurs adresses sur ton profil. Pense à supprimer celles qui sont obsolètes.');
         }
index 9dee7b0..0420c84 100644 (file)
@@ -263,7 +263,7 @@ class ProfileSettingJob implements ProfileSetting
         Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
         $terms_values = array();
         foreach ($value as $id => &$job) {
-            if (isset($job['name']) && $job['name']) {
+            if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) {
                 if (isset($job['jobid']) && $job['jobid']) {
                     XDB::execute('INSERT INTO  profile_job (pid, id, description, email,
                                                             url, pub, email_pub, jobid)