- Move around field types into egw_record class

- Add Infolog ID field to importexport
- Fix import condition matching
This commit is contained in:
Nathan Gray 2011-04-07 15:28:45 +00:00
parent 02d8b86d7e
commit f192583f58
6 changed files with 30 additions and 24 deletions

View File

@ -22,6 +22,15 @@ class infolog_egw_record implements importexport_iface_egw_record
private $record = array(); private $record = array();
private $bo; 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 * constructor
* reads record from backend if identifier is given. * reads record from backend if identifier is given.

View File

@ -16,14 +16,6 @@
*/ */
class infolog_export_csv implements importexport_iface_export_plugin { 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 * Exports records as defined in $_definition
@ -66,7 +58,7 @@ class infolog_export_csv implements importexport_iface_export_plugin {
} }
// Some conversion // Some conversion
if($options['convert']) { if($options['convert']) {
importexport_export_csv::convert($record, self::$types, 'infolog'); importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog');
$this->convert($record); $this->convert($record);
} else { } else {
// Implode arrays, so they don't say 'Array' // Implode arrays, so they don't say 'Array'

View File

@ -138,8 +138,14 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin {
} }
// set Owner // 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;
$_definition->plugin_options['record_owner'] = $this->user;
$_lookups = array(
'info_type' => $this->boinfolog->enums['types'],
'info_status' => $this->boinfolog->status['task']
);
// Start counting successes // Start counting successes
$count = 0; $count = 0;
@ -154,6 +160,13 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin {
// don't import empty records // don't import empty records
if( count( array_unique( $record ) ) < 2 ) continue; 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 // Set owner, unless it's supposed to come from CSV file
if($_definition->plugin_options['owner_from_csv']) { if($_definition->plugin_options['owner_from_csv']) {
if(!is_numeric($record['info_owner'])) { 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']; $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 // Special values
if ($record['addressbook'] && !is_numeric($record['addressbook'])) if ($record['addressbook'] && !is_numeric($record['addressbook']))
{ {
@ -189,13 +199,8 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin {
// exists // exists
case 'exists' : case 'exists' :
if($record[$condition['string']]) { if($record[$condition['string']]) {
$results = $this->boinfolog->search( $query['col_filter'] = array( $condition['string'] => $record[$condition['string']],);
//array( $condition['string'] => $record[$condition['string']],), $results = $this->boinfolog->search($query);
'',
$_definition->plugin_options['update_cats'] == 'add' ? false : true,
'', '', '', false, 'AND', false,
array( $condition['string'] => $record[$condition['string']],)
);
} }
if ( is_array( $results ) && count( array_keys( $results )) >= 1) { 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; return true;
case 'update' : case 'update' :
// Only update if there are changes // 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']) { if(!$this->definition->plugin_options['change_owner']) {
// Don't change addressbook of an existing contact // Don't change addressbook of an existing contact

View File

@ -79,7 +79,7 @@ class infolog_merge extends bo_merge
$info = array(); $info = array();
// Convert to human friendly values // 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]); $_selects = $this->bo->enums + array('status' => $this->bo->status[$record->info_type]);
foreach($_selects as $name => $value) foreach($_selects as $name => $value)
{ {

View File

@ -17,7 +17,7 @@ class infolog_wizard_export_csv extends importexport_wizard_basic_export_csv
// Field mapping // Field mapping
$bo = new infolog_tracking(); $bo = new infolog_tracking();
$this->export_fields = $bo->field2label; $this->export_fields = array('info_id' => 'Infolog ID') + $bo->field2label;
// Custom fields // Custom fields
unset($this->export_fields['custom']); // Heading, not a real field unset($this->export_fields['custom']); // Heading, not a real field

View File

@ -27,7 +27,7 @@ class infolog_wizard_import_infologs_csv extends importexport_wizard_basic_impor
// Field mapping // Field mapping
$tracking = new infolog_tracking(); $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 // List each custom field
unset($this->mapping_fields['custom']); unset($this->mapping_fields['custom']);
$custom = config::get_customfields('infolog'); $custom = config::get_customfields('infolog');