Index: subscriptions.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/subscriptions/subscriptions.install,v retrieving revision 1.3.2.1 diff -u -r1.3.2.1 subscriptions.install --- subscriptions.install 1 Mar 2007 16:33:23 -0000 1.3.2.1 +++ subscriptions.install 18 Aug 2007 19:15:10 -0000 @@ -10,12 +10,19 @@ op tinytext NOT NULL, pid int(11) NOT NULL default '0', PRIMARY KEY (`rid`) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); db_query("CREATE TABLE {subscriptions} ( sid int(10) unsigned NOT NULL, uid int(10) unsigned NOT NULL, - stype varchar(25) NOT NULL + stype varchar(25) NOT NULL, + send_interval int(10) unsigned NOT NULL default '0' + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + db_query("CREATE TABLE {subscriptions_sent} ( + uid int(10) unsigned NOT NULL, + last_sent int(10) unsigned NOT NULL default '0', + PRIMARY KEY (uid) ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + db_query("INSERT INTO {subscriptions_sent} (uid, last_sent) SELECT uid, 0 FROM {users} WHERE uid > 0"); drupal_set_message(t('Subscriptions database tables have been installed.')); break; case 'pgsql': @@ -29,10 +36,67 @@ db_query("CREATE TABLE {subscriptions} ( sid integer NOT NULL, uid integer NOT NULL, - stype text NOT NULL + stype text NOT NULL, + send_interval integer NOT NULL + )"); + db_query("CREATE TABLE {subscriptions_sent} ( + uid integer NOT NULL, + last_sent integer NOT NULL default '0', + PRIMARY KEY (uid) )"); - drupal_set_message(t('Subscriptions database tables have been installed.')); + db_query("INSERT INTO {subscriptions_sent} (uid, last_sent) SELECT uid, 0 FROM {users} WHERE uid > 0"); + drupal_set_message(t('Subscriptions database tables have been installed.')); break; } } + +function subscriptions_uninstall() { + if (db_table_exists('subscriptions')) { + db_query("DROP TABLE {subscriptions}"); + } + if (db_table_exists('subscriptions_holding')) { + db_query("DROP TABLE {subscriptions_holding}"); + } + if (db_table_exists('subscriptions_sent')) { + db_query("DROP TABLE {subscriptions_sent}"); + } + drupal_set_message(t('Subscriptions database tables have been removed.')); +} + + +/* + * update module for version 5.x-2.x. + */ +function subscriptions_update_1() { + $ret = array(); + + switch($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {subscriptions_sent} ( + uid int(10) unsigned NOT NULL, + last_sent int(10) unsigned NOT NULL default '0', + PRIMARY KEY (uid) + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + $ret[] = update_sql("INSERT INTO {subscriptions_sent} (uid, last_sent) SELECT uid, 0 FROM {users} WHERE uid > 0"); + $ret[] = update_sql("ALTER TABLE {subscriptions} ADD send_interval int(10) unsigned default '0' NOT NULL"); + break; + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {subscriptions_sent} ( + uid integer NOT NULL, + last_sent integer NOT NULL default '0', + PRIMARY KEY (uid) + )"); + $ret[] = update_sql("INSERT INTO {subscriptions_sent} (uid, last_sent) SELECT uid, 0 FROM {users} WHERE uid > 0"); + db_add_column($ret, 'subscriptions', 'send_interval', 'integer', array('default' => 0, 'not null' => TRUE)); + break; + } + + if (variable_get('subscriptions_usecron', 0)) { + $ret[] = update_sql("UPDATE {subscriptions} SET send_interval = 1"); + } + variable_del('subscriptions_usecron'); + return $ret; +} + ?>