feedapi.install in FeedAPI 6
Same filename and directory in other branches
Install file for FeedAPI module.
File
feedapi.installView source
<?php
/**
* @file
* Install file for FeedAPI module.
*/
/**
* Implementation of hook_schema().
*/
function feedapi_schema() {
$schema['feedapi'] = array(
'description' => 'Stores feed-related info for each feed',
'fields' => array(
'nid' => array(
'description' => 'The node identifier where the feed belongs.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The primary identifier for the feed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'url' => array(
'description' => 'The URL of the feed',
'type' => 'text',
'not null' => TRUE,
),
'feed_type' => array(
'description' => 'Type of feed',
'type' => 'varchar',
'not null' => TRUE,
'default' => 'XML feed',
'length' => '50',
),
'processors' => array(
'description' => 'List of enabled processors',
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => '255',
),
'parsers' => array(
'description' => 'List of enabled parsers',
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => '255',
),
'next_refresh_time' => array(
'description' => 'Timestamp of the earliest possible next refresh time',
'type' => 'int',
'unsigned' => FALSE,
'default' => 0,
'not null' => TRUE,
),
'hash' => array(
'description' => 'Hash of the feed content',
'type' => 'varchar',
'length' => '32',
),
'link' => array(
'description' => 'URL of the source site of the feed',
'type' => 'text',
),
'settings' => array(
'description' => 'Various settings of the feed',
'type' => 'text',
'size' => 'big',
),
'half_done' => array(
'description' => 'Indicates if not all of the feed items were processed at the last cron run',
'type' => 'int',
'size' => 'tiny',
),
),
'primary key' => array(
'vid',
'nid',
),
'indexes' => array(
'vid' => array(
'vid',
),
'next_refresh_time' => array(
'next_refresh_time',
),
),
);
$schema['feedapi_stat'] = array(
'description' => 'Statistics values over the time about the feeds',
'fields' => array(
'id' => array(
'description' => 'Unique identifier for statistics data',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'description' => 'Type of the data',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'timestamp' => array(
'description' => 'Timestamp of the data',
'type' => 'int',
'not null' => TRUE,
),
'time' => array(
'description' => 'Time of the data',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'value' => array(
'description' => 'Value of the data',
'type' => 'int',
),
),
'indexes' => array(
'feedapi_stat_id' => array(
'id',
),
'feedapi_stat_type' => array(
'type',
),
),
'feedapi_stat_timestamp' => array(
'timestamp',
),
'feedapi_stat_time' => array(
'time',
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function feedapi_install() {
drupal_install_schema('feedapi');
// This value warrants that og, taxonomy and similar modules does their job before feedapi. This is important
// because of for example feedapi_inherit or whatever processor which needs a 3rd-party processed data.
db_query("UPDATE {system} SET weight = 5 WHERE name = 'feedapi'");
}
/**
* Implementation of hook_uninstall().
*/
function feedapi_uninstall() {
drupal_uninstall_schema('feedapi');
// Delete variables site-wide
variable_del('feedapi_allowed_html_tags');
variable_del('feedapi_allow_html_all');
variable_del('feedapi_cron_percentage');
// Delete variables per-content-type
$types = array_keys(node_get_types());
foreach ($types as $type) {
variable_del('feedapi_settings_' . $type);
}
}
function feedapi_update_6101() {
$ret = array();
db_add_field($ret, 'feedapi', 'skip', array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
));
db_add_index($ret, 'feedapi', 'skip_id', array(
'skip',
));
return $ret;
}
function feedapi_update_6102() {
$ret = array();
db_change_field($ret, 'feedapi', 'url', 'url', array(
'description' => 'The URL of the feed',
'type' => 'text',
));
db_change_field($ret, 'feedapi', 'link', 'link', array(
'type' => 'text',
));
return $ret;
}
/**
* feedapi_access_op() was renamed to _feedapi_op_access().
* See #307853.
*/
function feedapi_update_6103() {
menu_rebuild();
return array();
}
/**
* Check out if the built-in content-type has an enabled parser.
*/
function feedapi_update_6104() {
$default_processor = 'feed';
// Determine if the installation is affected
$affected = FALSE;
$settings = variable_get('feedapi_settings_' . $default_processor, FALSE);
if (!isset($settings['parsers'])) {
$affected = TRUE;
}
else {
foreach ($settings['parsers'] as $parser => $setting) {
if (!module_exists($parser) && $setting['enabled']) {
$affected = TRUE;
}
}
}
if ($affected) {
// Set the parser of defaultly shipped processors if it's not done previously
$parsers = module_implements('feedapi_feed');
if (count($parsers) > 0) {
$set_processor = array(
"parsers" => array(
array_pop($parsers) => array(
"enabled" => TRUE,
"weight" => 0,
),
),
);
$settings = is_array($settings) ? array_merge($settings, $set_processor) : $set_processor;
variable_set('feedapi_settings_' . $default_processor, $settings);
}
}
return array();
}
/**
* Adds vid to feedapi table
*/
function feedapi_update_6105() {
global $db_type;
$ret = array();
db_add_field($ret, 'feedapi', 'vid', array(
'description' => 'The primary identifier for the feed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_drop_primary_key($ret, 'feedapi');
if ($db_type == 'mysql' || $db_type == 'mysqli') {
$ret[] = update_sql("UPDATE {feedapi} f, {node} n SET f.vid = n.vid WHERE n.nid = f.nid");
}
else {
$ret[] = update_sql("UPDATE {feedapi} SET vid = n.vid FROM (SELECT vid, nid FROM {node} n) n WHERE n.nid = feedapi.nid");
}
$ret[] = update_sql("UPDATE {feedapi} SET vid = nid WHERE vid = 0");
db_add_primary_key($ret, 'feedapi', array(
'vid',
'nid',
));
db_add_index($ret, 'feedapi', 'vid', array(
'vid',
));
return $ret;
}
/**
* Convert checked to next_refresh_time and consolidate skip and
* next_refresh_time, add an index on next_refresh_time, make next_refresh_time
* unsigned.
*/
function feedapi_update_6106() {
$spec = array(
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
'not null' => TRUE,
);
db_change_field($ret, 'feedapi', 'checked', 'next_refresh_time', $spec);
// Convert the value in next_refresh_time from the last time a feed has been
// to the next time it should be checked.
$ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = (next_refresh_time + ' . FEEDAPI_CRON_DEFAULT_REFRESH_TIME . ')');
// Set next_refresh_time to FEEDAPI_CRON_NEVER_REFRESH where skip = 1.
$ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = ' . FEEDAPI_CRON_NEVER_REFRESH . ' WHERE skip = 1');
// Drop skip row
db_drop_field($ret, 'feedapi', 'skip');
// Update all settings.
$node_types = node_get_types('types');
// Update all node type settings.
foreach ($node_types as $node_type) {
if (feedapi_enabled_type($node_type)) {
if ($settings = feedapi_get_settings($node_type)) {
$settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME;
unset($settings['skip']);
_feedapi_store_settings(array(
'node_type' => $node_type,
), $settings);
}
}
}
// Update all node settings.
$result = db_query('SELECT n.type, f.vid FROM {node} n JOIN {feedapi} f ON f.nid = n.nid');
while ($node = db_fetch_object($result)) {
if ($settings = feedapi_get_settings($node->type, $node->vid)) {
$settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME;
unset($settings['skip']);
_feedapi_store_settings(array(
'node_type' => $node->type,
'vid' => $node->vid,
), $settings);
}
}
return $ret;
}
/**
* Convert refresh_time values to new constants
* FEEDAPI_CRON_NEVER_REFRESH and FEEDAPI_CRON_ALWAYS_REFRESH.
*/
function feedapi_update_6107() {
$ret = array();
// next_refresh_time can contain negative values now.
$spec = array(
'type' => 'int',
'unsigned' => FALSE,
'default' => 0,
'not null' => TRUE,
);
db_change_field($ret, 'feedapi', 'next_refresh_time', 'next_refresh_time', $spec);
// Update all node type settings.
$node_types = node_get_types('types');
foreach ($node_types as $node_type) {
if (feedapi_enabled_type($node_type)) {
if ($settings = feedapi_get_settings($node_type)) {
if ($settings['refresh_time'] == 0 || $settings['refresh_time'] == 1) {
$settings['refresh_time'] = $settings['refresh_time'] == 0 ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_ALWAYS_REFRESH;
_feedapi_store_settings(array(
'node_type' => $node_type,
), $settings);
}
}
}
}
// Update all node settings.
$result = db_query('SELECT n.type, f.vid FROM {node} n JOIN {feedapi} f ON f.nid = n.nid');
while ($node = db_fetch_object($result)) {
if ($settings = feedapi_get_settings($node->type, $node->vid)) {
if ($settings['refresh_time'] == 0 || $settings['refresh_time'] == 1) {
$settings['refresh_time'] = $settings['refresh_time'] == 0 ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_ALWAYS_REFRESH;
_feedapi_store_settings(array(
'node_type' => $node->type,
'vid' => $node->vid,
), $settings);
}
}
}
return $ret;
}
Functions
Name | Description |
---|---|
feedapi_install | Implementation of hook_install(). |
feedapi_schema | Implementation of hook_schema(). |
feedapi_uninstall | Implementation of hook_uninstall(). |
feedapi_update_6101 | |
feedapi_update_6102 | |
feedapi_update_6103 | feedapi_access_op() was renamed to _feedapi_op_access(). See #307853. |
feedapi_update_6104 | Check out if the built-in content-type has an enabled parser. |
feedapi_update_6105 | Adds vid to feedapi table |
feedapi_update_6106 | Convert checked to next_refresh_time and consolidate skip and next_refresh_time, add an index on next_refresh_time, make next_refresh_time unsigned. |
feedapi_update_6107 | Convert refresh_time values to new constants FEEDAPI_CRON_NEVER_REFRESH and FEEDAPI_CRON_ALWAYS_REFRESH. |