1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Install, update and uninstall functions for the date_ical module.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_requirements().
|
9
|
*/
|
10
|
function date_ical_requirements($phase) {
|
11
|
$requirements = array();
|
12
|
|
13
|
// Ensure translations don't break at install time.
|
14
|
$t = get_t();
|
15
|
|
16
|
if ($phase == 'runtime') {
|
17
|
if (!function_exists('libraries_detect')) {
|
18
|
$requirements['date_ical'] = array(
|
19
|
'title' => $t('Date iCal'),
|
20
|
'value' => $t('Libraries module is not installed.'),
|
21
|
'description' => $t('Date iCal 2.x and above require the Libraries module. Please install it from !here.',
|
22
|
array('!here' => l('here', 'http://www.drupal.org/project/libraries'))
|
23
|
),
|
24
|
'severity' => REQUIREMENT_ERROR,
|
25
|
);
|
26
|
// Return immediately, since we can't even attempt to determine if iCalcreator is installed.
|
27
|
return $requirements;
|
28
|
}
|
29
|
|
30
|
$library = libraries_detect('iCalcreator');
|
31
|
if ($library && !empty($library['installed'])) {
|
32
|
$requirements['date_ical'] = array(
|
33
|
'title' => $t('Date iCal'),
|
34
|
'value' => $t('iCalcreator library is installed, version: @version found', array('@version' => $library['version'])),
|
35
|
'severity' => REQUIREMENT_OK,
|
36
|
);
|
37
|
}
|
38
|
else {
|
39
|
$requirements['date_ical'] = array(
|
40
|
'title' => $t('Date iCal'),
|
41
|
'value' => $t('iCalcreator library could not be found, check the installation instructions for the Date iCal module.'),
|
42
|
'description' => $t('The error message was: @error<br>!error_message',
|
43
|
array('@error' => $library['error'], '!error_message' => $library['error message'])
|
44
|
),
|
45
|
'severity' => REQUIREMENT_ERROR,
|
46
|
);
|
47
|
}
|
48
|
}
|
49
|
|
50
|
return $requirements;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Implements of hook_enable().
|
55
|
*/
|
56
|
function date_ical_enable() {
|
57
|
cache_clear_all('plugins:feeds:plugins', 'cache');
|
58
|
}
|
59
|
|
60
|
/*****************************************************************************
|
61
|
* UPDATE HOOKS
|
62
|
****************************************************************************/
|
63
|
|
64
|
/**
|
65
|
* Migrates all iCal feed importers for from Date iCal 2.x to 3.0.
|
66
|
*
|
67
|
* <br>
|
68
|
* PLEASE NOTE: If any of your importers are defined by Features, you'll need
|
69
|
* to update their feature(s) to match.
|
70
|
*/
|
71
|
function date_ical_update_7300() {
|
72
|
// Rebuild the registry immediately, so that we don't get fatal errors when
|
73
|
// Drupal attempts to instantiate the old feeds plugin classes.
|
74
|
registry_rebuild();
|
75
|
cache_clear_all('plugins:feeds:plugins', 'cache');
|
76
|
|
77
|
// Update all the importers which used DateIcalIcalcreatorParser to use
|
78
|
// DateiCalFeedsParser instead.
|
79
|
$importer_data = ctools_export_load_object('feeds_importer', 'all');
|
80
|
foreach ($importer_data as $key => $value) {
|
81
|
$importer = feeds_importer($key);
|
82
|
$importer_config = $importer->getConfig();
|
83
|
$needs_update = ($importer_config['parser']['plugin_key'] == 'DateIcalIcalcreatorParser');
|
84
|
|
85
|
$processor = $importer->processor;
|
86
|
$processor_config = $processor->getconfig();
|
87
|
// Also update importers which use the new parser, but have un-capitalized
|
88
|
// sources. This can happen if the user didn't run the update, and then
|
89
|
// manually fixed the warning they saw, without fixing their sources.
|
90
|
if ($importer_config['parser']['plugin_key'] == 'DateiCalFeedsParser'
|
91
|
&& !empty($processor_config['mappings'][0]['source'])) {
|
92
|
$needs_update = (strtoupper($processor_config['mappings'][0]['source']) != $processor_config['mappings'][0]['source']);
|
93
|
}
|
94
|
|
95
|
if ($needs_update) {
|
96
|
$importer->setPlugin('DateiCalFeedsParser');
|
97
|
|
98
|
// Source keys are now capitalized, so we need to update the mappings.
|
99
|
foreach ($processor_config['mappings'] as &$mapping) {
|
100
|
$mapping['source'] = strtoupper($mapping['source']);
|
101
|
}
|
102
|
$processor->setConfig($processor_config);
|
103
|
|
104
|
$importer->save();
|
105
|
|
106
|
// When this importer object got created, a warning was issued about its
|
107
|
// parser plugin being missing. We corrected that warning above, so we
|
108
|
// should clear it out to avoid potential confusion.
|
109
|
$messages = drupal_get_messages('warning');
|
110
|
foreach ($messages['warning'] as $warning) {
|
111
|
// Calling drupal_get_messages() removed *every* warning from the
|
112
|
// message queue, so we need to re-issue any warnings that aren't
|
113
|
// about missing Feeds plugins.
|
114
|
if (strpos($warning, 'Missing Feeds plugin') === FALSE) {
|
115
|
drupal_set_message($warning, 'warning');
|
116
|
}
|
117
|
}
|
118
|
$t = get_t();
|
119
|
$importer_link = l($key, "admin/structure/feeds/$key");
|
120
|
drupal_set_message($t('Date iCal updated the parser plugin for !importer.
|
121
|
If that importer is defined by a feature, you will need to update that feature to match.', array('!importer' => $importer_link))
|
122
|
);
|
123
|
}
|
124
|
}
|
125
|
}
|