feeds.install in Feeds 6
Same filename and directory in other branches
Schema definitions install/update/uninstall hooks.
File
feeds.installView source
<?php
/**
* @file
* Schema definitions install/update/uninstall hooks.
*/
/**
* Implements hook_schema().
*/
function feeds_schema() {
$schema = array();
$schema['feeds_importer'] = array(
'description' => 'Configuration of feeds objects.',
'export' => array(
'key' => 'id',
'identifier' => 'feeds_importer',
'default hook' => 'feeds_importer_default',
// Function hook name.
'api' => array(
'owner' => 'feeds',
'api' => 'feeds_importer_default',
// Base name for api include files.
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'id' => array(
'type' => 'varchar',
'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,
),
),
'primary key' => array(
'id',
),
);
$schema['feeds_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
'feed_nid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Node nid if this particular source is attached to a feed node.',
),
'config' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Configuration of the source.',
'serialize' => TRUE,
),
'source' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Main source resource identifier. E. g. a path or a URL.',
),
'batch' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for batching.',
'serialize' => TRUE,
),
),
'primary key' => array(
'id',
'feed_nid',
),
'indexes' => array(
'id' => array(
'id',
),
'feed_nid' => array(
'feed_nid',
),
'id_source' => array(
'id',
array(
'source',
128,
),
),
),
);
$schema['feeds_node_item'] = array(
'description' => 'Stores additional information about feed item nodes. Used by FeedsNodeProcessor.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "Primary Key: The feed item node's nid.",
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the fields object that is the producer of this item.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "Node id of the owner feed, 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(
'nid',
),
'indexes' => array(
'id' => array(
'id',
),
'feed_nid' => array(
'feed_nid',
),
'imported' => array(
'imported',
),
'url' => array(
array(
'url',
255,
),
),
'guid' => array(
array(
'guid',
255,
),
),
),
);
$schema['feeds_term_item'] = array(
'description' => 'Tracks imported terms.',
'fields' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Imported term id.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the fields object that is the creator of this item.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "Node id of the owner feed, 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.',
),
),
'primary key' => array(
'tid',
),
'indexes' => array(
'id' => array(
'id',
),
'feed_nid' => array(
'feed_nid',
),
'imported' => array(
'imported',
),
'url' => array(
array(
'url',
255,
),
),
'guid' => array(
array(
'guid',
255,
),
),
),
);
$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,
'description' => 'The URL of the hub endpoint of this subscription.',
),
'topic' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'The topic URL (feed URL) of this subscription.',
),
'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;
}
/**
* Implementation of hook_install().
*/
function feeds_install() {
// Create tables.
drupal_install_schema('feeds');
}
/**
* Implementation of hook_uninstall().
*/
function feeds_uninstall() {
// Remove tables.
drupal_uninstall_schema('feeds');
}
/**
* Remove class field on feeds_config.
*/
function feeds_update_6001() {
$ret = array();
db_drop_field($ret, 'feeds_config', 'class');
return $ret;
}
/**
* Rename table.
*/
function feeds_update_6002() {
$ret = array();
db_rename_table($ret, 'feeds_config', 'feeds_importer');
return $ret;
}
/**
* Add primary keys to feeds_importer and feeds_source.
*/
function feeds_update_6003() {
$ret = array();
db_drop_index($ret, 'feeds_importer', 'id');
db_add_primary_key($ret, 'feeds_importer', array(
'id',
));
db_add_primary_key($ret, 'feeds_source', array(
'id',
'feed_nid',
));
return $ret;
}
/**
* Add source field to feeds_source, make fields part of PKs not null.
*/
function feeds_update_6004() {
$ret = array();
$spec = array(
'type' => 'text',
'not null' => TRUE,
'description' => t('Main source resource identifier. E. g. a path or a URL.'),
);
db_add_field($ret, 'feeds_source', 'source', $spec);
db_add_index($ret, 'feeds_source', 'id_source', array(
'id',
array(
'source',
255,
),
));
// Make feed_nid not null, default 0. It is part of the primary key.
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Node nid if this particular source is attached to a feed node.',
);
db_change_field($ret, 'feeds_schedule', 'feed_nid', 'feed_nid', $spec);
// Same thing for feeds_source table.
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Node nid if this particular source is attached to a feed node.',
);
db_change_field($ret, 'feeds_source', 'feed_nid', 'feed_nid', $spec);
return $ret;
}
/**
* Add callback column to feeds_schedule.
*/
function feeds_update_6005() {
$ret = array();
// Add a callback column and an index.
$spec = array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Callback to be invoked.',
);
db_add_field($ret, 'feeds_schedule', 'callback', $spec);
db_add_index($ret, 'feeds_schedule', 'id_callback', array(
'id',
'callback',
));
return $ret;
}
/**
* Remove primary key from feeds_schedule and replace it by an index.
*/
function feeds_update_6006() {
$ret = array();
db_drop_primary_key($ret, 'feeds_schedule');
db_add_index($ret, 'feeds_schedule', 'feed_nid', array(
'feed_nid',
));
return $ret;
}
/**
* Add hash column to feeds_node_item.
*/
function feeds_update_6007() {
$ret = array();
$spec = array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => t('The hash of the item.'),
);
db_add_field($ret, 'feeds_node_item', 'hash', $spec);
return $ret;
}
/**
* Add batch field to feeds_source table, adjust feeds_schedule table.
*/
function feeds_update_6008() {
$ret = array();
$spec = array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => t('Cache for batching.'),
'serialize' => TRUE,
);
db_add_field($ret, 'feeds_source', 'batch', $spec);
// Make scheduled flag a timestamp.
$spec = array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'default' => 0,
'not null' => TRUE,
'description' => 'Timestamp when a job was scheduled. 0 if a job is currently not scheduled.',
);
db_change_field($ret, 'feeds_schedule', 'scheduled', 'scheduled', $spec);
// Rename last_scheduled_time to last_executed_time, fix unsigned property.
$spec = array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'default' => 0,
'not null' => TRUE,
'description' => 'Timestamp when a job was last executed.',
);
db_change_field($ret, 'feeds_schedule', 'last_scheduled_time', 'last_executed_time', $spec);
return $ret;
}
/**
* Add feeds_push_subscriptions tables.
*/
function feeds_update_6009() {
$ret = array();
$table = 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,
'description' => t('The URL of the hub endpoint of this subscription.'),
),
'topic' => array(
'type' => 'text',
'not null' => TRUE,
'description' => t('The topic URL (feed URL) of this subscription.'),
),
'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',
),
),
);
db_create_table($ret, 'feeds_push_subscriptions', $table);
return $ret;
}
/**
* Show a message about Feeds News, Feeds Import and Feeds fast news features.
*/
function feeds_update_6010() {
drupal_set_message(t('You may install Feeds News and Feeds Import as replacement for Feeds Defaults module.'));
if (module_exists('features')) {
drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/build/feeds and features on admin/build/features.</strong>'));
}
else {
drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/build/feeds and Feeds modules on admin/build/modules.</strong>'));
}
return array();
}
/**
* Add imported flag for terms.
*/
function feeds_update_6011() {
$ret = array();
$schema = array(
'description' => 'Tracks imported terms.',
'fields' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Imported term id.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the fields object that is the creator of this item.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => t("Node id of the owner feed, if available."),
),
),
'primary key' => array(
'tid',
),
'indexes' => array(
'id_feed_nid' => array(
'id',
'feed_nid',
),
'feed_nid' => array(
'feed_nid',
),
),
);
db_create_table($ret, 'feeds_term_item', $schema);
return $ret;
}
/**
* Drop schedule table install Job Scheduler module.
*/
function feeds_update_6012() {
$ret = array();
// Only attempt installation if module is present, otherwise we would leave
// the system table in a limbo.
$modules = module_rebuild_cache();
if (isset($modules['job_scheduler'])) {
if (!$modules['job_scheduler']->status) {
drupal_install_modules(array(
'job_scheduler',
));
drupal_set_message(t('Installed Job Scheduler module.'));
}
}
else {
drupal_set_message(t('NOTE: Please install new dependency of Feeds: <a href="@job-scheduler-link">Job scheduler module</a>.', array(
'@job-scheduler-link' => url('http://drupal.org/project/job_scheduler'),
)), 'warning');
}
db_drop_table($ret, 'feeds_schedule');
return $ret;
}
/**
* Reschedule all tasks.
*/
function feeds_update_6013() {
// This was originally part of 6012 upgrade, but failed due to usage of
// API functions residing in feeds.module. Make sure it runs again for all
// users of Feeds.
variable_set('feeds_reschedule', TRUE);
return array();
}
/**
* Update feeds_term_item to match feeds_node_item.
*/
function feeds_update_6014() {
$ret = array();
// Define new fields.
$fields = array(
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('Import date of the feed item, as a Unix timestamp.'),
),
'url' => array(
'type' => 'text',
'not null' => TRUE,
'description' => t('Link to the feed item.'),
),
'guid' => array(
'type' => 'text',
'not null' => TRUE,
'description' => t('Unique identifier for the feed item.'),
),
);
// Add new fields.
foreach ($fields as $field => $data) {
db_add_field($ret, 'feeds_term_item', $field, $data);
}
// Add new indexes, drop id_feed_nid.
db_drop_index($ret, 'feeds_term_item', 'id_feed_nid');
db_add_index($ret, 'feeds_term_item', 'id', array(
'id',
));
db_add_index($ret, 'feeds_term_item', 'imported', array(
'imported',
));
db_add_index($ret, 'feeds_term_item', 'url', array(
array(
'url',
255,
),
));
db_add_index($ret, 'feeds_term_item', 'guid', array(
array(
'guid',
255,
),
));
return $ret;
}
/**
* Change batch field from text to blob.
*/
function feeds_update_6015() {
$ret = array();
$spec = array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => t('Cache for batching.'),
'serialize' => TRUE,
);
db_change_field($ret, 'feeds_source', 'batch', 'batch', $spec);
return $ret;
}
Functions
Name | Description |
---|---|
feeds_install | Implementation of hook_install(). |
feeds_schema | Implements hook_schema(). |
feeds_uninstall | Implementation of hook_uninstall(). |
feeds_update_6001 | Remove class field on feeds_config. |
feeds_update_6002 | Rename table. |
feeds_update_6003 | Add primary keys to feeds_importer and feeds_source. |
feeds_update_6004 | Add source field to feeds_source, make fields part of PKs not null. |
feeds_update_6005 | Add callback column to feeds_schedule. |
feeds_update_6006 | Remove primary key from feeds_schedule and replace it by an index. |
feeds_update_6007 | Add hash column to feeds_node_item. |
feeds_update_6008 | Add batch field to feeds_source table, adjust feeds_schedule table. |
feeds_update_6009 | Add feeds_push_subscriptions tables. |
feeds_update_6010 | Show a message about Feeds News, Feeds Import and Feeds fast news features. |
feeds_update_6011 | Add imported flag for terms. |
feeds_update_6012 | Drop schedule table install Job Scheduler module. |
feeds_update_6013 | Reschedule all tasks. |
feeds_update_6014 | Update feeds_term_item to match feeds_node_item. |
feeds_update_6015 | Change batch field from text to blob. |