* Import/export speed improvements

This commit is contained in:
Nathan Gray 2011-12-05 16:02:19 +00:00
parent 5898109a41
commit 25914c234c
2 changed files with 78 additions and 22 deletions

View File

@ -20,7 +20,7 @@ class infolog_egw_record implements importexport_iface_egw_record
{
private $identifier = '';
private $record = array();
private $bo;
private static $bo;
// Used in conversions
static $types = array(
@ -39,9 +39,9 @@ class infolog_egw_record implements importexport_iface_egw_record
*/
public function __construct( $_identifier='' ){
$this->identifier = $_identifier;
$this->bo = new infolog_bo();
if(self::$bo == null) self::$bo = new infolog_bo();
if($_identifier) {
$this->set_record($this->bo->read($this->identifier));
$this->set_record(self::$bo->read($this->identifier));
}
}
@ -96,14 +96,6 @@ class infolog_egw_record implements importexport_iface_egw_record
*/
public function set_record(array $_record){
$this->record = $_record;
// Check for linked project ID
$links = egw_link::get_links('infolog', $_record['info_id'], 'projectmanager');
foreach($links as $link_id => $app_id) {
$this->record['pm_id'] = $app_id;
$this->record['project'] = egw_link::title('projectmanager', $app_id);
break;
}
}
/**
@ -158,7 +150,6 @@ class infolog_egw_record implements importexport_iface_egw_record
*
*/
public function __destruct() {
unset ($this->bo);
}
} // end of egw_addressbook_record

View File

@ -28,30 +28,95 @@ class infolog_export_csv implements importexport_iface_export_plugin {
$bo = new infolog_bo();
$selection = array();
$query = array();
$cf_links = array();
$export_object = new importexport_export_csv($_stream, (array)$options);
$export_object->set_mapping($options['mapping']);
// do we need to query the cf's
foreach($options['mapping'] as $field => $map) {
if($field[0] == '#') $query['custom_fields'][] = $field;
if($field[0] == '#') {
$query['custom_fields'][] = $field;
if($GLOBALS['egw_info']['user']['apps'][$bo->customfields[substr($field,1)]['type']])
{
$cf_links[$field] = $bo->customfields[substr($field,1)]['type'];
}
}
}
if ($options['selection'] == 'search') {
$query = array_merge($GLOBALS['egw']->session->appsession('session_data','infolog'), $query);
$query['num_rows'] = -1; // all
$selection = $bo->search($query);
$ids = array();
switch($options['selection'])
{
case 'search':
$query = array_merge($GLOBALS['egw']->session->appsession('session_data','infolog'), $query);
// Fall through
case 'all':
$query['num_rows'] = 500;
$query['start'] = 0;
do {
$selection = $bo->search($query);
$ids = array_keys($selection);
// Pre-load any cfs that are links
$cf_preload = array();
foreach($cf_links as $field => $app) {
foreach($selection as &$row) {
if($row[$field]) $cf_preload[$app][] = $row[$field];
}
if($cf_preload[$app]){
$selects[$field] = egw_link::titles($app, $cf_preload[$app]);
error_log('Preload ' . $field . '['.$app . ']: ' . implode(',',$cf_preload[$app]));
}
}
$this->export_records($export_object, $options, $selection, $ids);
$query['start'] += $query['num_rows'];
} while($query['start'] < $query['total']);
return $export_object;
break;
default:
$ids = $selection = explode(',',$options['selection']);
$this->export_records($export_object, $options, $selection, $ids);
break;
}
elseif ( $options['selection'] == 'all' ) {
$query['num_rows'] = -1;
$selection = $bo->search($query);
} else {
$selection = explode(',',$options['selection']);
return $export_object;
}
protected function export_records(&$export_object, $options, &$selection, $ids = array())
{
// Pre-load links all at once
if($ids && $options['mapping']['info_link_id'])
{
$links = egw_link::get_links_multiple('infolog', $ids, true, '!'.egw_link::VFS_APPNAME);
foreach($links as $id => $link) {
if(!is_array($selection[$id])) break;
$selection[$id]['info_link_id'] = $link;
if($options['convert']) $selection[$id]['info_link_id'] = egw_link::title($link['app'], $link['id']);
}
}
// If exporting PM fields, pre-load them all at once
if($ids && ($options['mapping']['pm_id'] || $options['mapping']['project']))
{
$projects = egw_link::get_links_multiple('infolog', $ids, true, 'projectmanager');
foreach($projects as $id => $links)
{
if(!is_array($selection[$id])) break;
$selection[$id]['pm_id'] = current($links);
$selection[$id]['project'] = egw_link::title('projectmanager', $selection[$id]['pm_id']);
}
}
foreach ($selection as $_identifier) {
if(!is_array($_identifier)) {
$record = new infolog_egw_record($_identifier);
if($link = $links[$record->info_id]) $record->info_link_id = $options['convert'] ? egw_link::title($link['app'], $link['id']) : $link;
if($project = $projects[$record->info_id])
{
$record->pm_id = current($project);
$record->project = egw_link::title('projectmanager', $record->pm_id);
}
} else {
$record = new infolog_egw_record();
$record->set_record($_identifier);