Changeset 3697 in subversion


Ignore:
Timestamp:
Jun 2, 2010 6:02:23 AM (3 years ago)
Author:
alec
Message:
  • Fix duplicated contacts when copying with group selected (#1486766)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/steps/addressbook/copy.inc

    r3694 r3697  
    3434 
    3535  if ($TARGET && $TARGET->ready && !$TARGET->readonly) { 
    36     if ($target_group && $TARGET->groups) 
    37       $TARGET->set_group($target_group); 
    38      
    3936    $arr_cids = explode(',', $cid); 
     37    $ids = array(); 
     38 
    4039    foreach ($arr_cids as $cid) { 
    4140      $plugin = $RCMAIL->plugins->exec_hook('create_contact', array( 
     
    4645      $a_record = $plugin['record']; 
    4746 
    48       if (!$plugin['abort']) 
    49         if ($TARGET->insert($a_record, true)) 
    50           $success++; 
     47      if (!$plugin['abort']) { 
     48        // check if contact exists, if so, we'll need it's ID 
     49        $result = $TARGET->search('email', $a_record['email'], true, true); 
     50 
     51        // insert contact record 
     52        if (!$result->count) { 
     53          if ($insert_id = $TARGET->insert($a_record, false)) { 
     54            $ids[] = $insert_id; 
     55            $success++; 
     56          } 
     57        } 
     58        else { 
     59          $record = $result->first(); 
     60          $ids[] = $record['ID']; 
     61        } 
     62      } 
     63    } 
     64 
     65    // assign to group 
     66    if ($target_group && $TARGET->groups && !empty($ids)) { 
     67      $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array( 
     68        'group_id' => $target_group, 'ids' => $ids, 'source' => $target)); 
     69 
     70      if (!$plugin['abort']) { 
     71        $TARGET->reset(); 
     72        $TARGET->set_group($target_group); 
     73 
     74        if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($TARGET->count()->count + count($plugin['ids']) > $maxnum)) { 
     75          $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); 
     76          $OUTPUT->send(); 
     77        } 
     78 
     79        if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success) 
     80          $success = $cnt; 
     81      } 
    5182    } 
    5283  } 
     
    5687  else 
    5788    $OUTPUT->show_message('copysuccess', 'notice', array('nr' => $success)); 
    58      
    59   // close connection to second address directory 
    60   $TARGET->close(); 
    6189} 
    6290 
Note: See TracChangeset for help on using the changeset viewer.