mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 15:33:23 +01:00
* Importexport: Progress updates when importing
This commit is contained in:
parent
707c0a7a6e
commit
56774cfeee
@ -15,27 +15,9 @@ use EGroupware\Api;
|
|||||||
/**
|
/**
|
||||||
* class import_csv for admin (groups)
|
* class import_csv for admin (groups)
|
||||||
*/
|
*/
|
||||||
class admin_import_groups_csv implements importexport_iface_import_plugin {
|
class admin_import_groups_csv extends importexport_basic_import_csv
|
||||||
|
{
|
||||||
|
|
||||||
private static $plugin_options = array(
|
|
||||||
'fieldsep', // char
|
|
||||||
'charset', // string
|
|
||||||
'num_header_lines', // int number of header lines
|
|
||||||
'field_conversion', // array( $csv_col_num => conversion)
|
|
||||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
|
||||||
'conditions', /* => array containing condition arrays:
|
|
||||||
'type' => exists, // exists
|
|
||||||
'string' => '#kundennummer',
|
|
||||||
'true' => array(
|
|
||||||
'action' => update,
|
|
||||||
'last' => true,
|
|
||||||
),
|
|
||||||
'false' => array(
|
|
||||||
'action' => insert,
|
|
||||||
'last' => true,
|
|
||||||
),*/
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* actions which could be done to data entries
|
* actions which could be done to data entries
|
||||||
@ -49,128 +31,80 @@ class admin_import_groups_csv implements importexport_iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
protected static $conditions = array( 'exists' );
|
protected static $conditions = array( 'exists' );
|
||||||
|
|
||||||
/**
|
|
||||||
* @var definition
|
|
||||||
*/
|
|
||||||
private $definition;
|
|
||||||
|
|
||||||
/**
|
protected function import_record(importexport_iface_egw_record &$record, &$import_csv)
|
||||||
* @var bool
|
{
|
||||||
*/
|
if($this->definition->plugin_options['conditions'])
|
||||||
private $dry_run = false;
|
{
|
||||||
|
foreach($this->definition->plugin_options['conditions'] as $condition)
|
||||||
|
{
|
||||||
|
switch($condition['type'])
|
||||||
|
{
|
||||||
|
// exists
|
||||||
|
case 'exists' :
|
||||||
|
$accounts = array();
|
||||||
|
|
||||||
/**
|
// Skip the search if the field is empty
|
||||||
* List of import warnings
|
if($record[$condition['string']] !== '')
|
||||||
*/
|
{
|
||||||
protected $warnings = array();
|
|
||||||
|
|
||||||
/**
|
$accounts = $GLOBALS['egw']->accounts->search(array(
|
||||||
* List of import errors
|
'type' => 'groups',
|
||||||
*/
|
'query' => $record[$condition['string']],
|
||||||
protected $errors = array();
|
'query_type' => $condition['string']
|
||||||
|
));
|
||||||
/**
|
}
|
||||||
* List of actions, and how many times that action was taken
|
// Search looks in the given field, but doesn't do an exact match
|
||||||
*/
|
foreach((array)$accounts as $key => $account)
|
||||||
protected $results = array();
|
{
|
||||||
|
if($account[$condition['string']] != $record[$condition['string']])
|
||||||
/**
|
|
||||||
* imports entries according to given definition object.
|
|
||||||
* @param resource $_stream
|
|
||||||
* @param string $_charset
|
|
||||||
* @param definition $_definition
|
|
||||||
*/
|
|
||||||
public function import( $_stream, importexport_definition $_definition ) {
|
|
||||||
$import_csv = new importexport_import_csv( $_stream, array(
|
|
||||||
'fieldsep' => $_definition->plugin_options['fieldsep'],
|
|
||||||
'charset' => $_definition->plugin_options['charset'],
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->definition = $_definition;
|
|
||||||
|
|
||||||
// dry run?
|
|
||||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
|
||||||
|
|
||||||
// set FieldMapping.
|
|
||||||
$import_csv->mapping = $_definition->plugin_options['field_mapping'];
|
|
||||||
|
|
||||||
// set FieldConversion
|
|
||||||
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
|
||||||
|
|
||||||
//check if file has a header lines
|
|
||||||
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
|
||||||
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
|
||||||
} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
|
|
||||||
// First method is preferred
|
|
||||||
$import_csv->skip_records(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start counting successes
|
|
||||||
$count = 0;
|
|
||||||
$this->results = array();
|
|
||||||
|
|
||||||
// Failures
|
|
||||||
$this->errors = array();
|
|
||||||
|
|
||||||
while ( $record = $import_csv->get_record() ) {
|
|
||||||
$success = false;
|
|
||||||
// don't import empty records
|
|
||||||
if( count( array_unique( $record ) ) < 2 ) continue;
|
|
||||||
|
|
||||||
importexport_import_csv::convert($record, admin_egw_group_record::$types, 'admin');
|
|
||||||
|
|
||||||
if ( $_definition->plugin_options['conditions'] ) {
|
|
||||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
|
||||||
switch ( $condition['type'] ) {
|
|
||||||
// exists
|
|
||||||
case 'exists' :
|
|
||||||
$accounts = array();
|
|
||||||
|
|
||||||
// Skip the search if the field is empty
|
|
||||||
if($record[$condition['string']] !== '') {
|
|
||||||
|
|
||||||
$accounts = $GLOBALS['egw']->accounts->search(array(
|
|
||||||
'type' => 'groups',
|
|
||||||
'query' => $record[$condition['string']],
|
|
||||||
'query_type' => $condition['string']
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// Search looks in the given field, but doesn't do an exact match
|
|
||||||
foreach ( (array)$accounts as $key => $account )
|
|
||||||
{
|
{
|
||||||
if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]);
|
unset($accounts[$key]);
|
||||||
}
|
}
|
||||||
if ( is_array( $accounts ) && count( $accounts ) >= 1 ) {
|
}
|
||||||
$account = current($accounts);
|
if(is_array($accounts) && count($accounts) >= 1)
|
||||||
// apply action to all contacts matching this exists condition
|
{
|
||||||
$action = $condition['true'];
|
$account = current($accounts);
|
||||||
foreach ( (array)$accounts as $account ) {
|
// apply action to all contacts matching this exists condition
|
||||||
// Read full account, and copy needed info for accounts->save()
|
$action = $condition['true'];
|
||||||
$account = $GLOBALS['egw']->accounts->read($account['account_id']);
|
foreach((array)$accounts as $account)
|
||||||
$record['account_id'] = $account['account_id'];
|
{
|
||||||
$record['account_firstname'] = $account['account_firstname'];
|
// Read full account, and copy needed info for accounts->save()
|
||||||
$record['account_lastname'] = $account['account_lastname'];
|
$account = $GLOBALS['egw']->accounts->read($account['account_id']);
|
||||||
$success = $this->action( $action['action'], $record, $import_csv->get_current_position() );
|
$record['account_id'] = $account['account_id'];
|
||||||
}
|
$record['account_firstname'] = $account['account_firstname'];
|
||||||
} else {
|
$record['account_lastname'] = $account['account_lastname'];
|
||||||
$action = $condition['false'];
|
$success = $this->admin_action($action['action'], $record, $import_csv->get_current_position());
|
||||||
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$action = $condition['false'];
|
||||||
|
$success = ($this->admin_action($action['action'], $record, $import_csv->get_current_position()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// not supported action
|
// not supported action
|
||||||
default :
|
default :
|
||||||
die('condition / action not supported!!!');
|
die('condition / action not supported!!!');
|
||||||
}
|
}
|
||||||
if ($action['last']) break;
|
if($action['last'])
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// unconditional insert
|
|
||||||
$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
|
|
||||||
}
|
}
|
||||||
if($success) $count++;
|
|
||||||
}
|
}
|
||||||
return $count;
|
else
|
||||||
|
{
|
||||||
|
// unconditional insert
|
||||||
|
$success = $this->admin_action('insert', $record, $import_csv->get_current_position());
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function action($_action, importexport_iface_egw_record &$record, $record_num = 0)
|
||||||
|
{
|
||||||
|
// Not used, see admin_action()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,7 +114,7 @@ class admin_import_groups_csv implements importexport_iface_import_plugin {
|
|||||||
* @param array $_data contact data for the action
|
* @param array $_data contact data for the action
|
||||||
* @return bool success or not
|
* @return bool success or not
|
||||||
*/
|
*/
|
||||||
private function action ( $_action, $_data, $record_num = 0 ) {
|
private function admin_action($_action, $_data, $record_num = 0 ) {
|
||||||
switch ($_action) {
|
switch ($_action) {
|
||||||
case 'none' :
|
case 'none' :
|
||||||
return true;
|
return true;
|
||||||
|
@ -15,28 +15,8 @@ use EGroupware\Api;
|
|||||||
/**
|
/**
|
||||||
* class import_csv for admin (users)
|
* class import_csv for admin (users)
|
||||||
*/
|
*/
|
||||||
class admin_import_users_csv implements importexport_iface_import_plugin {
|
class admin_import_users_csv extends importexport_basic_import_csv
|
||||||
|
{
|
||||||
private static $plugin_options = array(
|
|
||||||
'fieldsep', // char
|
|
||||||
'charset', // string
|
|
||||||
'num_header_lines', // int number of header lines
|
|
||||||
'field_conversion', // array( $csv_col_num => conversion)
|
|
||||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
|
||||||
'conditions', /* => array containing condition arrays:
|
|
||||||
'type' => exists, // exists
|
|
||||||
'string' => '#kundennummer',
|
|
||||||
'true' => array(
|
|
||||||
'action' => update,
|
|
||||||
'last' => true,
|
|
||||||
),
|
|
||||||
'false' => array(
|
|
||||||
'action' => insert,
|
|
||||||
'last' => true,
|
|
||||||
),*/
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* actions which could be done to data entries
|
* actions which could be done to data entries
|
||||||
*/
|
*/
|
||||||
@ -49,142 +29,99 @@ class admin_import_users_csv implements importexport_iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
protected static $conditions = array( 'exists' );
|
protected static $conditions = array( 'exists' );
|
||||||
|
|
||||||
/**
|
|
||||||
* @var definition
|
|
||||||
*/
|
|
||||||
private $definition;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $dry_run = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool is current user admin?
|
|
||||||
*/
|
|
||||||
private $is_admin = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $user = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of import warnings
|
|
||||||
*/
|
|
||||||
protected $warnings = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of import errors
|
|
||||||
*/
|
|
||||||
protected $errors = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of actions, and how many times that action was taken
|
|
||||||
*/
|
|
||||||
protected $results = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* imports entries according to given definition object.
|
* imports entries according to given definition object.
|
||||||
* @param resource $_stream
|
* @param resource $_stream
|
||||||
* @param string $_charset
|
* @param string $_charset
|
||||||
* @param definition $_definition
|
* @param definition $_definition
|
||||||
*/
|
*/
|
||||||
public function import( $_stream, importexport_definition $_definition ) {
|
public function init(importexport_definition $definition, importexport_import_csv $import_csv = null)
|
||||||
$import_csv = new importexport_import_csv( $_stream, array(
|
{
|
||||||
'fieldsep' => $_definition->plugin_options['fieldsep'],
|
parent::init($definition, $import_csv); // TODO: Change the autogenerated stub
|
||||||
'charset' => $_definition->plugin_options['charset'],
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->definition = $_definition;
|
$this->lookups['account_status'] = array('A' => lang('Active'), '' => lang('Disabled'),
|
||||||
|
'D' => lang('Disabled'));
|
||||||
|
}
|
||||||
|
|
||||||
// user, is admin ?
|
protected function import_record(importexport_iface_egw_record &$record, &$import_csv)
|
||||||
$this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin'];
|
{
|
||||||
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
$success = false;
|
||||||
|
// don't import empty records
|
||||||
// dry run?
|
if(count(array_unique($record)) < 2)
|
||||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
{
|
||||||
|
return $success;
|
||||||
// set FieldMapping.
|
|
||||||
$import_csv->mapping = $_definition->plugin_options['field_mapping'];
|
|
||||||
|
|
||||||
// set FieldConversion
|
|
||||||
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
|
||||||
|
|
||||||
//check if file has a header lines
|
|
||||||
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
|
||||||
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
|
||||||
} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
|
|
||||||
// First method is preferred
|
|
||||||
$import_csv->skip_records(1);
|
|
||||||
}
|
}
|
||||||
$admin_cmd = $_definition->plugin_options['admin_cmd'];
|
|
||||||
|
|
||||||
// Start counting successes
|
if(strtolower($record['account_expires']) == 'never')
|
||||||
$count = 0;
|
{
|
||||||
$this->results = array();
|
$record['account_expires'] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Failures
|
if($this->definition->plugin_options['conditions'])
|
||||||
$this->errors = array();
|
{
|
||||||
|
foreach($this->definition->plugin_options['conditions'] as $condition)
|
||||||
$lookups = array(
|
{
|
||||||
'account_status' => array('A' => lang('Active'), '' => lang('Disabled'), 'D' => lang('Disabled')),
|
switch($condition['type'])
|
||||||
);
|
{
|
||||||
|
// exists
|
||||||
while ( $record = $import_csv->get_record() ) {
|
case 'exists' :
|
||||||
$success = false;
|
$accounts = array();
|
||||||
// don't import empty records
|
// Skip the search if the field is empty
|
||||||
if( count( array_unique( $record ) ) < 2 ) continue;
|
if($record[$condition['string']] !== '')
|
||||||
|
{
|
||||||
if(strtolower($record['account_expires']) == 'never') $record['account_expires'] = -1;
|
$accounts = $GLOBALS['egw']->accounts->search(array(
|
||||||
importexport_import_csv::convert($record, admin_egw_user_record::$types, 'admin', $lookups);
|
'type' => 'accounts',
|
||||||
|
'query' => $record[$condition['string']],
|
||||||
if ( $_definition->plugin_options['conditions'] ) {
|
'query_type' => $condition['string']
|
||||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
));
|
||||||
switch ( $condition['type'] ) {
|
}
|
||||||
// exists
|
// Search looks in the given field, but doesn't do an exact match
|
||||||
case 'exists' :
|
foreach((array)$accounts as $key => $account)
|
||||||
$accounts = array();
|
{
|
||||||
// Skip the search if the field is empty
|
if($account[$condition['string']] != $record[$condition['string']])
|
||||||
if($record[$condition['string']] !== '')
|
|
||||||
{
|
{
|
||||||
$accounts = $GLOBALS['egw']->accounts->search(array(
|
unset($accounts[$key]);
|
||||||
'type' => 'accounts',
|
|
||||||
'query' => $record[$condition['string']],
|
|
||||||
'query_type' => $condition['string']
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
// Search looks in the given field, but doesn't do an exact match
|
}
|
||||||
foreach ( (array)$accounts as $key => $account )
|
if(is_array($accounts) && count($accounts) >= 1)
|
||||||
|
{
|
||||||
|
// apply action to all contacts matching this exists condition
|
||||||
|
$action = $condition['true'];
|
||||||
|
foreach((array)$accounts as $account)
|
||||||
{
|
{
|
||||||
if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]);
|
$record['account_id'] = $account['account_id'];
|
||||||
|
$success = $this->admin_action($action['action'], $record, $import_csv->get_current_position(), $admin_cmd);
|
||||||
}
|
}
|
||||||
if ( is_array( $accounts ) && count( $accounts ) >= 1 ) {
|
}
|
||||||
// apply action to all contacts matching this exists condition
|
else
|
||||||
$action = $condition['true'];
|
{
|
||||||
foreach ( (array)$accounts as $account ) {
|
$action = $condition['false'];
|
||||||
$record['account_id'] = $account['account_id'];
|
$success = ($this->admin_action($action['action'], $record, $import_csv->get_current_position(), $admin_cmd));
|
||||||
$success = $this->action( $action['action'], $record, $import_csv->get_current_position(), $admin_cmd );
|
}
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
$action = $condition['false'];
|
|
||||||
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position(), $admin_cmd ));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// not supported action
|
// not supported action
|
||||||
default :
|
default :
|
||||||
die('condition / action not supported!!!');
|
die('condition / action not supported!!!');
|
||||||
}
|
}
|
||||||
if ($action['last']) break;
|
if($action['last'])
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// unconditional insert
|
|
||||||
$success = $this->action( 'create', $record, $import_csv->get_current_position(), $admin_cmd );
|
|
||||||
}
|
}
|
||||||
if($success) $count++;
|
|
||||||
}
|
}
|
||||||
return $count;
|
else
|
||||||
|
{
|
||||||
|
// unconditional insert
|
||||||
|
$success = $this->admin_action('create', $record, $import_csv->get_current_position(), $admin_cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function action($_action, importexport_iface_egw_record &$record, $record_num = 0)
|
||||||
|
{
|
||||||
|
// Not used, see admin_action()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,7 +131,8 @@ class admin_import_users_csv implements importexport_iface_import_plugin {
|
|||||||
* @param array $_data contact data for the action
|
* @param array $_data contact data for the action
|
||||||
* @return bool success or not
|
* @return bool success or not
|
||||||
*/
|
*/
|
||||||
private function action ( $_action, $_data, $record_num = 0, $admin_cmd ) {
|
private function admin_action($_action, $_data, $record_num = 0, $admin_cmd)
|
||||||
|
{
|
||||||
switch ($_action) {
|
switch ($_action) {
|
||||||
case 'none' :
|
case 'none' :
|
||||||
return true;
|
return true;
|
||||||
|
@ -99,6 +99,8 @@ class calendar_import_ical implements importexport_iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
protected $results = array();
|
protected $results = array();
|
||||||
|
|
||||||
|
protected $record_count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* imports entries according to given definition object.
|
* imports entries according to given definition object.
|
||||||
* @param resource $_stream
|
* @param resource $_stream
|
||||||
@ -132,6 +134,15 @@ class calendar_import_ical implements importexport_iface_import_plugin {
|
|||||||
echo lang("No preview for iCal");
|
echo lang("No preview for iCal");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Estimate event count
|
||||||
|
while(($line = fgets($_stream)) !== false)
|
||||||
|
{
|
||||||
|
$this->record_count += preg_match_all("/^BEGIN:VEVENT/i", $line, $matches);
|
||||||
|
}
|
||||||
|
rewind($_stream);
|
||||||
|
}
|
||||||
// switch off notifications by default
|
// switch off notifications by default
|
||||||
$plugin_options = $_definition->plugin_options;
|
$plugin_options = $_definition->plugin_options;
|
||||||
if(!array_key_exists('no_notification', $_definition->plugin_options))
|
if(!array_key_exists('no_notification', $_definition->plugin_options))
|
||||||
@ -180,6 +191,8 @@ class calendar_import_ical implements importexport_iface_import_plugin {
|
|||||||
$this->results['imported'] += $calendar_ical->events_imported;
|
$this->results['imported'] += $calendar_ical->events_imported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importexport_import_ui::sendUpdate(100, $this->results['imported'], print_r($this->results, true));
|
||||||
|
|
||||||
return $calendar_ical->events_imported;
|
return $calendar_ical->events_imported;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,11 +201,16 @@ class calendar_import_ical implements importexport_iface_import_plugin {
|
|||||||
*/
|
*/
|
||||||
public function event_callback(&$event)
|
public function event_callback(&$event)
|
||||||
{
|
{
|
||||||
|
static $event_count = 0;
|
||||||
|
|
||||||
// Check & apply value overrides
|
// Check & apply value overrides
|
||||||
foreach((array)$this->definition->plugin_options['override_values'] as $field => $settings)
|
foreach((array)$this->definition->plugin_options['override_values'] as $field => $settings)
|
||||||
{
|
{
|
||||||
$event[$field] = $settings['value'];
|
$event[$field] = $settings['value'];
|
||||||
}
|
}
|
||||||
|
// Update UI with progress
|
||||||
|
$progress = $this->record_count ? (int)(100 * (++$event_count / $this->record_count)) : false;
|
||||||
|
importexport_import_ui::sendUpdate($progress, $this->bo->link_title($event), $this->bo->link_title($event));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,12 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
// set FieldConversion
|
// set FieldConversion
|
||||||
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
||||||
|
|
||||||
|
if(!$this->dry_run)
|
||||||
|
{
|
||||||
|
// This needs to scan the whole file, so it can take a while
|
||||||
|
$record_count = $import_csv->get_num_of_records();
|
||||||
|
}
|
||||||
|
|
||||||
//check if file has a header lines
|
//check if file has a header lines
|
||||||
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
||||||
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
||||||
@ -190,7 +196,19 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
{
|
{
|
||||||
$this->set_overrides($_definition, $egw_record);
|
$this->set_overrides($_definition, $egw_record);
|
||||||
}
|
}
|
||||||
$success = $this->import_record($egw_record, $import_csv);
|
try
|
||||||
|
{
|
||||||
|
$success = $this->import_record($egw_record, $import_csv);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$this->errors[] = $e->getMessage();
|
||||||
|
$success = false;
|
||||||
|
if(!$this->dry_run)
|
||||||
|
{
|
||||||
|
importexport_import_ui::sendUpdate("", get_class($e), $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($success)
|
if($success)
|
||||||
{
|
{
|
||||||
@ -204,6 +222,13 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
set_time_limit(10);
|
set_time_limit(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send an update to client
|
||||||
|
if(!$this->dry_run)
|
||||||
|
{
|
||||||
|
$complete = $record_count ? (int)(100 * ($import_csv->get_current_position() / $record_count)) : false;
|
||||||
|
$this->sendUpdate($complete, $egw_record);
|
||||||
|
}
|
||||||
|
|
||||||
// Keep a few records for preview, but process the whole file
|
// Keep a few records for preview, but process the whole file
|
||||||
if($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])
|
if($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])
|
||||||
{
|
{
|
||||||
@ -734,5 +759,26 @@ error_log("Searching for $custom_field = $value");
|
|||||||
public function get_results() {
|
public function get_results() {
|
||||||
return $this->results;
|
return $this->results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send some progress so the UI doesn't look frozen
|
||||||
|
*
|
||||||
|
* @param integer $complete 0-100 or false for indeterminate
|
||||||
|
* @param importexport_iface_egw_record $record
|
||||||
|
* @return void
|
||||||
|
* @throws Api\Json\Exception
|
||||||
|
*/
|
||||||
|
protected function sendUpdate($complete, $record)
|
||||||
|
{
|
||||||
|
$label = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$label = $record->get_title() ?: "";
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
importexport_import_ui::sendUpdate($complete, $label, substr(array2string($record->get_record_array()), 0, 120) . '...');
|
||||||
|
}
|
||||||
} // end of iface_export_plugin
|
} // end of iface_export_plugin
|
||||||
?>
|
?>
|
||||||
|
@ -175,7 +175,9 @@ class importexport_import_csv implements importexport_iface_import_record { //,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'last' :
|
case 'last' :
|
||||||
while ($this->get_raw_record()) {}
|
while($this->get_raw_record() !== false)
|
||||||
|
{
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: //somenumber
|
default: //somenumber
|
||||||
@ -207,7 +209,7 @@ class importexport_import_csv implements importexport_iface_import_record { //,
|
|||||||
return $this->num_of_records;
|
return $this->num_of_records;
|
||||||
}
|
}
|
||||||
$current_position = $this->current_position;
|
$current_position = $this->current_position;
|
||||||
while ($this->get_raw_record()) {}
|
$this->get_raw_record('last');
|
||||||
$this->num_of_records = $this->current_position;
|
$this->num_of_records = $this->current_position;
|
||||||
$this->get_record($current_position);
|
$this->get_record($current_position);
|
||||||
return $this->num_of_records;
|
return $this->num_of_records;
|
||||||
|
@ -137,19 +137,21 @@ use EGroupware\Api\Etemplate;
|
|||||||
{
|
{
|
||||||
$this->message .= implode("<br />\n", $check_message) . "<br />\n";
|
$this->message .= implode("<br />\n", $check_message) . "<br />\n";
|
||||||
}
|
}
|
||||||
|
// Clear first, to prevent request from being collected if the result is the same
|
||||||
|
$template->setElementAttribute('preview', 'value', '');
|
||||||
if($content['dry-run'])
|
if($content['dry-run'])
|
||||||
{
|
{
|
||||||
$preview = $this->preview($plugin, $file, $definition_obj);
|
$preview = $this->preview($plugin, $file, $definition_obj);
|
||||||
|
|
||||||
$template->setElementAttribute('message', 'value', $this->message);
|
$template->setElementAttribute('message', 'value', $this->message);
|
||||||
|
|
||||||
// Clear first, to prevent request from being collected if the result is the same
|
|
||||||
$template->setElementAttribute('preview', 'value', '');
|
|
||||||
$template->setElementAttribute('preview', 'value', $preview);
|
$template->setElementAttribute('preview', 'value', $preview);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Set up feedback area
|
||||||
|
$this->feedback($template, $content['definition'] . ': ' . $content['file']['name']);
|
||||||
|
|
||||||
// Disable push so we don't overload or spend time notifying
|
// Disable push so we don't overload or spend time notifying
|
||||||
EGroupware\Swoolepush\Hooks::pushDisabled(true);
|
EGroupware\Swoolepush\Hooks::pushDisabled(true);
|
||||||
|
|
||||||
@ -157,9 +159,9 @@ use EGroupware\Api\Etemplate;
|
|||||||
$count = $plugin->import($file, $definition_obj);
|
$count = $plugin->import($file, $definition_obj);
|
||||||
|
|
||||||
EGroupware\Swoolepush\Hooks::pushDisabled(false);
|
EGroupware\Swoolepush\Hooks::pushDisabled(false);
|
||||||
|
|
||||||
// Close preview
|
// Don't close progress, leave it open so they can see
|
||||||
EGroupware\Api\Json\Response::get()->call('app.importexport.closePreview');
|
//static::sendUpdate(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -180,21 +182,24 @@ use EGroupware\Api\Etemplate;
|
|||||||
}
|
}
|
||||||
$total_processed = 0;
|
$total_processed = 0;
|
||||||
foreach($plugin->get_results() as $action => $a_count) {
|
foreach($plugin->get_results() as $action => $a_count) {
|
||||||
$this->message .= "<br />\n" . lang($action) . ": $a_count";
|
$this->message .= "\n" . lang($action) . ": $a_count";
|
||||||
$total_processed += $a_count;
|
$total_processed += $a_count;
|
||||||
}
|
}
|
||||||
if(count($plugin->get_warnings())) {
|
if(count($plugin->get_warnings())) {
|
||||||
$this->message .= "<br />\n".lang('Warnings').':';
|
$this->message .= "\n" . lang('Warnings') . ':';
|
||||||
foreach($plugin->get_warnings() as $record => $message) {
|
foreach($plugin->get_warnings() as $record => $message) {
|
||||||
$this->message .= "<br />\n$record: $message";
|
$this->message .= "\n$record: $message";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count($plugin->get_errors())) {
|
if(count($plugin->get_errors())) {
|
||||||
$this->message .= "<br />\n".lang('Problems during import:');
|
$this->message .= "\n" . lang('Problems during import:');
|
||||||
foreach($plugin->get_errors() as $record => $message) {
|
foreach($plugin->get_errors() as $record => $message) {
|
||||||
$this->message .= "<br />\n$record: $message";
|
$this->message .= "\n$record: $message";
|
||||||
|
}
|
||||||
|
if($count != $total_processed)
|
||||||
|
{
|
||||||
|
$this->message .= "\n" . lang('Some records may not have been imported');
|
||||||
}
|
}
|
||||||
if($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
|
|
||||||
}
|
}
|
||||||
if ($dst_file && $content['file']['tmp_name'] == $dst_file) {
|
if ($dst_file && $content['file']['tmp_name'] == $dst_file) {
|
||||||
// Remove file
|
// Remove file
|
||||||
@ -207,6 +212,11 @@ use EGroupware\Api\Etemplate;
|
|||||||
$this->message .= lang('Database error');
|
$this->message .= lang('Database error');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->message .= $e->getMessage();
|
$this->message .= $e->getMessage();
|
||||||
|
$this->sendUpdate(false, get_class($e), $e->getMessage());
|
||||||
|
}
|
||||||
|
if($file && !$content['dry-run'] && $count)
|
||||||
|
{
|
||||||
|
static::sendUpdate(100, lang('%1 records processed', $count), $this->message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif($content['cancel'])
|
elseif($content['cancel'])
|
||||||
@ -379,6 +389,52 @@ use EGroupware\Api\Etemplate;
|
|||||||
return '<div class="header">' . lang('Preview') . ' - ' . $plugin->get_name() . '</div>' . $preview;
|
return '<div class="header">' . lang('Preview') . ' - ' . $plugin->get_name() . '</div>' . $preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup progress feedback area
|
||||||
|
* This includes sending the response, but not returning. Progress is sent via Push.
|
||||||
|
*/
|
||||||
|
protected function feedback($template, $title)
|
||||||
|
{
|
||||||
|
$template->setElementAttribute('progress_title', 'value', $title);
|
||||||
|
EGroupware\Api\Json\Response::get()->call('app.importexport.progressUpdate', false);
|
||||||
|
// Send response
|
||||||
|
EGroupware\Api\Json\Response::sendResult();
|
||||||
|
@ob_flush();
|
||||||
|
flush();
|
||||||
|
fastcgi_finish_request();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send some feedback to the client about how the import is going
|
||||||
|
*
|
||||||
|
* @param $complete numeric | null Send null to close the progress
|
||||||
|
* @param $label
|
||||||
|
* @param $log
|
||||||
|
* @return void
|
||||||
|
* @throws Api\Json\Exception
|
||||||
|
*/
|
||||||
|
public static function sendUpdate($complete, $label = '', $log = '')
|
||||||
|
{ // No real push, no updates
|
||||||
|
if(EGroupware\Api\Json\Push::onlyFallback())
|
||||||
|
{
|
||||||
|
error_log($complete . "% $label\t" . $log);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$update = [
|
||||||
|
'progress' => $complete,
|
||||||
|
'label' => $label,
|
||||||
|
'log' => $log
|
||||||
|
];
|
||||||
|
// Close the progress
|
||||||
|
if($complete === null)
|
||||||
|
{
|
||||||
|
$update = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$p = new Api\Json\Push();
|
||||||
|
$p->call('app.importexport.progressUpdate', $update);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple check to see if the file at least matches the definition
|
* Simple check to see if the file at least matches the definition
|
||||||
*
|
*
|
||||||
|
@ -74,6 +74,13 @@ class ImportExportApp extends EgwApp
|
|||||||
jQuery('div.filters').hide();
|
jQuery('div.filters').hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(_name == "importexport.import_dialog")
|
||||||
|
{
|
||||||
|
// Store popup so we can find it from parent
|
||||||
|
// Using _name only allows one import (at a time) to be updated
|
||||||
|
this.egw.window.name = _name;
|
||||||
|
this.egw.window.opener.egw.storeWindow(this.appname, this.egw.window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,6 +156,70 @@ class ImportExportApp extends EgwApp
|
|||||||
preview.parent().hide();
|
preview.parent().hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressUpdate(progress : ProgressUpdate)
|
||||||
|
{
|
||||||
|
const dialog = window.open('', "importexport.import_dialog");
|
||||||
|
|
||||||
|
if(!dialog || !dialog.app?.importexport?.et2)
|
||||||
|
{
|
||||||
|
this.egw.message(this.egw.lang("Lost the dialog, no progress updates"), "warning");
|
||||||
|
if(dialog)
|
||||||
|
{
|
||||||
|
dialog.close();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Find the template in the dialog and do the update there
|
||||||
|
const et2 = dialog.app.importexport.et2;
|
||||||
|
if(progress !== null)
|
||||||
|
{
|
||||||
|
dialog.app.importexport._doProgressUpdate(progress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dialog.app.importexport._closeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_doProgressUpdate(progress : ProgressUpdate)
|
||||||
|
{
|
||||||
|
const progress_box = this.et2.getDOMWidgetById("progress_box")
|
||||||
|
progress_box.classList.remove("hideme");
|
||||||
|
// Get the td too
|
||||||
|
progress_box.parentNode.classList.remove("hideme");
|
||||||
|
const preview_box = this.et2.getDOMWidgetById("preview_box").parentNode
|
||||||
|
preview_box.classList.add("hideme");
|
||||||
|
|
||||||
|
const record = progress_box.getWidgetById("progress_record");
|
||||||
|
record.value = progress.label || "";
|
||||||
|
|
||||||
|
// sl-progress-bar is not an etemplate widget and chokes the server processing if we put it in the xet
|
||||||
|
let bar = progress_box.querySelector("sl-progress-bar");
|
||||||
|
if(!bar)
|
||||||
|
{
|
||||||
|
bar = document.createElement("sl-progress-bar");
|
||||||
|
progress_box.insertBefore(bar, record.nextSibling);
|
||||||
|
}
|
||||||
|
|
||||||
|
bar.indeterminate = !Number.isInteger(progress.progress);
|
||||||
|
bar.value = progress.progress || 0;
|
||||||
|
|
||||||
|
if(progress.log)
|
||||||
|
{
|
||||||
|
const log = this.et2.getDOMWidgetById("import_log")
|
||||||
|
log.value = log.value + "\n" + progress.log;
|
||||||
|
// Try to scroll to bottom
|
||||||
|
const text = log.shadowRoot.querySelector("textarea");
|
||||||
|
text.scrollTop = text.scrollHeight + 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_closeProgress()
|
||||||
|
{
|
||||||
|
const progress_box = this.et2.getDOMWidgetById("progress_box")
|
||||||
|
progress_box.parentNode.classList.add("hideme");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a popup to run a given definition
|
* Open a popup to run a given definition
|
||||||
*
|
*
|
||||||
@ -242,3 +313,13 @@ class ImportExportApp extends EgwApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.classes.importexport = ImportExportApp;
|
app.classes.importexport = ImportExportApp;
|
||||||
|
|
||||||
|
interface ProgressUpdate
|
||||||
|
{
|
||||||
|
// Update the progress bar
|
||||||
|
progress : number | false;
|
||||||
|
// Set label in progress bar
|
||||||
|
label? : string;
|
||||||
|
// Add something to the log
|
||||||
|
log? : string;
|
||||||
|
}
|
||||||
|
@ -1,21 +1,34 @@
|
|||||||
.preview {
|
.preview, .import_progress {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
width: 97%;
|
width: 97%;
|
||||||
height: 95%;
|
height: 95%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
display: none;
|
display: none;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview .content {
|
.import_progress {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not sure why these are missing */
|
||||||
|
.import_progress sl-progress-bar {
|
||||||
|
--track-color: hsl(240 5.9% 90%);
|
||||||
|
--indicator-color: hsl(200.4 98% 39.4%);
|
||||||
|
--label-color: var(--label-color);
|
||||||
|
--sl-border-radius-pill: 9999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview .content, .import_progress .log {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
max-height: 99%;
|
max-height: 99%;
|
||||||
display: block;
|
display: block;
|
||||||
|
flex: 1 1 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview_box .header, .preview .header {
|
.preview_box .header, .preview .header {
|
||||||
@ -30,7 +43,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.preview [id$='buttons'] {
|
.preview [id$='buttons'] {
|
||||||
margin-left: 50%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.wizard_content > div > table {
|
.wizard_content > div > table {
|
||||||
|
@ -52,7 +52,17 @@
|
|||||||
<et2-button align="center" label="OK" onclick="jQuery(this).parents('.preview').css('display','none'); return false;" noSubmit="true"></et2-button>
|
<et2-button align="center" label="OK" onclick="jQuery(this).parents('.preview').css('display','none'); return false;" noSubmit="true"></et2-button>
|
||||||
</et2-box>
|
</et2-box>
|
||||||
</et2-vbox>
|
</et2-vbox>
|
||||||
<et2-description></et2-description>
|
</row>
|
||||||
|
<row>
|
||||||
|
<et2-vbox id="progress_box" span="all" class="import_progress hideme">
|
||||||
|
<et2-description id="progress_title"></et2-description>
|
||||||
|
<et2-description id="progress_record"></et2-description>
|
||||||
|
<!--<sl-progress-bar id="progress" indeterminate="true"></sl-progress-bar>-->
|
||||||
|
<et2-box class="log">
|
||||||
|
<et2-textarea id="import_log"></et2-textarea>
|
||||||
|
</et2-box>
|
||||||
|
<et2-button label="OK" onclick="app.importexport._closeProgress"></et2-button>
|
||||||
|
</et2-vbox>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<et2-hbox span="all">
|
<et2-hbox span="all">
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
* @package projectmanager
|
* @package projectmanager
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
.preview {
|
.preview,
|
||||||
|
.import_progress {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
@ -24,10 +25,22 @@
|
|||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
margin: 1.5%;
|
margin: 1.5%;
|
||||||
}
|
}
|
||||||
.preview .content {
|
.import_progress {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
/* Not sure why these are missing */
|
||||||
|
.import_progress sl-progress-bar {
|
||||||
|
--track-color: hsl(240, 5.9%, 90%);
|
||||||
|
--indicator-color: hsl(200.4, 98%, 39.4%);
|
||||||
|
--label-color: var(--label-color);
|
||||||
|
--sl-border-radius-pill: 9999px;
|
||||||
|
}
|
||||||
|
.preview .content,
|
||||||
|
.import_progress .log {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
max-height: 99%;
|
max-height: 99%;
|
||||||
display: block;
|
display: block;
|
||||||
|
flex: 1 1 auto;
|
||||||
}
|
}
|
||||||
.preview_box .header,
|
.preview_box .header,
|
||||||
.preview .header {
|
.preview .header {
|
||||||
@ -39,9 +52,6 @@
|
|||||||
.preview tr {
|
.preview tr {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
.preview [id$='buttons'] {
|
|
||||||
margin-left: 50%;
|
|
||||||
}
|
|
||||||
.wizard_content > div > table {
|
.wizard_content > div > table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user