date_ical.install 4.25 KB
Newer Older
Karen Stevenson's avatar
Karen Stevenson committed
1
2
3
4
5
6
7
<?php

/**
 * @file
 * Install, update and uninstall functions for the date_ical module.
 *
 */
8

Robert Rollins's avatar
Robert Rollins committed
9
10
11
12
13
/**
 * Implements hook_requirements().
 */
function date_ical_requirements($phase) {
  $requirements = array();
14
  
15
  // Ensure translations don't break at install time.
Robert Rollins's avatar
Robert Rollins committed
16
  $t = get_t();
17
  
Robert Rollins's avatar
Robert Rollins committed
18
19
  switch ($phase) {
    case 'runtime':
Robert Rollins's avatar
Robert Rollins committed
20
21
      $library = libraries_detect('iCalcreator');
      if ($library && !empty($library['installed'])) {
Robert Rollins's avatar
Robert Rollins committed
22
23
24
25
26
27
28
29
30
        $requirements['date_ical'] = array(
          'title' => $t('Date iCal'),
          'value' => $t('iCalcreator library is installed, version: @version found', array('@version' => $library['version'])),
          'severity' => REQUIREMENT_OK,
        );
      }
      else {
        $requirements['date_ical'] = array(
          'title' => $t('Date iCal'),
31
          'value' => $t('iCalcreator library could not be found, check the installation instructions for the Date iCal module.'),
Robert Rollins's avatar
Robert Rollins committed
32
33
34
          'description' => $t('The error message was: @error<br>!error_message',
            array('@error' => $library['error'], '!error_message' => $library['error message'])
          ),
Robert Rollins's avatar
Robert Rollins committed
35
36
37
38
39
          'severity' => REQUIREMENT_ERROR,
        );
      }
      break;
  }
40
  
Robert Rollins's avatar
Robert Rollins committed
41
42
43
44
  return $requirements;
}

/**
45
 * Implements of hook_enable().
Robert Rollins's avatar
Robert Rollins committed
46
47
48
49
 */
function date_ical_enable() {
  cache_clear_all('plugins:feeds:plugins', 'cache');
}
Robert Rollins's avatar
Robert Rollins committed
50
51
52
53
54
55
56

/*****************************************************************************
 *                              UPDATE HOOKS
 ****************************************************************************/

/**
 * Migrates all iCal feed importers for from Date iCal 2.x to 3.0.
57
 *
Robert Rollins's avatar
Robert Rollins committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 * <br>
 * PLEASE NOTE: If any of your importers are defined by Features, you'll need
 * to update their feature(s) to match.
 */
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);
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    $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) {
Robert Rollins's avatar
Robert Rollins committed
87
88
      $importer->setPlugin('DateiCalFeedsParser');
      
89
      // Source keys are now capitalized, so we need to update the mappings.
Robert Rollins's avatar
Robert Rollins committed
90
91
92
93
94
95
96
97
98
99
100
      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');
101
      foreach ($messages['warning'] as $warning) {
Robert Rollins's avatar
Robert Rollins committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
        // 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))
      );
    }
  }
}