You are here

function date_ical_update_7300 in Date iCal 7.3

Migrates all iCal feed importers for from Date iCal 2.x to 3.0.

<br> PLEASE NOTE: If any of your importers are defined by Features, you'll need to update their feature(s) to match.

File

./date_ical.install, line 71
Install, update and uninstall functions for the date_ical module.

Code

function date_ical_update_7300() {

  // Rebuild the registry immediately, so that we don't get fatal errors when
  // Drupal attempts to instantiate the old feeds plugin classes.
  registry_rebuild();
  cache_clear_all('plugins:feeds:plugins', 'cache');

  // Update all the importers which used DateIcalIcalcreatorParser to use
  // DateiCalFeedsParser instead.
  $importer_data = ctools_export_load_object('feeds_importer', 'all');
  foreach ($importer_data as $key => $value) {
    $importer = feeds_importer($key);
    $importer_config = $importer
      ->getConfig();
    $needs_update = $importer_config['parser']['plugin_key'] == 'DateIcalIcalcreatorParser';
    $processor = $importer->processor;
    $processor_config = $processor
      ->getconfig();

    // Also update importers which use the new parser, but have un-capitalized
    // sources. This can happen if the user didn't run the update, and then
    // manually fixed the warning they saw, without fixing their sources.
    if ($importer_config['parser']['plugin_key'] == 'DateiCalFeedsParser' && !empty($processor_config['mappings'][0]['source'])) {
      $needs_update = strtoupper($processor_config['mappings'][0]['source']) != $processor_config['mappings'][0]['source'];
    }
    if ($needs_update) {
      $importer
        ->setPlugin('DateiCalFeedsParser');

      // Source keys are now capitalized, so we need to update the mappings.
      foreach ($processor_config['mappings'] as &$mapping) {
        $mapping['source'] = strtoupper($mapping['source']);
      }
      $processor
        ->setConfig($processor_config);
      $importer
        ->save();

      // When this importer object got created, a warning was issued about its
      // parser plugin being missing. We corrected that warning above, so we
      // should clear it out to avoid potential confusion.
      $messages = drupal_get_messages('warning');
      foreach ($messages['warning'] as $warning) {

        // Calling drupal_get_messages() removed *every* warning from the
        // message queue, so we need to re-issue any warnings that aren't
        // about missing Feeds plugins.
        if (strpos($warning, 'Missing Feeds plugin') === FALSE) {
          drupal_set_message($warning, 'warning');
        }
      }
      $t = get_t();
      $importer_link = l($key, "admin/structure/feeds/{$key}");
      drupal_set_message($t('Date iCal updated the parser plugin for !importer.
        If that importer is defined by a feature, you will need to update that feature to match.', array(
        '!importer' => $importer_link,
      )));
    }
  }
}