Use new ical parser iterator to import large files and avoid htp connection timeouts

This commit is contained in:
Thomas Bruederli 2013-10-17 14:32:50 +02:00
parent 7af1dda119
commit 8039a2f6e5
2 changed files with 18 additions and 12 deletions

View file

@ -968,7 +968,7 @@ class calendar extends rcube_plugin
rcube_upload_progress();
}
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
@set_time_limit(0);
// process uploaded file if there is no error
$err = $_FILES['_data']['error'];
@ -976,22 +976,23 @@ class calendar extends rcube_plugin
if (!$err && $_FILES['_data']['tmp_name']) {
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
$rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
$count = $errors = 0;
$user_email = $this->rc->user->get_username();
try {
$events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name'], 'UTF-8', true);
}
catch (Exception $e) {
$errors = 1;
$msg = $e->getMessage();
$events = array();
}
$ical = $this->get_ical();
$errors = !$ical->fopen($_FILES['_data']['tmp_name']);
$count = $i = 0;
foreach ($ical as $event) {
// keep the browser connection alive on long import jobs
if (++$i > 100 && $i % 100 == 0) {
echo "<!-- -->";
ob_flush();
}
foreach ($events as $event) {
// TODO: correctly handle recurring events which start before $rangestart
if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)))
continue;
$event['_owner'] = $user_email;
$event['calendar'] = $calendar;
if ($this->driver->new_event($event)) {
$count++;

View file

@ -1970,10 +1970,15 @@ function rcube_calendar_ui(settings)
rcmail.display_message(rcmail.get_label('importerror', 'calendar'), 'error');
});
// display upload indicator
// display upload indicator (with extended timeout)
var timeout = rcmail.env.request_timeout;
rcmail.env.request_timeout = 600;
me.import_succeeded = null;
me.saving_lock = rcmail.set_busy(true, 'uploading');
$('.ui-dialog-buttonpane button', $dialog.parent()).button('disable');
// restore settings
rcmail.env.request_timeout = timeout;
}
};