You are here

feedapi_node.install in FeedAPI 5

Same filename and directory in other branches
  1. 6 feedapi_node/feedapi_node.install

File

feedapi_node/feedapi_node.install
View source
<?php

function feedapi_node_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {feedapi_node_item} (\n        nid int(10) unsigned NOT NULL,\n        url text character set latin1 collate latin1_general_ci NOT NULL,\n        `timestamp` int(10) unsigned NOT NULL default '0',\n        arrived int(10) unsigned NOT NULL default '0',\n        guid text character set latin1 collate latin1_general_ci NOT NULL,\n        PRIMARY KEY  (nid),\n        KEY arrived (arrived),\n        KEY url (url(255)),\n        KEY guid (guid(255))\n        ) DEFAULT CHARSET=latin1;\n      ");
      db_query("CREATE TABLE {feedapi_node_item_feed} (\n        `feed_nid` int(10) unsigned NOT NULL default '0',\n        `feed_item_nid` int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (`feed_nid`,`feed_item_nid`),\n        KEY `feed_nid` (`feed_nid`),\n        KEY `feed_item_nid` (`feed_item_nid`)\n        ) DEFAULT CHARSET=latin1;\n      ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {feedapi_node_item} (\n        nid integer not null,\n        url text NOT NULL default '',\n        timestamp integer not null,\n        arrived integer not null,\n        guid text NOT NULL default '',\n        PRIMARY KEY(nid))\n      ");
      db_query("CREATE INDEX {feedapi_node_item}_arrived_idx ON {feedapi_node_item} (arrived)");
      db_query("CREATE INDEX url_index on {feedapi_node_item}(url)");
      db_query("CREATE INDEX guid_index on {feedapi_node_item}(guid)");
      db_query("CREATE TABLE {feedapi_node_item_feed} (\n        feed_nid integer NOT NULL default '0',\n        feed_item_nid integer NOT NULL default '0',\n        PRIMARY KEY  (feed_nid,feed_item_nid))\n      ");
      db_query("CREATE INDEX feed_nid_index on {feedapi_node_item_feed}(feed_nid)");
      db_query("CREATE INDEX feed_item_nid_index on {feedapi_node_item_feed}(feed_item_nid)");
      break;
  }

  // Add the node type.
  _feedapi_node_install_type_create();
}

/**
 * Fix columns indeces.
 */
function feedapi_node_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} CHANGE fiid fiid INT( 10 ) UNSIGNED NOT NULL");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP PRIMARY KEY");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD PRIMARY KEY ( nid )");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( feed_nid )");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( fiid )");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( `url` ( 255 ) )");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( `guid` ( 255 ) )");
      $ret[] = update_sql("DELETE FROM {sequences} WHERE name = 'feedapi_node_item_fiid'");
      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('feedapi_node_item_fiid', (SELECT MAX(fiid) FROM {feedapi_node_item}) )");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE INDEX {fiid_index} on {feedapi_node_item}(fiid)");
      $ret[] = update_sql("CREATE INDEX {feed_nid_index} on {feedapi_node_item}(feed_nid)");
      $ret[] = update_sql("CREATE INDEX {url_index} on {feedapi_node_item}(url)");
      $ret[] = update_sql("CREATE INDEX {guid_index} on {feedapi_node_item}(guid)");
      break;
  }
  return $ret;
}

/**
 * Accept URLs > 255 char.
 */
function feedapi_node_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP INDEX url");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP INDEX guid");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} CHANGE url url TEXT CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} CHANGE guid guid TEXT CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( url ( 255 ) )");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ADD INDEX ( guid ( 255 ) )");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ALTER COLUMN url TYPE TEXT");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} ALTER COLUMN guid TYPE TEXT");
      break;
  }
  return $ret;
}

/**
 * Create and populate feed_nid / feed_item_nid table.
 */
function feedapi_node_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {feedapi_node_item_feed} (\n        `feed_nid` int(10) unsigned NOT NULL default '0',\n        `feed_item_nid` int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (`feed_nid`,`feed_item_nid`),\n        KEY `feed_nid` (`feed_nid`),\n        KEY `feed_item_nid` (`feed_item_nid`)\n        ) DEFAULT CHARSET=latin1;\n      ");
      $ret[] = update_sql("REPLACE INTO {feedapi_node_item_feed} (feed_nid, feed_item_nid) SELECT feed_nid, nid FROM {feedapi_node_item}");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP `feed_nid`");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {feedapi_node_item_feed} (\n        feed_nid integer NOT NULL default '0',\n        feed_item_nid integer NOT NULL default '0',\n        PRIMARY KEY  (feed_nid,feed_item_nid))\n      ");
      $ret[] = update_sql("CREATE INDEX feed_item_nid_index on {feedapi_node_item_feed}(feed_item_nid)");
      $ret[] = update_sql("INSERT INTO {feedapi_node_item_feed} (feed_nid, feed_item_nid) SELECT feed_nid, nid FROM {feedapi_node_item}");
      $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP feed_nid");
      break;
  }
  return $ret;
}

/**
 * Drop unwanted fiid field
 */
function feedapi_node_update_4() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP COLUMN fiid");
  return $ret;
}

/**
 * Fix missing index in the case of postgres database
 */
function feedapi_node_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE INDEX {feedapi_node_item}_arrived_idx ON {feedapi_node_item} (arrived)");
      break;
  }
  return $ret;
}
function feedapi_node_uninstall() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
    case 'pgsql':
      db_query("DROP TABLE {feedapi_node_item}");
      db_query("DROP TABLE {feedapi_node_item_feed}");
      break;
  }
  node_type_delete('feedapi_node');
  variable_del('feedapi_settings_feedapi_node');
  menu_rebuild();
}
function _feedapi_node_install_type_create() {

  // Create an additional node type.
  $feed_node_type = array(
    'type' => 'feed',
    'name' => t('Feed'),
    'module' => 'node',
    'description' => t('Items from these feeds will be turned into nodes.'),
    'custom' => TRUE,
    'modified' => TRUE,
    'locked' => FALSE,
  );
  $feed_node_type = (object) _node_type_set_defaults($feed_node_type);
  node_type_save($feed_node_type);

  // Default to not promoted.
  variable_set('node_options_feed', array(
    'status',
  ));

  // 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:1:{s:12:"feedapi_node";a:7:{s:7:"enabled";s:1:"1";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:"0";s:9:"list_feed";s:1:"3";s:4:"user";s:5:"admin";}}}');
  if (is_array(variable_get('feedapi_settings_feed', FALSE))) {
    $preset = array_merge($preset, variable_get('feedapi_settings_feed', FALSE));
  }
  variable_set('feedapi_settings_feed', $preset);
}

Functions

Namesort descending Description
feedapi_node_install
feedapi_node_uninstall
feedapi_node_update_1 Fix columns indeces.
feedapi_node_update_2 Accept URLs > 255 char.
feedapi_node_update_3 Create and populate feed_nid / feed_item_nid table.
feedapi_node_update_4 Drop unwanted fiid field
feedapi_node_update_5 Fix missing index in the case of postgres database
_feedapi_node_install_type_create