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;
}
_feedapi_node_install_type_create();
}
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;
}
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;
}
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;
}
function feedapi_node_update_4() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {feedapi_node_item} DROP COLUMN fiid");
return $ret;
}
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() {
$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);
variable_set('node_options_feed', array(
'status',
));
$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);
}