From f192583f5870a0b8784174300bf74d962473437b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 7 Apr 2011 15:28:45 +0000 Subject: [PATCH] - Move around field types into egw_record class - Add Infolog ID field to importexport - Fix import condition matching --- infolog/inc/class.infolog_egw_record.inc.php | 9 ++++++ infolog/inc/class.infolog_export_csv.inc.php | 10 +------ .../class.infolog_import_infologs_csv.inc.php | 29 +++++++++++-------- infolog/inc/class.infolog_merge.inc.php | 2 +- .../class.infolog_wizard_export_csv.inc.php | 2 +- ...infolog_wizard_import_infologs_csv.inc.php | 2 +- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/infolog/inc/class.infolog_egw_record.inc.php b/infolog/inc/class.infolog_egw_record.inc.php index 33b1b578dd..06a0a5c463 100644 --- a/infolog/inc/class.infolog_egw_record.inc.php +++ b/infolog/inc/class.infolog_egw_record.inc.php @@ -22,6 +22,15 @@ class infolog_egw_record implements importexport_iface_egw_record private $record = array(); private $bo; + // Used in conversions + static $types = array( + 'select-account' => array('info_owner','info_responsible','modifier'), + 'date-time' => array('info_datecompleted', 'info_datemodified','created','last_event','next_event'), + 'date' => array('info_startdate', 'info_enddate'), + 'select-cat' => array('info_cat', 'cat_id'), + 'links' => array('info_link_id'), + ); + /** * constructor * reads record from backend if identifier is given. diff --git a/infolog/inc/class.infolog_export_csv.inc.php b/infolog/inc/class.infolog_export_csv.inc.php index ad9e0b4d84..64b7a148d5 100644 --- a/infolog/inc/class.infolog_export_csv.inc.php +++ b/infolog/inc/class.infolog_export_csv.inc.php @@ -16,14 +16,6 @@ */ class infolog_export_csv implements importexport_iface_export_plugin { - // Used in conversions - static $types = array( - 'select-account' => array('info_owner','info_responsible','modifier'), - 'date-time' => array('info_datecompleted', 'info_datemodified','created','last_event','next_event'), - 'date' => array('info_startdate', 'info_enddate'), - 'select-cat' => array('info_cat', 'cat_id'), - 'links' => array('info_link_id'), - ); /** * Exports records as defined in $_definition @@ -66,7 +58,7 @@ class infolog_export_csv implements importexport_iface_export_plugin { } // Some conversion if($options['convert']) { - importexport_export_csv::convert($record, self::$types, 'infolog'); + importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog'); $this->convert($record); } else { // Implode arrays, so they don't say 'Array' diff --git a/infolog/inc/class.infolog_import_infologs_csv.inc.php b/infolog/inc/class.infolog_import_infologs_csv.inc.php index 8e2b4a933e..81a494be86 100644 --- a/infolog/inc/class.infolog_import_infologs_csv.inc.php +++ b/infolog/inc/class.infolog_import_infologs_csv.inc.php @@ -138,8 +138,14 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin { } // set Owner - $_definition->plugin_options['record_owner'] = isset( $_definition->plugin_options['record_owner'] ) ? + $_definition->plugin_options['record_owner'] = $_definition->plugin_options['record_owner'] ? $_definition->plugin_options['record_owner'] : $this->user; + $_definition->plugin_options['record_owner'] = $this->user; + + $_lookups = array( + 'info_type' => $this->boinfolog->enums['types'], + 'info_status' => $this->boinfolog->status['task'] + ); // Start counting successes $count = 0; @@ -154,6 +160,13 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin { // don't import empty records if( count( array_unique( $record ) ) < 2 ) continue; + $lookups = $_lookups; + if($record['info_type'] && $this->boinfolog->status[$record['info_type']]) { + $lookups['info_status'] = $this->boinfolog->status[$record['info_type']]; + } + + importexport_import_csv::convert($record, infolog_egw_record::$types, 'infolog', $lookups); + // Set owner, unless it's supposed to come from CSV file if($_definition->plugin_options['owner_from_csv']) { if(!is_numeric($record['info_owner'])) { @@ -168,9 +181,6 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin { $record['info_owner'] = $_definition->plugin_options['record_owner']; } - // Automatically handle text categories without explicit translation - $record['cat_id'] = importexport_helper_functions::cat_name2id($record['cat_id']); - // Special values if ($record['addressbook'] && !is_numeric($record['addressbook'])) { @@ -189,13 +199,8 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin { // exists case 'exists' : if($record[$condition['string']]) { - $results = $this->boinfolog->search( - //array( $condition['string'] => $record[$condition['string']],), - '', - $_definition->plugin_options['update_cats'] == 'add' ? false : true, - '', '', '', false, 'AND', false, - array( $condition['string'] => $record[$condition['string']],) - ); + $query['col_filter'] = array( $condition['string'] => $record[$condition['string']],); + $results = $this->boinfolog->search($query); } if ( is_array( $results ) && count( array_keys( $results )) >= 1) { @@ -246,7 +251,7 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin { return true; case 'update' : // Only update if there are changes - $old = $this->boinfolog->read($_data['id']); + $old = $this->boinfolog->read($_data['info_id']); if(!$this->definition->plugin_options['change_owner']) { // Don't change addressbook of an existing contact diff --git a/infolog/inc/class.infolog_merge.inc.php b/infolog/inc/class.infolog_merge.inc.php index 577396e0b7..8b060e8a12 100644 --- a/infolog/inc/class.infolog_merge.inc.php +++ b/infolog/inc/class.infolog_merge.inc.php @@ -79,7 +79,7 @@ class infolog_merge extends bo_merge $info = array(); // Convert to human friendly values - $types = infolog_export_csv::$types; + $types = infolog_egw_record::$types; $_selects = $this->bo->enums + array('status' => $this->bo->status[$record->info_type]); foreach($_selects as $name => $value) { diff --git a/infolog/inc/class.infolog_wizard_export_csv.inc.php b/infolog/inc/class.infolog_wizard_export_csv.inc.php index b981cb71f4..bf7d49d172 100644 --- a/infolog/inc/class.infolog_wizard_export_csv.inc.php +++ b/infolog/inc/class.infolog_wizard_export_csv.inc.php @@ -17,7 +17,7 @@ class infolog_wizard_export_csv extends importexport_wizard_basic_export_csv // Field mapping $bo = new infolog_tracking(); - $this->export_fields = $bo->field2label; + $this->export_fields = array('info_id' => 'Infolog ID') + $bo->field2label; // Custom fields unset($this->export_fields['custom']); // Heading, not a real field diff --git a/infolog/inc/class.infolog_wizard_import_infologs_csv.inc.php b/infolog/inc/class.infolog_wizard_import_infologs_csv.inc.php index cb72f68101..4cc8b885f7 100644 --- a/infolog/inc/class.infolog_wizard_import_infologs_csv.inc.php +++ b/infolog/inc/class.infolog_wizard_import_infologs_csv.inc.php @@ -27,7 +27,7 @@ class infolog_wizard_import_infologs_csv extends importexport_wizard_basic_impor // Field mapping $tracking = new infolog_tracking(); - $this->mapping_fields = $tracking->field2label + infolog_import_infologs_csv::$special_fields; + $this->mapping_fields = array('info_id' => 'Infolog ID') + $tracking->field2label + infolog_import_infologs_csv::$special_fields; // List each custom field unset($this->mapping_fields['custom']); $custom = config::get_customfields('infolog');