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

/**
 * Implementation of hook_enable().
 */
function date_ical_enable() {
  cache_clear_all('plugins:feeds:plugins', 'cache');
}
Robert Rollins's avatar
Robert Rollins committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

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

/**
 * 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.
 */
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);
    $config = $importer->getConfig();
    if ($config['parser']['plugin_key'] == 'DateIcalIcalcreatorParser') {
      $importer->setPlugin('DateiCalFeedsParser');
      
      // Update the mappings: the source keys are now capitalized.
      $processor = $importer->processor;
      $processor_config = $processor->getconfig();
      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))
      );
    }
  }
}