Abort import if more than 100 errors are encountered.

Prevents request from dying if you upload a large, bad, file
This commit is contained in:
Nathan Gray 2014-05-05 20:30:06 +00:00
parent 4053d1a204
commit f5dc2d6903

View File

@ -87,6 +87,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
*/
protected $user = null;
/**
* Maximum number of errors or warnings before aborting
*/
const MAX_MESSAGES = 100;
/**
* List of import errors
*/
@ -157,7 +162,7 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
$warning = importexport_import_csv::convert($record, $record_class::$types, $app, $this->lookups, $_definition->plugin_options['convert']);
if($warning) $this->warnings[$import_csv->get_current_position()] = $warning;
if($warning) $this->warnings[$import_csv->get_current_position()] = $warning;
$egw_record = new $record_class();
$egw_record->set_record($record);
@ -170,6 +175,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
{
$this->preview_records[] = $egw_record;
}
if(count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES)
{
$this->errors[] = 'Too many errors, aborted';
break;
}
}
return $count;
}
@ -298,12 +308,14 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
// Set up HTML
$rows['h1'] = $labels;
error_log("Wow, ".count($this->preview_records) . ' preveiw records');
foreach($this->preview_records as $i => $row_data)
{
// Convert to human-friendly
importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups);
$rows[] = $row_data->get_record_array();
}
$this->preview_records = array();
return html::table($rows);
}