Newer
Older
Alex Barth
committed
Alex Barth
committed
* Schema definitions install/update/uninstall hooks.
*/
function feeds_schema() {
Alex Barth
committed
$schema = array();
$schema['feeds_importer'] = array(
'description' => 'Configuration of feeds objects.',
'export' => array(
'key' => 'id',
Alex Barth
committed
'identifier' => 'feeds_importer',
'default hook' => 'feeds_importer_default', // Function hook name.
Alex Barth
committed
'owner' => 'feeds',
'api' => 'feeds_importer_default', // Base name for api include files.
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'id' => array(
'type' => 'varchar',
Alex Barth
committed
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the fields object.',
),
'config' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Configuration of the feeds object.',
'serialize' => TRUE,
),
),
Alex Barth
committed
'primary key' => array('id'),
$schema['feeds_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
Alex Barth
committed
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
Alex Barth
committed
'feed_nid' => array(
Alex Barth
committed
'not null' => TRUE,
'default' => 0,
Alex Barth
committed
'description' => 'Node nid if this particular source is attached to a feed node.',
Alex Barth
committed
'config' => array(
Alex Barth
committed
'description' => 'Configuration of the source.',
Alex Barth
committed
'source' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Main source resource identifier. E. g. a path or a URL.',
Alex Barth
committed
),
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
Alex Barth
committed
'description' => 'Cache for batching.',
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
),
'fetcher_result' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
Alex Barth
committed
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
Alex Barth
committed
'primary key' => array('id', 'feed_nid'),
Alex Barth
committed
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'id_source' => array('id', array('source', 128)),
),
);
$schema['feeds_item'] = array(
'description' => 'Tracks items such as nodes, terms, users.',
Alex Barth
committed
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
),
'entity_id' => array(
Alex Barth
committed
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The imported entity\'s serial id.',
Alex Barth
committed
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that created this item.',
Alex Barth
committed
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, if available.',
Alex Barth
committed
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
Alex Barth
committed
'description' => 'Import date of the feed item, as a Unix timestamp.',
Alex Barth
committed
),
'url' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Link to the feed item.',
Alex Barth
committed
),
'guid' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Unique identifier for the feed item.'
Alex Barth
committed
),
'hash' => array(
'type' => 'varchar',
'length' => 32, // The length of an MD5 hash.
'not null' => TRUE,
'default' => '',
'description' => 'The hash of the source item.',
Alex Barth
committed
),
'primary key' => array('entity_type', 'entity_id'),
Alex Barth
committed
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 255)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 255)),
Alex Barth
committed
'imported' => array('imported'),
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
$schema['feeds_push_subscriptions'] = array(
'description' => 'PubSubHubbub subscriptions.',
'fields' => array(
'domain' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Domain of the subscriber. Corresponds to an importer id.',
),
'subscriber_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'ID of the subscriber. Corresponds to a feed nid.',
),
'timestamp' => array(
'type' => 'int',
'unsigned' => FALSE,
'default' => 0,
'not null' => TRUE,
'description' => 'Created timestamp.',
),
'hub' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'The URL of the hub endpoint of this subscription.',
),
'topic' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'The topic URL (feed URL) of this subscription.',
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
),
'secret' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Shared secret for message authentication.',
),
'status' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Status of subscription.',
),
'post_fields' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Fields posted.',
'serialize' => TRUE,
),
),
'primary key' => array('domain', 'subscriber_id'),
'indexes' => array(
'timestamp' => array('timestamp'),
),
);
return $schema;
}
/**
* Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
* result.
*/
function feeds_update_7100(&$sandbox) {
$spec = array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
);
db_change_field('feeds_source', 'batch', 'state', $spec);
$spec = array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
'serialize' => TRUE,
);
db_add_field('feeds_source', 'fetcher_result', $spec);
}
Alex Barth
committed
/**
* Add imported timestamp to feeds_source table.
*/
function feeds_update_7201(&$sandbox) {
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
);
db_add_field('feeds_source', 'imported', $spec);
}
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
* Create a single feeds_item table tracking all imports.
*/
function feeds_update_7202(&$sandbox) {
$spec = array(
'description' => 'Tracks items such as nodes, terms, users.',
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
),
'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The imported entity\'s serial id.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that created this item.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, if available.',
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Import date of the feed item, as a Unix timestamp.',
),
'url' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Link to the feed item.',
),
'guid' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Unique identifier for the feed item.'
),
'hash' => array(
'type' => 'varchar',
'length' => 32, // The length of an MD5 hash.
'not null' => TRUE,
'default' => '',
'description' => 'The hash of the source item.',
),
),
'primary key' => array('entity_type', 'entity_id'),
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 255)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 255)),
'imported' => array('imported'),
),
);
db_create_table('feeds_item', $spec);
// Copy all existing values from old tables and drop them.
$insert = "INSERT INTO {feeds_item} (entity_type, entity_id, id, feed_nid, imported, url, guid, hash)";
db_query($insert . " SELECT 'node', nid, id, feed_nid, imported, url, guid, hash FROM {feeds_node_item}");
db_query($insert . " SELECT 'taxonomy_term', tid, id, feed_nid, 0, '', '', '' FROM {feeds_term_item}");
db_drop_table('feeds_node_item');
db_drop_table('feeds_term_item');
}