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; protected $user = null;
/**
* Maximum number of errors or warnings before aborting
*/
const MAX_MESSAGES = 100;
/** /**
* List of import errors * List of import errors
*/ */
@ -170,6 +175,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
{ {
$this->preview_records[] = $egw_record; $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; return $count;
} }
@ -298,12 +308,14 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
// Set up HTML // Set up HTML
$rows['h1'] = $labels; $rows['h1'] = $labels;
error_log("Wow, ".count($this->preview_records) . ' preveiw records');
foreach($this->preview_records as $i => $row_data) foreach($this->preview_records as $i => $row_data)
{ {
// Convert to human-friendly // Convert to human-friendly
importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups); importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups);
$rows[] = $row_data->get_record_array(); $rows[] = $row_data->get_record_array();
} }
$this->preview_records = array();
return html::table($rows); return html::table($rows);
} }