Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (106 sloc) 3.31 KB
<?php
/**
* @file
* Install and uninstall schema and functions for the feedburner module.
*/
/**
* Implements hook_install().
*/
function feedburner_install() {
// Set module weight to run before others.
db_query("UPDATE {system} SET weight = -1 WHERE type = 'module' AND name = 'feedburner'");
}
/**
* Implements hook_uninstall().
*/
function feedburner_uninstall() {
drupal_uninstall_schema('feedburner');
// Remove variables.
drupal_load('module', 'feedburner');
$variables = array_keys(feedburner_variables());
foreach ($variables as $variable) {
variable_del($variable);
}
}
/**
* Implements hook_requirements().
*/
function feedburner_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
if (!function_exists('simplexml_load_string')) {
$requirements['feedburner_simplexml'] = array(
'title' => $t('FeedBurner module'),
'value' => $t('SimpleXML not enabled'),
'severity' => REQUIREMENT_WARNING,
'description' => $t('Some FeedBurner features require the SimpleXML PHP extension (not available for PHP4).'),
);
}
}
return $requirements;
}
/**
* Implementshook_schema().
*/
function feedburner_schema() {
$schema['feedburner'] = array(
'description' => 'Stores information on FeedBurner feed redirections.',
'fields' => array(
'path' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'The source feed.',
),
'feedburner' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'description' => 'FeedBurner feed.',
),
),
'primary key' => array('path'),
'indexes' => array(
'feedburner' => array('feedburner'),
),
);
return $schema;
}
/**
* Updates table schema and variables from 5.x versions.
*/
function feedburner_update_6000() {
$ret = array();
if (!db_table_exists('feedburner')) {
// If new tables not found, install the new schema
$ret[] = drupal_install_schema('feedburner');
}
elseif (db_column_exists('feedburner', 'verified')) {
// Remove verified column
db_drop_field($ret, 'feedburner', 'verified');
}
// Update from 5.x-0.5 version
$old_feeds = variable_get('feedburner_feeds', array());
if (count($old_feeds)) {
variable_del('feedburner_feeds');
foreach ($old_feeds as $path => $feedburner) {
$ret[] = update_sql("INSERT INTO {feedburner} (path, feedburner) VALUES ('" . $path . "', '" . $feedburner . "')");
}
}
// Update from 5.x-1.x version
if (db_table_exists('feedburner_feeds')) {
$old_feeds = db_query("SELECT local_uri, fb_uri FROM {feedburner_feeds}");
while ($old_feed = db_fetch_object($old_feeds)) {
$ret[] = update_sql("INSERT INTO {feedburner} (path, feedburner) VALUES ('" . $old_feed->local_uri . "', '" . $old_feed->fb_uri . "')");
}
db_drop_table($ret, 'feedburner_feeds');
}
// Convert old useragent variable to full regex expression
$useragents = variable_get('feedburner_useragents', '/feedburner|feedvalidator/i');
if (!preg_match('%^/.*/i$%', $useragents)) {
variable_set('feedburner_useragents', '/' . $useragents . '/i');
}
$ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE type = 'module' AND name = 'feedburner'");
return $ret;
}