function subscriptions_update_3 in Subscriptions 6
Same name and namespace in other branches
- 5.2 subscriptions.install \subscriptions_update_3()
Database update function 3 for 5.x-2.0 rewrite.
File
- ./
subscriptions.install, line 195 - Subscriptions module installation.
Code
function subscriptions_update_3() {
$ret = array();
$t = get_t();
if (db_table_exists('subscriptions_holding')) {
db_drop_table($ret, 'subscriptions_holding');
// old left-over from 5.x-1.x
}
if (db_table_exists('subscriptions_sent')) {
// old left-over from first
db_drop_table($ret, 'subscriptions_sent');
// incarnation of 5.x-2.0
}
if (db_table_exists('subscriptions_old')) {
db_drop_table($ret, 'subscriptions_old');
}
db_rename_table($ret, subscriptions, subscriptions_old);
$schema['subscriptions'] = array(
'fields' => array(
'sid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'module' => array(
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
),
'field' => array(
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
),
'value' => array(
'type' => 'varchar',
'length' => '237',
'not null' => FALSE,
),
'recipient_uid' => array(
'type' => 'int',
'not null' => TRUE,
),
'send_interval' => array(
'type' => 'int',
'not null' => FALSE,
),
'author_uid' => array(
'type' => 'int',
'not null' => TRUE,
),
'send_updates' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'send_comments' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'sid',
),
'indexes' => array(
'module' => array(
'module',
'field',
'value',
),
'recipient_uid' => array(
'recipient_uid',
),
),
);
db_create_table($ret, 'subscriptions', $schema['subscriptions']);
$ret[] = update_sql("INSERT INTO {subscriptions}\n (module, field, value, recipient_uid, send_interval, author_uid, send_updates, send_comments)\n SELECT 'node', 'nid', sid, uid, send_interval, -1, 0, 1\n FROM {subscriptions_old}\n WHERE stype = 'node'");
$ret[] = update_sql("INSERT INTO {subscriptions}\n (module, field, value, recipient_uid, send_interval, author_uid, send_updates, send_comments)\n SELECT 'node', 'tid', sid, uid, send_interval, -1, 0, 1\n FROM {subscriptions_old}\n WHERE stype = 'taxa'");
$ret[] = update_sql("INSERT INTO {subscriptions}\n (module, field, value, recipient_uid, send_interval, author_uid, send_updates, send_comments)\n SELECT 'node', 'type', SUBSTRING(stype FROM 5), uid, send_interval, -1, 0, 1\n FROM {subscriptions_old}\n WHERE stype LIKE 'type%'");
$ret[] = update_sql("UPDATE {subscriptions} SET send_interval = 1 WHERE send_interval < 1");
db_drop_table($ret, 'subscriptions_old');
$schema['subscriptions_queue'] = array(
'fields' => array(
'sqid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'type' => 'int',
'not null' => FALSE,
),
'name' => array(
'type' => 'varchar',
'length' => '60',
'not null' => FALSE,
),
'mail' => array(
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
),
'language' => array(
'type' => 'varchar',
'length' => '12',
'not null' => FALSE,
),
'module' => array(
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
),
'field' => array(
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
),
'value' => array(
'type' => 'varchar',
'length' => '237',
'not null' => FALSE,
),
'author_uid' => array(
'type' => 'int',
'not null' => FALSE,
),
'send_interval' => array(
'type' => 'int',
'not null' => FALSE,
),
'digest' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
),
'load_args' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'load_function' => array(
'type' => 'varchar',
'length' => '60',
'not null' => TRUE,
'default' => '',
),
'last_sent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'sqid',
),
'indexes' => array(
'load_args' => array(
'load_args',
'load_function',
'uid',
),
),
);
db_create_table($ret, 'subscriptions_queue', $schema['subscriptions_queue']);
$schema['subscriptions_user'] = array(
'fields' => array(
'uid' => array(
'type' => 'int',
'not null' => TRUE,
),
'digest' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => -1,
),
'last_sent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'uid',
),
);
db_create_table($ret, 'subscriptions_user', $schema['subscriptions_user']);
$ret[] = update_sql("INSERT INTO {subscriptions_user} (uid) SELECT uid FROM {users} WHERE uid > 0");
include_once drupal_get_path('module', 'subscriptions') . '/subscriptions.install.inc';
_subscriptions_install_information();
return $ret;
}