View source
<?php
function simplenews_install() {
$result = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$result[] = db_query("CREATE TABLE {simplenews_subscriptions} (\n snid int(10) NOT NULL auto_increment,\n a_status int(2) NOT NULL default '0',\n s_status int(2) NOT NULL default '0',\n mail varchar(64) NOT NULL default '',\n uid int(10) NOT NULL default '0',\n PRIMARY KEY (snid),\n KEY mail (mail)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$result[] = db_query("CREATE TABLE {simplenews_newsletters} (\n nid int(10) NOT NULL default '0',\n vid int(10) NOT NULL default '0',\n tid int(10) NOT NULL default '0',\n s_status int(2) NOT NULL default '0',\n s_format varchar(8) NOT NULL default '',\n priority int(2) NOT NULL default '0',\n receipt int(2) NOT NULL default '0',\n PRIMARY KEY (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$result[] = db_query("CREATE TABLE {simplenews_snid_tid} (\n snid int(10) NOT NULL default '0',\n tid int(10) NOT NULL default '0',\n PRIMARY KEY (snid,tid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
$result[] = db_query("CREATE TABLE {simplenews_subscriptions} (\n snid SERIAL,\n a_status smallint NOT NULL default '0',\n s_status smallint NOT NULL default '0',\n mail varchar(64) NOT NULL default '',\n uid integer NOT NULL default '0',\n PRIMARY KEY (snid)\n );");
$result[] = db_query('CREATE INDEX {simplenews_subscriptions}_mail_idx ON {simplenews_subscriptions} (mail)');
$result[] = db_query("CREATE TABLE {simplenews_newsletters} (\n nid integer NOT NULL default '0',\n vid integer NOT NULL default '0',\n tid integer NOT NULL default '0',\n s_status smallint NOT NULL default '0',\n s_format varchar(8) NOT NULL default '',\n priority smallint NOT NULL default '0',\n receipt smallint NOT NULL default '0',\n PRIMARY KEY (nid)\n );");
$result[] = db_query("CREATE TABLE {simplenews_snid_tid} (\n snid integer NOT NULL default '0',\n tid integer NOT NULL default '0',\n PRIMARY KEY (snid,tid)\n );");
break;
case 'mssql':
$result[] = db_query("CREATE TABLE {simplenews_subscriptions} (\n snid int NOT NULL IDENTITY(1,1),\n a_status int NOT NULL default '0',\n s_status int NOT NULL default '0',\n mail varchar(64) NOT NULL default '',\n uid int NOT NULL default '0',\n PRIMARY KEY (snid)\n );");
$result[] = db_query("CREATE TABLE {simplenews_newsletters} (\n nid int NOT NULL default '0',\n tid int NOT NULL default '0',\n s_status int NOT NULL default '0',\n s_format varchar(8) NOT NULL default '',\n priority int NOT NULL default '0',\n receipt int NOT NULL default '0',\n PRIMARY KEY (nid)\n );");
$result[] = db_query("CREATE TABLE {simplenews_snid_tid} (\n snid int NOT NULL default '0',\n tid int NOT NULL default '0',\n PRIMARY KEY (snid,tid)\n );");
break;
}
if (count($result) != count(array_filter($result))) {
drupal_set_message(t('The installation of the Simplenews module was unsuccessful.'), 'error');
}
}
function simplenews_enable() {
if ($vocabulary = taxonomy_get_vocabulary(variable_get('simplenews_vid', ''))) {
$vocabulary = (array) $vocabulary;
$vocabulary['nodes']['simplenews'] = 1;
unset($vocabulary['nodes'][0]);
taxonomy_save_vocabulary($vocabulary);
}
else {
$vocabulary = array(
'name' => t('Newsletter'),
'multiple' => '0',
'required' => '0',
'hierarchy' => '0',
'relations' => '0',
'module' => 'simplenews',
'nodes' => array(
'simplenews' => 1,
),
);
taxonomy_save_vocabulary($vocabulary);
variable_set('simplenews_vid', $vocabulary['vid']);
}
$tid = db_result(db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vocabulary['vid']));
if (!$tid) {
$form_values = array(
'name' => variable_get('site_name', 'Drupal') . ' ' . t('newsletter'),
'vid' => $vocabulary['vid'],
'weight' => 0,
);
switch (taxonomy_save_term($form_values)) {
case SAVED_UPDATED:
drupal_set_message(t('Updated term %name.', array(
'%name' => $form_values['name'],
)));
break;
case SAVED_DELETED:
drupal_set_message(t('Deleted term %name.', array(
'%name' => $form_values['name'],
)));
break;
}
}
}
function simplenews_uninstall() {
db_query('DROP TABLE {simplenews_snid_tid}');
db_query('DROP TABLE {simplenews_newsletters}');
db_query('DROP TABLE {simplenews_subscriptions}');
db_query("DELETE FROM {variable} WHERE name LIKE 'simplenews_%%'");
}
function simplenews_update_1() {
return _system_update_utf8(array(
'sn_snid_tid',
'sn_newsletters',
'sn_subscriptions',
));
}
function simplenews_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql('ALTER TABLE {sn_snid_tid} RENAME TO {simplenews_snid_tid}');
$ret[] = update_sql('ALTER TABLE {sn_newsletters} RENAME TO {simplenews_newsletters}');
$ret[] = update_sql('ALTER TABLE {sn_subscriptions} RENAME TO {simplenews_subscriptions}');
break;
}
return $ret;
}
function simplenews_update_5000() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {simplenews_subscriptions} ADD INDEX mail (mail);");
break;
case 'pgsql':
$ret[] = update_sql('CREATE INDEX {simplenews_subscriptions}_mail_idx ON {simplenews_subscriptions} (mail)');
break;
}
return $ret;
}
function simplenews_update_5001() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {simplenews_newsletters} ADD vid int(10) NOT NULL default '0'");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {simplenews_newsletters} ADD vid int NOT NULL default '0'");
break;
}
return $ret;
}