<?php
// $Id: aggregator.install,v 1.8 2006/09/26 14:19:00 dries Exp $

/**
 * Implementation of hook_install().
 */
function aggregator_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {aggregator_category} (
        cid int NOT NULL auto_increment,
        title varchar(255) NOT NULL default '',
        description longtext NOT NULL,
        block tinyint NOT NULL default '0',
        PRIMARY KEY (cid),
        UNIQUE KEY title (title)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {aggregator_category_feed} (
        fid int NOT NULL default '0',
        cid int NOT NULL default '0',
        PRIMARY KEY (fid,cid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {aggregator_category_item} (
        iid int NOT NULL default '0',
        cid int NOT NULL default '0',
        PRIMARY KEY (iid,cid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {aggregator_feed} (
        fid int NOT NULL auto_increment,
        title varchar(255) NOT NULL default '',
        url varchar(255) NOT NULL default '',
        refresh int NOT NULL default '0',
        checked int NOT NULL default '0',
        link varchar(255) NOT NULL default '',
        description longtext NOT NULL,
        image longtext NOT NULL,
        etag varchar(255) NOT NULL default '',
        modified int NOT NULL default '0',
        block tinyint NOT NULL default '0',
        PRIMARY KEY (fid),
        UNIQUE KEY link (url),
        UNIQUE KEY title (title)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {aggregator_item} (
        iid int NOT NULL auto_increment,
        fid int NOT NULL default '0',
        title varchar(255) NOT NULL default '',
        link varchar(255) NOT NULL default '',
        author varchar(255) NOT NULL default '',
        description longtext NOT NULL,
        timestamp int default NULL,
        guid varchar(255),
        PRIMARY KEY (iid),
        KEY fid (fid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      break;
    case 'pgsql':
      db_query("CREATE TABLE {aggregator_category} (
        cid serial,
        title varchar(255) NOT NULL default '',
        description text NOT NULL,
        block smallint NOT NULL default '0',
        PRIMARY KEY (cid),
        UNIQUE (title)
      )");

      db_query("CREATE TABLE {aggregator_category_feed} (
        fid int NOT NULL default '0',
        cid int NOT NULL default '0',
        PRIMARY KEY (fid,cid)
      )");

      db_query("CREATE TABLE {aggregator_category_item} (
        iid int NOT NULL default '0',
        cid int NOT NULL default '0',
        PRIMARY KEY (iid,cid)
      )");

      db_query("CREATE TABLE {aggregator_feed} (
        fid serial,
        title varchar(255) NOT NULL default '',
        url varchar(255) NOT NULL default '',
        refresh int NOT NULL default '0',
        checked int NOT NULL default '0',
        link varchar(255) NOT NULL default '',
        description text NOT NULL default '',
        image text NOT NULL default '',
        etag varchar(255) NOT NULL default '',
        modified int NOT NULL default '0',
        block smallint NOT NULL default '0',
        PRIMARY KEY (fid),
        UNIQUE (url),
        UNIQUE (title)
      )");

      db_query("CREATE TABLE {aggregator_item} (
        iid serial,
        fid int NOT NULL default '0',
        title varchar(255) NOT NULL default '',
        link varchar(255) NOT NULL default '',
        author varchar(255) NOT NULL default '',
        description text NOT NULL,
        timestamp int default NULL,
        guid varchar(255),
        PRIMARY KEY (iid)
      )");
      db_query("CREATE INDEX {aggregator_item}_fid_idx ON {aggregator_item} (fid)");

      break;
  }
}

/**
 * Implementation of hook_uninstall().
 */
function aggregator_uninstall() {
  db_query('DROP TABLE {aggregator_category}');
  db_query('DROP TABLE {aggregator_category_feed}');
  db_query('DROP TABLE {aggregator_category_item}');
  db_query('DROP TABLE {aggregator_feed}');
  db_query('DROP TABLE {aggregator_item}');
  variable_del('aggregator_allowed_html_tags');
  variable_del('aggregator_summary_items');
  variable_del('aggregator_clear');
  variable_del('aggregator_category_selector');
}
