Use new ical parser iterator to import large files and avoid htp connection timeouts
This commit is contained in:
parent
7af1dda119
commit
8039a2f6e5
2 changed files with 18 additions and 12 deletions
|
@ -968,7 +968,7 @@ class calendar extends rcube_plugin
|
||||||
rcube_upload_progress();
|
rcube_upload_progress();
|
||||||
}
|
}
|
||||||
|
|
||||||
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
|
@set_time_limit(0);
|
||||||
|
|
||||||
// process uploaded file if there is no error
|
// process uploaded file if there is no error
|
||||||
$err = $_FILES['_data']['error'];
|
$err = $_FILES['_data']['error'];
|
||||||
|
@ -976,22 +976,23 @@ class calendar extends rcube_plugin
|
||||||
if (!$err && $_FILES['_data']['tmp_name']) {
|
if (!$err && $_FILES['_data']['tmp_name']) {
|
||||||
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
|
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
|
||||||
$rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
|
$rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
|
||||||
$count = $errors = 0;
|
$user_email = $this->rc->user->get_username();
|
||||||
|
|
||||||
try {
|
$ical = $this->get_ical();
|
||||||
$events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name'], 'UTF-8', true);
|
$errors = !$ical->fopen($_FILES['_data']['tmp_name']);
|
||||||
}
|
$count = $i = 0;
|
||||||
catch (Exception $e) {
|
foreach ($ical as $event) {
|
||||||
$errors = 1;
|
// keep the browser connection alive on long import jobs
|
||||||
$msg = $e->getMessage();
|
if (++$i > 100 && $i % 100 == 0) {
|
||||||
$events = array();
|
echo "<!-- -->";
|
||||||
}
|
ob_flush();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($events as $event) {
|
|
||||||
// TODO: correctly handle recurring events which start before $rangestart
|
// TODO: correctly handle recurring events which start before $rangestart
|
||||||
if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)))
|
if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
$event['_owner'] = $user_email;
|
||||||
$event['calendar'] = $calendar;
|
$event['calendar'] = $calendar;
|
||||||
if ($this->driver->new_event($event)) {
|
if ($this->driver->new_event($event)) {
|
||||||
$count++;
|
$count++;
|
||||||
|
|
|
@ -1970,10 +1970,15 @@ function rcube_calendar_ui(settings)
|
||||||
rcmail.display_message(rcmail.get_label('importerror', 'calendar'), 'error');
|
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.import_succeeded = null;
|
||||||
me.saving_lock = rcmail.set_busy(true, 'uploading');
|
me.saving_lock = rcmail.set_busy(true, 'uploading');
|
||||||
$('.ui-dialog-buttonpane button', $dialog.parent()).button('disable');
|
$('.ui-dialog-buttonpane button', $dialog.parent()).button('disable');
|
||||||
|
|
||||||
|
// restore settings
|
||||||
|
rcmail.env.request_timeout = timeout;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue