Commit 93511808 authored by Robert Rollins's avatar Robert Rollins

Issue #2179435: You can now skip importing events more than X days old.

There's a new setting on the "iCal parser" settings page, which lets you set
an integer number of days. Events which ended more than that number of days
before the import will be skipped.
parent 73995cff
......@@ -75,6 +75,7 @@ class DateiCalFeedsParser extends FeedsParser {
return array(
'indefinite_count' => $this->config['indefinite_count'],
'until_not_utc' => $this->config['until_not_utc'],
'skip_days' => $this->config['skip_days'],
);
}
......@@ -85,6 +86,7 @@ class DateiCalFeedsParser extends FeedsParser {
return array(
'indefinite_count' => '52',
'until_not_utc' => FALSE,
'skip_days' => NULL,
);
}
......@@ -108,14 +110,35 @@ class DateiCalFeedsParser extends FeedsParser {
$form['until_not_utc'] = array(
'#title' => t('RRULE UNTILs are not in UTC'),
'#type' => 'checkbox',
'#description' => t('Enable this setting if you\'re seeing reccuring events lose or gain repeat(s) at the end. ' .
'#description' => t('Enable this setting if your reccuring events are not repeating the correct number of times. ' .
'The iCal spec requires that the UNTIL value in an RRULE be specified in UTC, but some iCal feed creators fail to do this ' .
'(the UNTIL values in the feed\'s RRULEs don\'t end is "Z"). This causes the UNTIL value to be off by several hours.'),
'(the UNTIL values in those feeds\' RRULEs don\'t end is "Z"). This causes the UNTIL value to be off by several hours, ' .
'which can cause the repeat calculator to miss or add repeats.'),
'#default_value' => $this->config['until_not_utc'],
);
$form['skip_days'] = array(
'#title' => t('Skip events more than X days old'),
'#type' => 'textfield',
'#size' => 5,
'#description' => t('Set this value to any positive integer (or 0) to skip events which ended more than that many days before the import. ' .
'Leave it blank to import all events.'),
'#default_value' => $this->config['skip_days'],
);
return $form;
}
/**
* Validation handler for configForm.
*/
public function configFormValidate(&$source_config) {
if (!preg_match('/^\d+$/', $source_config['skip_days']) && $source_config['skip_days'] !== '') {
form_set_error('skip_days', 'You must enter a positive integer.');
}
if ($source_config['skip_days'] === '') {
$source_config['skip_days'] = NULL;
}
}
/**
* Creates the list of mapping sources offered by DateiCalFeedsParser.
*/
......
......@@ -153,7 +153,10 @@ class ParserVcalendar {
// Feeds processor.
drupal_alter('date_ical_import_post_parse', $this->parsed_data, $context2);
// Skip this event if it's earlier than the user's specified skip time.
if (!$this->_skip_current_event()) {
$events[] = $this->parsed_data;
}
// The indices of the original $raw_components array are preserved in
// $batch, so using the $ndx value here lets us communicate our progress
// through the full collection of components.
......@@ -474,4 +477,18 @@ class ParserVcalendar {
}
return $datetimezone;
}
/**
* Internal helper function for skipping old events.
*/
protected function _skip_current_event() {
// Must use !isset() here, because 0 and NULL mean different things.
if (!isset($this->config['skip_days'])) {
return FALSE;
}
$compare_date = isset($this->parsed_data['DTEND']) ? $this->parsed_data['DTEND'] : $this->parsed_data['DTSTART'];
$skip_date = new FeedsDateTime("today -{$this->config['skip_days']} days", $compare_date->getTimezone());
$skip = ($skip_date > $compare_date);
return $skip;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment