Removing translation directories
[project/feedapi.git] / feedapi.install
1 <?php
2
3 /**
4 * @file
5 * Install file for FeedAPI module.
6 */
7
8 /**
9 * Implementation of hook_schema().
10 */
11 function feedapi_schema() {
12 $schema['feedapi'] = array(
13 'description' => 'Stores feed-related info for each feed',
14 'fields' => array(
15 'nid' => array(
16 'description' => 'The node identifier where the feed belongs.',
17 'type' => 'int',
18 'unsigned' => TRUE,
19 'not null' => TRUE),
20 'vid' => array(
21 'description' => 'The primary identifier for the feed.',
22 'type' => 'int',
23 'unsigned' => TRUE,
24 'not null' => TRUE),
25 'url' => array(
26 'description' => 'The URL of the feed',
27 'type' => 'text',
28 'not null' => TRUE),
29 'feed_type' => array(
30 'description' => 'Type of feed',
31 'type' => 'varchar',
32 'not null' => TRUE,
33 'default' => 'XML feed',
34 'length' => '50'),
35 'processors' => array(
36 'description' => 'List of enabled processors',
37 'type' => 'varchar',
38 'not null' => TRUE,
39 'default' => '',
40 'length' => '255'),
41 'parsers' => array(
42 'description' => 'List of enabled parsers',
43 'type' => 'varchar',
44 'not null' => TRUE,
45 'default' => '',
46 'length' => '255'),
47 'next_refresh_time' => array(
48 'description' => 'Timestamp of the earliest possible next refresh time',
49 'type' => 'int',
50 'unsigned' => FALSE,
51 'default' => 0,
52 'not null' => TRUE),
53 'hash' => array(
54 'description' => 'Hash of the feed content',
55 'type' => 'varchar',
56 'length' => '32'),
57 'link' => array(
58 'description' => 'URL of the source site of the feed',
59 'type' => 'text'),
60 'settings' => array(
61 'description' => 'Various settings of the feed',
62 'type' => 'text',
63 'size' => 'big'),
64 'half_done' => array(
65 'description' => 'Indicates if not all of the feed items were processed at the last cron run',
66 'type' => 'int',
67 'size' => 'tiny'),
68 ),
69 'primary key' => array('vid', 'nid'),
70 'indexes' => array(
71 'vid' => array('vid'),
72 'next_refresh_time' => array('next_refresh_time')),
73 );
74 $schema['feedapi_stat'] = array(
75 'description' => 'Statistics values over the time about the feeds',
76 'fields' => array(
77 'id' => array(
78 'description' => 'Unique identifier for statistics data',
79 'type' => 'int',
80 'not null' => TRUE,
81 'default' => 0),
82 'type' => array(
83 'description' => 'Type of the data',
84 'type' => 'varchar',
85 'length' => 64,
86 'not null' => TRUE),
87 'timestamp' => array(
88 'description' => 'Timestamp of the data',
89 'type' => 'int',
90 'not null' => TRUE),
91 'time' => array(
92 'description' => 'Time of the data',
93 'type' => 'varchar',
94 'length' => 20,
95 'not null' => TRUE),
96 'value' => array(
97 'description' => 'Value of the data',
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 /**
110 * Implementation of hook_install().
111 */
112 function feedapi_install() {
113 drupal_install_schema('feedapi');
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'");
117 }
118
119 /**
120 * Implementation of hook_uninstall().
121 */
122 function feedapi_uninstall() {
123 drupal_uninstall_schema('feedapi');
124
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 }
135 }
136
137 function feedapi_update_6101() {
138 $ret = array();
139 db_add_field($ret, 'feedapi', 'skip', array('type' => 'int', 'size' => 'tiny', 'default' => 0));
140 db_add_index($ret, 'feedapi', 'skip_id', array('skip'));
141 return $ret;
142 }
143
144 function feedapi_update_6102() {
145 $ret = array();
146 db_change_field($ret, 'feedapi', 'url', 'url', array('description' => 'The URL of the feed', 'type' => 'text'));
147 db_change_field($ret, 'feedapi', 'link', 'link', array('type' => 'text'));
148 return $ret;
149 }
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 }
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 }
179
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 }
191
192 /**
193 * Adds vid to feedapi table
194 */
195 function feedapi_update_6105() {
196 global $db_type;
197 $ret = array();
198 db_add_field($ret, 'feedapi', 'vid',
199 array(
200 'description' => 'The primary identifier for the feed.',
201 'type' => 'int',
202 'unsigned' => TRUE,
203 'not null' => TRUE,
204 'default' => 0,
205 )
206 );
207 db_drop_primary_key($ret, 'feedapi');
208 if ($db_type == 'mysql' || $db_type == 'mysqli') {
209 $ret[] = update_sql("UPDATE {feedapi} f, {node} n SET f.vid = n.vid WHERE n.nid = f.nid");
210 }
211 else {
212 $ret[] = update_sql("UPDATE {feedapi} SET vid = n.vid FROM (SELECT vid, nid FROM {node} n) n WHERE n.nid = feedapi.nid");
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'));
217 return $ret;
218 }
219
220 /**
221 * Convert checked to next_refresh_time and consolidate skip and
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;
269 }
270
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 }