forked from extern/egroupware
fix: skip empty lines, even if conversion fills (empty) record
This commit is contained in:
parent
f726b0093b
commit
f1d0271672
@ -23,18 +23,17 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
'fieldsep', // char
|
'fieldsep', // char
|
||||||
'charset', // string
|
'charset', // string
|
||||||
'contact_owner', // int
|
'contact_owner', // int
|
||||||
|
'update_cats', // string {override|add} overides record
|
||||||
|
// with cat(s) from csv OR add the cat from
|
||||||
|
// csv file to exeisting cat(s) of record
|
||||||
|
'num_header_lines', // int number of header lines
|
||||||
'field_conversion', // array( $csv_col_num => conversion)
|
'field_conversion', // array( $csv_col_num => conversion)
|
||||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
'field_mapping', // array( $csv_col_num => adb_filed)
|
||||||
'has_header_line', //bool
|
|
||||||
'conditions', /* => array containing condition arrays:
|
'conditions', /* => array containing condition arrays:
|
||||||
'type' => exists, // exists
|
'type' => exists, // exists
|
||||||
'string' => '#kundennummer',
|
'string' => '#kundennummer',
|
||||||
'true' => array(
|
'true' => array(
|
||||||
'action' => update,
|
'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,
|
'last' => true,
|
||||||
),
|
),
|
||||||
'false' => array(
|
'false' => array(
|
||||||
@ -56,6 +55,11 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
private static $conditions = array( 'exists', 'greater', 'greater or equal', );
|
private static $conditions = array( 'exists', 'greater', 'greater or equal', );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var definition
|
||||||
|
*/
|
||||||
|
private $definition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bocontacts
|
* @var bocontacts
|
||||||
*/
|
*/
|
||||||
@ -66,6 +70,16 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
private $dry_run = false;
|
private $dry_run = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool is current user admin?
|
||||||
|
*/
|
||||||
|
private $is_admin = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $user = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* imports entries according to given definition object.
|
* imports entries according to given definition object.
|
||||||
* @param resource $_stream
|
* @param resource $_stream
|
||||||
@ -78,6 +92,12 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
'charset' => $_definition->plugin_options['charset'],
|
'charset' => $_definition->plugin_options['charset'],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->definition = $_definition;
|
||||||
|
|
||||||
|
// user, is admin ?
|
||||||
|
$this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin'];
|
||||||
|
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
||||||
|
|
||||||
// dry run?
|
// dry run?
|
||||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
||||||
|
|
||||||
@ -90,22 +110,24 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
// set FieldConversion
|
// set FieldConversion
|
||||||
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
||||||
|
|
||||||
//check if file has a header line
|
//check if file has a header lines
|
||||||
if ($_definition->plugin_options['has_header_line']) {
|
if ( isset( $_definition->plugin_options['num_header_lines'] ) ) {
|
||||||
$record = $import_csv->get_record();
|
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set contactOwner
|
// set eventOwner
|
||||||
if ( isset( $_definition->plugin_options['contact_owner'] )
|
$_definition->plugin_options['contact_owner'] = isset( $_definition->plugin_options['contact_owner'] ) ?
|
||||||
&& abs( $_definition->plugin_options['contact_owner'] > 0 ) ) {
|
$_definition->plugin_options['contact_owner'] : $this->user;
|
||||||
$record['contact_owner'] = $_definition->plugin_options['contact_owner'];
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( $record = $import_csv->get_record() ) {
|
while ( $record = $import_csv->get_record() ) {
|
||||||
|
|
||||||
// don't import empty contacts
|
// don't import empty contacts
|
||||||
if( count( array_unique( $record ) ) < 2 ) continue;
|
if( count( array_unique( $record ) ) < 2 ) continue;
|
||||||
|
|
||||||
|
if ( $_definition->plugin_options['contact_owner'] != -1 ) {
|
||||||
|
$record['contact_owner'] = $_definition->plugin_options['contact_owner'];
|
||||||
|
} else unset( $record['contact_owner'] );
|
||||||
|
|
||||||
if ( $_definition->plugin_options['conditions'] ) {
|
if ( $_definition->plugin_options['conditions'] ) {
|
||||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
||||||
switch ( $condition['type'] ) {
|
switch ( $condition['type'] ) {
|
||||||
@ -113,7 +135,7 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
case 'exists' :
|
case 'exists' :
|
||||||
$contacts = $this->bocontacts->search(
|
$contacts = $this->bocontacts->search(
|
||||||
array( $condition['string'] => $record[$condition['string']],),
|
array( $condition['string'] => $record[$condition['string']],),
|
||||||
$condition['true']['options']['update_cats'] == 'add' ? false : true
|
$_definition->plugin_options['update_cats'] == 'add' ? false : true
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( is_array( $contacts ) && count( array_keys( $contacts ) >= 1 ) ) {
|
if ( is_array( $contacts ) && count( array_keys( $contacts ) >= 1 ) ) {
|
||||||
@ -121,7 +143,7 @@ class import_contacts_csv implements iface_import_plugin {
|
|||||||
$action = $condition['true'];
|
$action = $condition['true'];
|
||||||
foreach ( (array)$contacts as $contact ) {
|
foreach ( (array)$contacts as $contact ) {
|
||||||
$record['id'] = $contact['id'];
|
$record['id'] = $contact['id'];
|
||||||
if ( $condition['true']['options']['update_cats'] == 'add' ) {
|
if ( $_definition->plugin_options['update_cats'] == 'add' ) {
|
||||||
if ( !is_array( $contact['cat_id'] ) ) $contact['cat_id'] = explode( ',', $contact['cat_id'] );
|
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'] );
|
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'] ) ) );
|
$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $contact['cat_id'] ) ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user