You are here

function feedapi_aggregator_install in FeedAPI 5

Implementation of hook_install().

File

feedapi_aggregator/feedapi_aggregator.install, line 6

Code

function feedapi_aggregator_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {feedapi_aggregator_category} (\n        cid int NOT NULL auto_increment,\n        title varchar(255) NOT NULL default '',\n        description longtext NOT NULL,\n        block tinyint NOT NULL default '0',\n        PRIMARY KEY (cid),\n        UNIQUE KEY title (title)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {feedapi_aggregator_category_feed} (\n        feed_nid int NOT NULL default '0',\n        cid int NOT NULL default '0',\n        PRIMARY KEY (feed_nid,cid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {feedapi_aggregator_category_item} (\n        iid int NOT NULL default '0',\n        cid int NOT NULL default '0',\n        PRIMARY KEY (iid,cid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {feedapi_aggregator_item} (\n        iid int NOT NULL auto_increment,\n        feed_nid int NOT NULL default '0',\n        title varchar(255) NOT NULL default '',\n        link varchar(255) NOT NULL default '',\n        author varchar(255) NOT NULL default '',\n        description longtext NOT NULL,\n        timestamp int default NULL,\n        guid varchar(255),\n        PRIMARY KEY (iid),\n        KEY feed_nid (feed_nid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {feedapi_aggregator_category} (\n        cid serial,\n        title varchar(255) NOT NULL default '',\n        description text NOT NULL,\n        block smallint NOT NULL default '0',\n        PRIMARY KEY (cid),\n        UNIQUE (title)\n      )");
      db_query("CREATE TABLE {feedapi_aggregator_category_feed} (\n        feed_nid int NOT NULL default '0',\n        cid int NOT NULL default '0',\n        PRIMARY KEY (feed_nid,cid)\n      )");
      db_query("CREATE TABLE {feedapi_aggregator_category_item} (\n        iid int NOT NULL default '0',\n        cid int NOT NULL default '0',\n        PRIMARY KEY (iid,cid)\n      )");
      db_query("CREATE TABLE {feedapi_aggregator_item} (\n        iid serial,\n        feed_nid int NOT NULL default '0',\n        title varchar(255) NOT NULL default '',\n        link varchar(255) NOT NULL default '',\n        author varchar(255) NOT NULL default '',\n        description text NOT NULL,\n        timestamp int default NULL,\n        guid varchar(255),\n        PRIMARY KEY (iid)\n      )");
      db_query("CREATE INDEX {feedapi_aggregator_item}_feed_nid_idx ON {feedapi_aggregator_item} (feed_nid)");
      break;
  }

  // Create a default content type
  $info->type = 'feedapi_aggregator';
  $info->name = t('Feed (lightweight items)');
  $info->description = t('Aggregates RSS or Atom feeds. Feed items will be turned into lightweight database entries.');
  $info->module = 'node';
  $info->has_title = TRUE;
  $info->title_label = t('Title');
  $info->has_body = TRUE;
  $info->body_label = t('Body');
  $info->min_word_count = 0;
  $info->custom = TRUE;
  node_type_save($info);

  // Adding default FeedAPI settings
  $preset = unserialize('a:3:{s:7:"enabled";s:1:"1";s:12:"items_delete";s:1:"0";s:10:"processors";a:2:{s:18:"feedapi_aggregator";a:3:{s:7:"enabled";s:1:"1";s:6:"weight";s:1:"0";s:5:"block";s:1:"3";}s:12:"feedapi_item";a:6:{s:6:"weight";s:1:"0";s:12:"content_type";s:5:"story";s:9:"node_date";s:4:"feed";s:7:"promote";s:1:"3";s:9:"list_feed";s:1:"3";s:4:"user";s:5:"admin";}}}');
  if (is_array(variable_get('feedapi_settings_feedapi_aggregator', FALSE))) {
    $preset = array_merge($preset, variable_get('feedapi_settings_feedapi_aggregator', FALSE));
  }
  variable_set('feedapi_settings_feedapi_aggregator', $preset);
}