Fixed a bug with customer merge. Common contacts were being deleted when selected as a source contact to keep.

git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1000 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2010-07-12 21:48:42 +00:00
parent 954f0d7968
commit c76ba261d8

View File

@@ -330,13 +330,15 @@ class Customer extends AppModel {
} }
// Remove any contacts which are already destination customer contacts // Remove any contacts which are already destination customer contacts
$contacts = array_diff($contacts, array_keys($dst_contacts)); $new_contacts = array_diff($contacts, array_keys($dst_contacts));
$all_contacts = array_merge($new_contacts, array_keys($dst_contacts));
$this->pr(17, compact('new_contacts', 'all_contacts'));
// For now, we'll assume the operation will succeed. // For now, we'll assume the operation will succeed.
$ret = true; $ret = true;
// Add each desired source customer contact to the destination customer // Add each desired source customer contact to the destination customer
foreach ($contacts AS $contact_id) { foreach ($new_contacts AS $contact_id) {
$CM = new ContactsCustomer(); $CM = new ContactsCustomer();
if (!$CM->save(array('customer_id' => $dst_id) if (!$CM->save(array('customer_id' => $dst_id)
+ $src_contacts[$contact_id], false)) { + $src_contacts[$contact_id], false)) {
@@ -372,7 +374,7 @@ class Customer extends AppModel {
$this->delete($src_id); $this->delete($src_id);
// Delete all the orphaned customers // Delete all the orphaned customers
foreach (array_diff(array_keys($src_contacts), $contacts) AS $contact_id) { foreach (array_diff(array_keys($src_contacts), $all_contacts) AS $contact_id) {
// Delete un-used or duplicate contacts // Delete un-used or duplicate contacts
// REVISIT <AP> 20100702: // REVISIT <AP> 20100702:
// Not sure if we really want to do this. // Not sure if we really want to do this.