Commit 73d42500 authored by Robert Rollins's avatar Robert Rollins

Implemented batch parsing. Improvements to the Date field parser.

iCal feeds are now parsed in batches of 50 (by default).

The Date parser code has been significantly improved, removing the
old limitation of needing to parse DTSTART first, and also covering
more edge cases and error conditions.
parent 05caebca
......@@ -178,10 +178,12 @@ function hook_date_ical_import_component_alter(&$component, $context) {
* Alter the timezone string from an imported iCal Feed.
*
* This is useful for when an iCal feed you're trying to import uses deprecated
* timezone names, like "Eastern Standard Time" rather than "America/New_York".
* timezone names, like "Eastern Standard Time" rather than "America/New_York",
* or has date values with missing timezone information.
*
* @param string $tzid
* The timezone id sting to be altered (e.g. "America/Los_Angeles").
* If this value is NULL, not timezone id was set in the feed.
* @param array $context
* An associative array of context, with the following keys and values:
* - 'property_key': The name of the property (e.g. DTSTART). Can be NULL.
......
......@@ -2,9 +2,7 @@
/**
* @file
* Classes implementing Date iCal's iCalcreator-based parser functionality.
*
* @TODO: Figure out how to parse VVENUE information.
* DateiCalFeedsParser is Date iCal's Feeds parser plugin.
*/
class DateiCalFeedsParser extends FeedsParser {
......@@ -23,6 +21,7 @@ class DateiCalFeedsParser extends FeedsParser {
if (!libraries_load('iCalcreator')) {
throw new DateIcalException(t('Unable to load the iCalcreator library. Please ensure that you have installed the library correctly.'));
}
$state = $source->state(FEEDS_PARSE);
// Read the iCal feed into memory.
$ical_feed_contents = $fetcher_result->getRaw();
......@@ -44,16 +43,28 @@ class DateiCalFeedsParser extends FeedsParser {
// We've got a vcalendar object created from the feed data. Now we need to
// convert that vcalendar into an array of Feeds-compatible data arrays.
// ParserVcalendar does this conversion.
// ParserVcalendar->parse() does that.
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc');
$source_config = $source->getConfigFor($this);
$parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source_config);
return new FeedsParserResult($parser->parse());
$parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this));
// Using either the stored progress pointer (or 0 if it's not set),
// determine which section of the feed to parse, then parse it.
$offset = isset($state->pointer) ? $state->pointer : 0;
$limit = $source->importer->getLimit();
$rows = $parser->parse($offset, $limit);
// Report progress.
$state->total = $parser->getTotalComponents();
// We need to add 1 to the index of the last parsed componenent so that
// the subsequent batch starts on the *next* component.
$state->pointer = $parser->getLastComponentParsed() + 1;
$state->progress($state->total, $state->pointer);
return new FeedsParserResult($rows);
}
/**
* Define our default configuration settings for when the user performs an
* import.
* Defines the default configuration settings for an actual import.
*/
public function sourceDefaults() {
return array(
......@@ -62,8 +73,7 @@ class DateiCalFeedsParser extends FeedsParser {
}
/**
* Define our default configuration settings for when the user visits the
* config page.
* Defines the default settings shown on the configuration form.
*/
public function configDefaults() {
return array(
......@@ -72,7 +82,7 @@ class DateiCalFeedsParser extends FeedsParser {
}
/**
* Build configuration form.
* Builds the configuration form.
*/
public function configForm(&$form_state) {
$form = array();
......@@ -97,10 +107,6 @@ class DateiCalFeedsParser extends FeedsParser {
* @return array
*/
public static function getiCalMappingSources() {
// NOTE TO MAINTAINERS:
// The order of these properties determines their parse order! Since we
// need to parse the DTSTART property before parsing DTEND, the DTSTART
// source *must* come before it in this function.
$sources = array();
$sources['SUMMARY'] = array(
'name' => t('Summary/Title'),
......
This diff is collapsed.
......@@ -120,7 +120,7 @@ BEGIN:VEVENT
SUMMARY:Event with escaped characters in DESCRIPTION
DTSTART;TZID=America/New_York:20131009T190000
DTEND;TZID=America/New_York:20131009T210000
UID:date_ical_basic_test0B
UID:date_ical_basic_test0C
DESCRIPTION:This event has several escaped characters right here:\,\;\\\n\NThis text should be 2 lines down from the rest.
END:VEVENT
......
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