From ce92ba767a9557daf7f18be94882dd7e6f4591fb Mon Sep 17 00:00:00 2001 From: alecpl Date: Thu, 30 Sep 2010 13:24:33 +0000 Subject: - Plugin API: improved 'abort' flag handling, added 'result' item in some hooks: group_*, contact_*, identity_* (#1486914) --- program/steps/addressbook/copy.inc | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'program/steps/addressbook/copy.inc') diff --git a/program/steps/addressbook/copy.inc b/program/steps/addressbook/copy.inc index a37e93211..8a8379078 100644 --- a/program/steps/addressbook/copy.inc +++ b/program/steps/addressbook/copy.inc @@ -37,29 +37,31 @@ if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) & $ids = array(); foreach ($arr_cids as $cid) { - $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( - 'record' => $CONTACTS->get_record($cid, true), - 'source' => $target, - 'group' => $target_group, - )); - $a_record = $plugin['record']; + $a_record = $CONTACTS->get_record($cid, true); - if (!$plugin['abort']) { - // check if contact exists, if so, we'll need it's ID - $result = $TARGET->search('email', $a_record['email'], true, true); + // check if contact exists, if so, we'll need it's ID + $result = $TARGET->search('email', $a_record['email'], true, true); + + // insert contact record + if (!$result->count) { + $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( + 'record' => $a_record, 'source' => $target, 'group' => $target_group)); - // insert contact record - if (!$result->count) { + if (!$plugin['abort']) { if ($insert_id = $TARGET->insert($a_record, false)) { $ids[] = $insert_id; $success++; } } - else { - $record = $result->first(); - $ids[] = $record['ID']; + else if ($plugin['result']) { + $ids = array_merge($ids, $plugin['result']); + $success++; } } + else { + $record = $result->first(); + $ids[] = $record['ID']; + } } // assign to group @@ -79,6 +81,8 @@ if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) & if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success) $success = $cnt; } + else if ($plugin['result']) + $success = $plugin['result']; } } -- cgit v1.2.3