function event_install in Event 5.2
Same name and namespace in other branches
- 5 event.install \event_install()
File
- ./
event.install, line 27
Code
function event_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {event} (\n nid int(10) unsigned NOT NULL default '0',\n event_start datetime NOT NULL,\n event_end datetime NOT NULL,\n timezone int NOT NULL default '0',\n start_in_dst int NOT NULL default '0',\n end_in_dst int NOT NULL default '0',\n has_time int NOT NULL default '1',\n has_end_date int NOT NULL default '1',\n PRIMARY KEY (nid),\n KEY event_start (event_start),\n KEY event_end (event_end),\n KEY timezone (timezone)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {event_timezones} (\n timezone int NOT NULL default '0',\n name varchar(255) NOT NULL default '',\n offset TIME NOT NULL default '0',\n offset_dst TIME NOT NULL default '0',\n dst_region int NOT NULL default '0',\n is_dst int NOT NULL default '0',\n PRIMARY KEY (timezone)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("ALTER TABLE {users} ADD timezone_id int NOT NULL default '0'");
$zones = event_install_timezones();
foreach ($zones as $zone => $value) {
db_query("INSERT INTO {event_timezones} (timezone, name, offset, offset_dst, dst_region) VALUES (%d, '%s', '%s', '%s', %d)", $zone, $value['timezone'], $value['offset'], $value['offset_dst'], $value['dst_region']);
}
variable_del('event_range_prev');
variable_del('event_range_next');
break;
case 'pgsql':
db_query("CREATE TABLE {event} (\n nid integer NOT NULL default '0',\n event_start timestamp NOT NULL,\n event_end timestamp NOT NULL,\n timezone integer NOT NULL default '0',\n start_in_dst integer NOT NULL default '0',\n end_in_dst integer NOT NULL default '0',\n has_time integer NOT NULL default '1',\n has_end_date integer NOT NULL default '1',\n PRIMARY KEY (nid)\n ) ");
db_query("CREATE TABLE {event_timezones} (\n timezone integer NOT NULL default '0',\n name varchar(255) NOT NULL default '',\n \"offset\" interval NOT NULL default '0 seconds',\n offset_dst interval NOT NULL default '0 seconds',\n dst_region integer NOT NULL default '0',\n is_dst integer NOT NULL default '0',\n PRIMARY KEY (timezone)\n ) ");
db_query('CREATE INDEX {event}_event_start_idx ON {event} (event_start)');
db_query('CREATE INDEX {event}_event_end_idx ON {event} (event_end)');
db_query('CREATE INDEX {event}_timezone_idx ON {event} (timezone)');
db_query("ALTER TABLE {users} ADD timezone_id int NOT NULL default '0'");
$zones = event_install_timezones();
foreach ($zones as $zone => $value) {
db_query("INSERT INTO {event_timezones} (timezone, name, \"offset\", offset_dst, dst_region) VALUES (%d, '%s', '%s', '%s', %d)", $zone, $value['timezone'], $value['offset'], $value['offset_dst'], $value['dst_region']);
}
break;
}
// Create default event type
$type = array(
'type' => 'event',
'name' => t('Event'),
'module' => 'node',
'description' => t('Events have a start date and an optional end date as well as a teaser and a body. They can be extended by other modules, too.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
);
$type = (object) _node_type_set_defaults($type);
node_type_save($type);
variable_set('event_nodeapi_event', 'all');
// Notify of changes
drupal_set_message(t('Event module was successfully installed with default options. To customize event and/or location settings for events, please view the <a href="!settings">event content type settings page</a>. Make sure to <a href="!url">select the default timezone</a> for your website before creating events.', array(
'!settings' => url('admin/content/types/event'),
'!url' => url('admin/settings/date-time'),
)));
drupal_set_message('A content type "event" was created.');
}