| Commit | Line | Data |
|---|---|---|
| bcee876d | 1 | <?php |
| bcee876d | 2 | |
| 30ba3a78 | 3 | /** |
| dd1d80c1 AN |
4 | * @file |
| 5 | * Install file for FeedAPI module. | |
| 6 | */ | |
| 7 | ||
| 8 | /** | |
| 9ca34887 | 9 | * Implementation of hook_schema(). |
| 25a3b58b AN |
10 | */ |
| 11 | function feedapi_schema() { | |
| 12 | $schema['feedapi'] = array( | |
| 4f95f0ab | 13 | 'description' => 'Stores feed-related info for each feed', |
| 25a3b58b AN |
14 | 'fields' => array( |
| 15 | 'nid' => array( | |
| 4f95f0ab | 16 | 'description' => 'The node identifier where the feed belongs.', |
| 348a079d AN |
17 | 'type' => 'int', |
| 18 | 'unsigned' => TRUE, | |
| 19 | 'not null' => TRUE), | |
| 20 | 'vid' => array( | |
| 4f95f0ab | 21 | 'description' => 'The primary identifier for the feed.', |
| 25a3b58b AN |
22 | 'type' => 'int', |
| 23 | 'unsigned' => TRUE, | |
| 24 | 'not null' => TRUE), | |
| 25 | 'url' => array( | |
| 4f95f0ab | 26 | 'description' => 'The URL of the feed', |
| 9ee3d054 | 27 | 'type' => 'text', |
| d9ee1997 | 28 | 'not null' => TRUE), |
| 25a3b58b | 29 | 'feed_type' => array( |
| 335970c3 | 30 | 'description' => 'Type of feed', |
| 25a3b58b AN |
31 | 'type' => 'varchar', |
| 32 | 'not null' => TRUE, | |
| 33 | 'default' => 'XML feed', | |
| 34 | 'length' => '50'), | |
| 35 | 'processors' => array( | |
| 335970c3 | 36 | 'description' => 'List of enabled processors', |
| 25a3b58b AN |
37 | 'type' => 'varchar', |
| 38 | 'not null' => TRUE, | |
| 39 | 'default' => '', | |
| 40 | 'length' => '255'), | |
| 41 | 'parsers' => array( | |
| 335970c3 | 42 | 'description' => 'List of enabled parsers', |
| 25a3b58b AN |
43 | 'type' => 'varchar', |
| 44 | 'not null' => TRUE, | |
| 45 | 'default' => '', | |
| 46 | 'length' => '255'), | |
| e9545db8 | 47 | 'next_refresh_time' => array( |
| 335970c3 | 48 | 'description' => 'Timestamp of the earliest possible next refresh time', |
| 25a3b58b | 49 | 'type' => 'int', |
| 42ec78cc | 50 | 'unsigned' => FALSE, |
| 8bde2d6d | 51 | 'default' => 0, |
| 25a3b58b AN |
52 | 'not null' => TRUE), |
| 53 | 'hash' => array( | |
| 335970c3 | 54 | 'description' => 'Hash of the feed content', |
| 25a3b58b AN |
55 | 'type' => 'varchar', |
| 56 | 'length' => '32'), | |
| 25a3b58b | 57 | 'link' => array( |
| 335970c3 | 58 | 'description' => 'URL of the source site of the feed', |
| 9ee3d054 | 59 | 'type' => 'text'), |
| 25a3b58b | 60 | 'settings' => array( |
| 335970c3 | 61 | 'description' => 'Various settings of the feed', |
| 25a3b58b AN |
62 | 'type' => 'text', |
| 63 | 'size' => 'big'), | |
| 64 | 'half_done' => array( | |
| 335970c3 | 65 | 'description' => 'Indicates if not all of the feed items were processed at the last cron run', |
| 25a3b58b AN |
66 | 'type' => 'int', |
| 67 | 'size' => 'tiny'), | |
| 68 | ), | |
| 6e62fa05 | 69 | 'primary key' => array('vid', 'nid'), |
| 14f9ba3c | 70 | 'indexes' => array( |
| 6e62fa05 | 71 | 'vid' => array('vid'), |
| e9545db8 | 72 | 'next_refresh_time' => array('next_refresh_time')), |
| 25a3b58b AN |
73 | ); |
| 74 | $schema['feedapi_stat'] = array( | |
| 4f95f0ab | 75 | 'description' => 'Statistics values over the time about the feeds', |
| 25a3b58b AN |
76 | 'fields' => array( |
| 77 | 'id' => array( | |
| 335970c3 | 78 | 'description' => 'Unique identifier for statistics data', |
| 25a3b58b AN |
79 | 'type' => 'int', |
| 80 | 'not null' => TRUE, | |
| 81 | 'default' => 0), | |
| 82 | 'type' => array( | |
| 335970c3 | 83 | 'description' => 'Type of the data', |
| 25a3b58b AN |
84 | 'type' => 'varchar', |
| 85 | 'length' => 64, | |
| 86 | 'not null' => TRUE), | |
| 87 | 'timestamp' => array( | |
| 335970c3 | 88 | 'description' => 'Timestamp of the data', |
| 25a3b58b AN |
89 | 'type' => 'int', |
| 90 | 'not null' => TRUE), | |
| 91 | 'time' => array( | |
| 335970c3 | 92 | 'description' => 'Time of the data', |
| 25a3b58b AN |
93 | 'type' => 'varchar', |
| 94 | 'length' => 20, | |
| 95 | 'not null' => TRUE), | |
| 96 | 'value' => array( | |
| 335970c3 | 97 | 'description' => 'Value of the data', |
| 25a3b58b AN |
98 | 'type' => 'int'), |
| 99 | ), | |
| 100 | 'indexes' => array( | |
| 101 | 'feedapi_stat_id' => array('id'), | |
| 102 | 'feedapi_stat_type' => array('type')), | |
| 103 | 'feedapi_stat_timestamp' => array('timestamp'), | |
| 104 | 'feedapi_stat_time' => array('time'), | |
| 105 | ); | |
| 106 | return $schema; | |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 9ca34887 | 110 | * Implementation of hook_install(). |
| 30ba3a78 | 111 | */ |
| bcee876d | 112 | function feedapi_install() { |
| 25a3b58b | 113 | drupal_install_schema('feedapi'); |
| 5b9d898b AN |
114 | // This value warrants that og, taxonomy and similar modules does their job before feedapi. This is important |
| 115 | // because of for example feedapi_inherit or whatever processor which needs a 3rd-party processed data. | |
| 116 | db_query("UPDATE {system} SET weight = 5 WHERE name = 'feedapi'"); | |
| dd1d80c1 | 117 | } |
| 4f95f0ab | 118 | |
| dd1d80c1 AN |
119 | /** |
| 120 | * Implementation of hook_uninstall(). | |
| 121 | */ | |
| 122 | function feedapi_uninstall() { | |
| 123 | drupal_uninstall_schema('feedapi'); | |
| 0aa46c53 | 124 | |
| aa0cf13b AN |
125 | // Delete variables site-wide |
| 126 | variable_del('feedapi_allowed_html_tags'); | |
| 127 | variable_del('feedapi_allow_html_all'); | |
| 128 | variable_del('feedapi_cron_percentage'); | |
| 129 | ||
| 130 | // Delete variables per-content-type | |
| 131 | $types = array_keys(node_get_types()); | |
| 132 | foreach ($types as $type) { | |
| 133 | variable_del('feedapi_settings_'. $type); | |
| 134 | } | |
| 61ad0e1d AN |
135 | } |
| 136 | ||
| 14f9ba3c AN |
137 | function feedapi_update_6101() { |
| 138 | $ret = array(); | |
| d5f9ceb6 | 139 | db_add_field($ret, 'feedapi', 'skip', array('type' => 'int', 'size' => 'tiny', 'default' => 0)); |
| 14f9ba3c AN |
140 | db_add_index($ret, 'feedapi', 'skip_id', array('skip')); |
| 141 | return $ret; | |
| 142 | } | |
| 143 | ||
| 144 | function feedapi_update_6102() { | |
| 145 | $ret = array(); | |
| 4f95f0ab | 146 | db_change_field($ret, 'feedapi', 'url', 'url', array('description' => 'The URL of the feed', 'type' => 'text')); |
| d9ee1997 | 147 | db_change_field($ret, 'feedapi', 'link', 'link', array('type' => 'text')); |
| 14f9ba3c AN |
148 | return $ret; |
| 149 | } | |
| cb31c19a AN |
150 | |
| 151 | /** | |
| 152 | * feedapi_access_op() was renamed to _feedapi_op_access(). | |
| 153 | * See #307853. | |
| 154 | */ | |
| 155 | function feedapi_update_6103() { | |
| 156 | menu_rebuild(); | |
| 157 | return array(); | |
| 158 | } | |
| ec0991d0 AN |
159 | |
| 160 | ||
| 161 | /** | |
| 162 | * Check out if the built-in content-type has an enabled parser. | |
| 163 | */ | |
| 164 | function feedapi_update_6104() { | |
| 165 | $default_processor = 'feed'; | |
| 166 | // Determine if the installation is affected | |
| 167 | $affected = FALSE; | |
| 168 | $settings = variable_get('feedapi_settings_'. $default_processor, FALSE); | |
| 169 | if (!isset($settings['parsers'])) { | |
| 170 | $affected = TRUE; | |
| 171 | } | |
| 172 | else { | |
| 173 | foreach ($settings['parsers'] as $parser => $setting) { | |
| 174 | if (!module_exists($parser) && $setting['enabled']) { | |
| 175 | $affected = TRUE; | |
| 176 | } | |
| 177 | } | |
| 178 | } | |
| 4f95f0ab | 179 | |
| ec0991d0 AN |
180 | if ($affected) { |
| 181 | // Set the parser of defaultly shipped processors if it's not done previously | |
| 182 | $parsers = module_implements('feedapi_feed'); | |
| 183 | if (count($parsers) > 0) { | |
| 184 | $set_processor = array("parsers" => array(array_pop($parsers) => array("enabled" => TRUE, "weight" => 0))); | |
| 185 | $settings = is_array($settings) ? array_merge($settings, $set_processor) : $set_processor; | |
| 186 | variable_set('feedapi_settings_'. $default_processor, $settings); | |
| 187 | } | |
| 188 | } | |
| 189 | return array(); | |
| 190 | } | |
| 348a079d AN |
191 | |
| 192 | /** | |
| 193 | * Adds vid to feedapi table | |
| 194 | */ | |
| 195 | function feedapi_update_6105() { | |
| 6e62fa05 | 196 | global $db_type; |
| 348a079d AN |
197 | $ret = array(); |
| 198 | db_add_field($ret, 'feedapi', 'vid', | |
| 199 | array( | |
| 4f95f0ab | 200 | 'description' => 'The primary identifier for the feed.', |
| 348a079d AN |
201 | 'type' => 'int', |
| 202 | 'unsigned' => TRUE, | |
| 6e62fa05 AN |
203 | 'not null' => TRUE, |
| 204 | 'default' => 0, | |
| 348a079d AN |
205 | ) |
| 206 | ); | |
| 207 | db_drop_primary_key($ret, 'feedapi'); | |
| 6e62fa05 | 208 | if ($db_type == 'mysql' || $db_type == 'mysqli') { |
| e202b969 | 209 | $ret[] = update_sql("UPDATE {feedapi} f, {node} n SET f.vid = n.vid WHERE n.nid = f.nid"); |
| 6e62fa05 AN |
210 | } |
| 211 | else { | |
| e202b969 | 212 | $ret[] = update_sql("UPDATE {feedapi} SET vid = n.vid FROM (SELECT vid, nid FROM {node} n) n WHERE n.nid = feedapi.nid"); |
| 6e62fa05 AN |
213 | } |
| 214 | $ret[] = update_sql("UPDATE {feedapi} SET vid = nid WHERE vid = 0"); | |
| 215 | db_add_primary_key($ret, 'feedapi', array('vid', 'nid')); | |
| 216 | db_add_index($ret, 'feedapi', 'vid', array('vid')); | |
| 348a079d AN |
217 | return $ret; |
| 218 | } | |
| e9545db8 AN |
219 | |
| 220 | /** | |
| 0aa46c53 | 221 | * Convert checked to next_refresh_time and consolidate skip and |
| e9545db8 AN |
222 | * next_refresh_time, add an index on next_refresh_time, make next_refresh_time |
| 223 | * unsigned. | |
| 224 | */ | |
| 225 | function feedapi_update_6106() { | |
| 226 | $spec = array( | |
| 227 | 'type' => 'int', | |
| 228 | 'unsigned' => TRUE, | |
| 229 | 'default' => 0, | |
| 230 | 'not null' => TRUE, | |
| 231 | ); | |
| 232 | db_change_field($ret, 'feedapi', 'checked', 'next_refresh_time', $spec); | |
| 233 | ||
| 234 | // Convert the value in next_refresh_time from the last time a feed has been | |
| 235 | // to the next time it should be checked. | |
| 236 | $ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = (next_refresh_time + '. FEEDAPI_CRON_DEFAULT_REFRESH_TIME .')'); | |
| 237 | ||
| 238 | // Set next_refresh_time to FEEDAPI_CRON_NEVER_REFRESH where skip = 1. | |
| 239 | $ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = '. FEEDAPI_CRON_NEVER_REFRESH .' WHERE skip = 1'); | |
| 240 | ||
| 241 | // Drop skip row | |
| 242 | db_drop_field($ret, 'feedapi', 'skip'); | |
| 243 | ||
| 244 | // Update all settings. | |
| 245 | $node_types = node_get_types('types'); | |
| 246 | ||
| 247 | // Update all node type settings. | |
| 248 | foreach ($node_types as $node_type) { | |
| 249 | if (feedapi_enabled_type($node_type)) { | |
| 250 | if ($settings = feedapi_get_settings($node_type)) { | |
| 251 | $settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME; | |
| 252 | unset($settings['skip']); | |
| 253 | _feedapi_store_settings(array('node_type' => $node_type), $settings); | |
| 254 | } | |
| 255 | } | |
| 256 | } | |
| 257 | ||
| 258 | // Update all node settings. | |
| 259 | $result = db_query('SELECT n.type, f.vid FROM {node} n JOIN {feedapi} f ON f.nid = n.nid'); | |
| 260 | while ($node = db_fetch_object($result)) { | |
| 261 | if ($settings = feedapi_get_settings($node->type, $node->vid)) { | |
| 262 | $settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME; | |
| 263 | unset($settings['skip']); | |
| 264 | _feedapi_store_settings(array('node_type' => $node->type, 'vid' => $node->vid), $settings); | |
| 265 | } | |
| 266 | } | |
| 267 | ||
| 268 | return $ret; | |
| 023a1fc9 AN |
269 | } |
| 270 | ||
| 42ec78cc AB |
271 | /** |
| 272 | * Convert refresh_time values to new constants | |
| 273 | * FEEDAPI_CRON_NEVER_REFRESH and FEEDAPI_CRON_ALWAYS_REFRESH. | |
| 274 | */ | |
| 275 | function feedapi_update_6107() { | |
| 276 | $ret = array(); | |
| 277 | // next_refresh_time can contain negative values now. | |
| 278 | $spec = array( | |
| 279 | 'type' => 'int', | |
| 280 | 'unsigned' => FALSE, | |
| 281 | 'default' => 0, | |
| 282 | 'not null' => TRUE, | |
| 283 | ); | |
| 284 | db_change_field($ret, 'feedapi', 'next_refresh_time', 'next_refresh_time', $spec); | |
| 285 | ||
| 286 | // Update all node type settings. | |
| 287 | $node_types = node_get_types('types'); | |
| 288 | foreach ($node_types as $node_type) { | |
| 289 | if (feedapi_enabled_type($node_type)) { | |
| 290 | if ($settings = feedapi_get_settings($node_type)) { | |
| 291 | if ($settings['refresh_time'] == 0 || $settings['refresh_time'] == 1) { | |
| 292 | $settings['refresh_time'] = ($settings['refresh_time'] == 0) ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_ALWAYS_REFRESH; | |
| 293 | _feedapi_store_settings(array('node_type' => $node_type), $settings); | |
| 294 | } | |
| 295 | } | |
| 296 | } | |
| 297 | } | |
| 298 | ||
| 299 | // Update all node settings. | |
| 300 | $result = db_query('SELECT n.type, f.vid FROM {node} n JOIN {feedapi} f ON f.nid = n.nid'); | |
| 301 | while ($node = db_fetch_object($result)) { | |
| 302 | if ($settings = feedapi_get_settings($node->type, $node->vid)) { | |
| 303 | if ($settings['refresh_time'] == 0 || $settings['refresh_time'] == 1) { | |
| 304 | $settings['refresh_time'] = ($settings['refresh_time'] == 0) ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_ALWAYS_REFRESH; | |
| 305 | _feedapi_store_settings(array('node_type' => $node->type, 'vid' => $node->vid), $settings); | |
| 306 | } | |
| 307 | } | |
| 308 | } | |
| 309 | return $ret; | |
| 310 | } |