From d3ce1117c43e2463f109c8f0b82b8aeee42407db Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 11 Feb 2011 13:50:45 +0100 Subject: [PATCH] Do not reinsert private data if one can one insert ax or public data. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/address.php | 28 +++++++++++++++------------- modules/profile/addresses.inc.php | 8 +++++--- modules/profile/jobs.inc.php | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/classes/address.php b/classes/address.php index 07f310b..3be8b91 100644 --- a/classes/address.php +++ b/classes/address.php @@ -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(); } } diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index de92fda..ca02810 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -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.'); } diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 9dee7b0..0420c84 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -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) -- 2.1.4