Commit 065cfa3d authored by Robert Rollins's avatar Robert Rollins

Issue [#2098051]: UIDs are now persistent across multiple retrievals of the ical feed.

The previous fix that I applied for issue #2070883 was the complete wrong way to
go about fixing that problem, because it introduced a new, much more sinister
issue: the UID for an event would change every time the iCal feed got downloaded.

According to the spec, the UID is supposed to be persistent, so I re-engineered
the algoithm that creates UIDs for the Fields plugin so it will create the same
UIDs as the Entity plugin does.
parent 0ec0fc57
......@@ -319,10 +319,9 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event['location'] = $location;
}
// Generate a unique ID for this event.
$domain = check_plain($_SERVER['SERVER_NAME']);
$uniqid = uniqid(rand(), true);
$event['uid'] = "date_ical.$uniqid@$domain";
// For this event's UID, use either the date_id generated by the Date module, or the
// event page's URL, if the date_id isn't available.
$event['uid'] = !empty($entity->date_id) ? $entity->date_id[0] : $event['url'];
// If we are using a repeat rule (and not just multi-day events)
// we remove the item from the entities.
......
......@@ -109,6 +109,8 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
$date = $this->get_row_date($row_index);
}
catch (BlankDateFieldException $e) {
// Unless the user has specifically said that they want to skip rows which
// have blank dates, let this exception percolate.
if ($this->options['additional_settings']['skip_blank_dates']) {
return NULL;
}
......@@ -117,7 +119,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
}
}
$event = array();
// Create the event by starting with the date array from this row.
$event = $date;
// Add the LAST-MODIFIED and URL components based on the original entity.
$entity = $row->_field_data[$this->view->base_field]['entity'];
$entity_type = $row->_field_data[$this->view->base_field]['entity_type'];
......@@ -128,12 +132,30 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
$uri['options']['absolute'] = TRUE;
$event['url'] = url($uri['path'], $uri['options']);
// Generate a unique ID for this event.
// Generate a unique ID for this event by emulating the way the Date module
// creates a Date ID.
if (isset($row->{"field_data_{$this->options['date_field']}_delta"})) {
$date_field_delta = $row->{"field_data_{$this->options['date_field']}_delta"};
}
else {
// I'm not sure why the "field_data_<field_name>_delta" field is part of
// the $row, so it's possible that it will sometimes be missing. If it
// is, make an educated guess about the delta by comparing this row's
// start date to each of the entity's dates.
$date_field_delta = 0;
foreach ($entity->{$this->options['date_field']}['und'] as $ndx => $date_array) {
if ($date['start']->originalTime == $date_array['value']) {
$date_field_delta = $ndx;
break;
}
}
}
$entity_id = $row->{$this->view->base_field};
$date_field_name = $this->options['date_field'];
$domain = check_plain($_SERVER['SERVER_NAME']);
$uniqid = uniqid(rand(), true);
$event['uid'] = "date_ical.$uniqid@$domain";
$event['uid'] = "calendar.$entity_id.$date_field_name.$date_field_delta@$domain";
// Create the primary text fields.
// Retrieve the rendered text fields.
$text_fields['summary'] = $this->get_field($row_index, $this->options['title_field']);
$text_fields['description'] = $this->get_field($row_index, $this->options['description_field']);
$text_fields['location'] = $this->get_field($row_index, $this->options['location_field']);
......@@ -155,9 +177,6 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
$event['location'] = date_ical_sanitize_text(strip_tags($text_fields['location']));
$event['description'] = date_ical_sanitize_text($text_fields['description']);
// Add the date data.
$event = array_merge($event, $date);
// Allow other modules to alter the event object, before it gets passed to
// the style plugin to be converted into an iCal VEVENT.
$context = array(
......@@ -182,15 +201,15 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
* The normalized array.
*/
function get_row_date($row_index) {
// Fetch the date field value.
$date_field_value = $this->view->style_plugin->get_field_value($row_index, $this->options['date_field']);
$start = NULL;
$end = NULL;
$rrule = NULL;
$delta = 0;
$is_date_field = FALSE;
// Fetch the date field value.
$date_field_value = $this->view->style_plugin->get_field_value($row_index, $this->options['date_field']);
// Handle date fields.
if (isset($date_field_value[$delta]) && is_array($date_field_value[$delta])) {
$is_date_field = TRUE;
......
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