You are here

parser_common_syndication.install in FeedAPI 6

Same filename and directory in other branches
  1. 5 parser_common_syndication/parser_common_syndication.install

Adds it to the content-type configuration

File

parser_common_syndication/parser_common_syndication.install
View source
<?php

/**
 * @file
 * Adds it to the content-type configuration
 */

/**
 * Implementation of hook_schema().
 */
function parser_common_syndication_schema() {
  $schema['parser_common_syndication'] = array(
    'fields' => array(
      'url' => array(
        'description' => t('The MD5 hash of feed URL'),
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => '32',
      ),
      'etag' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
      'last_modified' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'url',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function parser_common_syndication_install() {
  drupal_install_schema('parser_common_syndication');

  // Set the parser of defaultly shipped processors if it's not done previously.
  $default_processors = array(
    'feed',
  );
  $set_common = array(
    "parsers" => array(
      "parser_common_syndication" => array(
        "enabled" => TRUE,
        "weight" => 0,
      ),
    ),
  );
  foreach ($default_processors as $processor) {
    $settings = variable_get('feedapi_settings_' . $processor, FALSE);
    if (!isset($settings['parsers'])) {
      $settings = is_array($settings) ? array_merge($settings, $set_common) : $set_common;
      variable_set('feedapi_settings_' . $processor, $settings);
    }
  }
}

/**
 * Implementation of hook_uninstall().
 */
function parser_common_syndication_uninstall() {
  drupal_uninstall_schema('parser_common_syndication');

  // Empty cache directory.
  $cache_dir = variable_get('parser_common_syndication_cache', FALSE);
  if (is_dir($cache_dir)) {
    $dp = opendir($cache_dir);
    while (($file = readdir($dp)) !== FALSE) {
      if (is_file($file)) {
        unlink($cache_dir . '/' . $file);
      }
    }
    closedir($dp);
    rmdir($cache_dir);
  }
  variable_del('parser_common_syndication_cache');
}

/**
 * Instead of textual URL, store MD5 in the parser_common_syndication table
 */
function parser_common_syndication_update_6101() {
  $ret = array();
  db_query('DELETE FROM {parser_common_syndication}');
  db_change_field($ret, 'parser_common_syndication', 'url', 'url', array(
    'description' => t('The MD5 hash of feed URL'),
    'type' => 'varchar',
    'not null' => TRUE,
    'length' => '32',
  ));
  return $ret;
}

Functions

Namesort descending Description
parser_common_syndication_install Implementation of hook_install().
parser_common_syndication_schema Implementation of hook_schema().
parser_common_syndication_uninstall Implementation of hook_uninstall().
parser_common_syndication_update_6101 Instead of textual URL, store MD5 in the parser_common_syndication table