From 10225ce9d8a589b2476253d1d2e541ab50b9601a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Thu, 21 Jun 2007 14:02:28 +0000 Subject: [PATCH] fixed category handling. allow to preserv cat if record is updated --- .../class.import_contacts_csv.inc.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/addressbook/importexport/class.import_contacts_csv.inc.php b/addressbook/importexport/class.import_contacts_csv.inc.php index 1bdf9892c4..3f910e7bb4 100644 --- a/addressbook/importexport/class.import_contacts_csv.inc.php +++ b/addressbook/importexport/class.import_contacts_csv.inc.php @@ -27,10 +27,14 @@ class import_contacts_csv implements iface_import_plugin { 'field_mapping', // array( $csv_col_num => adb_filed) 'has_header_line', //bool 'conditions', /* => array containing condition arrays: - 'type' => 0, // exists + 'type' => exists, // exists 'string' => '#kundennummer', 'true' => array( 'action' => update, + 'options' => array ( + update_cats' => 'add' // string {override|add} overides record + ), // with cat(s) from csv OR add the cat from + // csv file to exeisting cat(s) of record 'last' => true, ), 'false' => array( @@ -96,6 +100,7 @@ class import_contacts_csv implements iface_import_plugin { $record['contact_owner'] = $_definition->plugin_options['contact_owner']; } + // while ( $record = $import_csv->get_record() ) { // don't import empty contacts @@ -106,15 +111,21 @@ class import_contacts_csv implements iface_import_plugin { switch ( $condition['type'] ) { // exists case 'exists' : - $contacts = $this->bocontacts->search(array( - $condition['string'] => $record[$condition['string']], - ),true); + $contacts = $this->bocontacts->search( + array( $condition['string'] => $record[$condition['string']],), + $condition['true']['options']['update_cats'] == 'add' ? false : true + ); if ( is_array( $contacts ) && count( array_keys( $contacts ) >= 1 ) ) { // apply action to all contacts matching this exists condition $action = $condition['true']; foreach ( (array)$contacts as $contact ) { $record['id'] = $contact['id']; + if ( $condition['true']['options']['update_cats'] == 'add' ) { + if ( !is_array( $contact['cat_id'] ) ) $contact['cat_id'] = explode( ',', $contact['cat_id'] ); + if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] ); + $record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $contact['cat_id'] ) ) ); + } $this->action( $action['action'], $record ); } } else {