datereminder.install in Date Reminder 6.2
Same filename and directory in other branches
Stuff Druapl needs to install this module.
File
datereminder.installView source
<?php
/**
* @file
* Stuff Druapl needs to install this module.
*/
/**
* Implements hook_install().
*/
function datereminder_install() {
content_notify('install', 'datereminder');
$ret = drupal_install_schema('datereminder');
return $ret;
}
/**
* Implements hook_uninstall().
*/
function datereminder_uninstall() {
$ret = drupal_uninstall_schema('datereminder');
content_notify('uninstall', 'datereminder');
// Probably could do this by getting a list of all content types.
$variables = db_query("SELECT name FROM {variable} WHERE name LIKE 'datereminder%%'");
while ($variable = db_fetch_object($variables)) {
variable_del($variable->name);
}
return $ret;
}
/**
* Implements hook_enable().
*
* Notify content module when this module is enabled.
*/
function datereminder_enable() {
content_notify('enable', 'datereminder');
}
/**
* Implements hook_disable().
*
* Notify content module when this module is disabled.
*/
function datereminder_disable() {
content_notify('disable', 'datereminder');
}
/**
* Implements hook_schema().
*
* Tell Drupal about database tables and content.
*/
function datereminder_schema() {
$schema['datereminder_enable'] = array(
'description' => 'Reminder per-node enable flags',
'fields' => array(
'nid' => array(
'description' => 'Primary key: node id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'enabled' => array(
'description' => '0: No reminders, 1: Saved reminders, 3: Allow reminders',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
),
);
$schema['datereminder'] = array(
'description' => "Information on user's reminders",
'fields' => array(
'rid' => array(
'description' => 'Primary key, reminder id',
'type' => 'serial',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'node id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'user id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'leadtime' => array(
'description' => 'How long before event to send reminder in seconds',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'email' => array(
'description' => 'If allowed, alternate email address',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'expired' => array(
'description' => "If TRUE, delete after 'next'",
'type' => 'int',
'size' => 'tiny',
'default' => '0',
'not null' => TRUE,
),
'next_due' => array(
'description' => 'Time for reminder as Unix epoch',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'rid',
),
'indexes' => array(
'uid' => array(
'uid',
),
'nid' => array(
'nid',
),
),
);
return $schema;
}
/**
* Adding new 'expired' field.
*/
function datereminder_update_6003() {
$ret = array();
$fd = array(
'description' => "If TRUE, delete after 'next'",
'type' => 'int',
'size' => 'tiny',
'default' => '0',
'not null' => TRUE,
);
db_add_field($ret, 'datereminder', 'expired', $fd);
return $ret;
}
/**
* Convert `next` from datestamp to Unix timestamp.
*/
function datereminder_update_6200() {
$ret = array();
// First, add field to hold converted values.
$fd = array(
'description' => 'Time for reminder as Unix epoch',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
db_add_field($ret, 'datereminder', 'next_due', $fd);
// The following forces Drupal to start using the new schema. That's
// necessary for drupal_write_record() to write out the new field.
drupal_get_schema('datereminder', TRUE);
// Now, read all records and generate new value.
$utc = new DateTimeZone('UTC');
$q = db_query('SELECT * from {datereminder}');
while ($r = db_fetch_object($q)) {
$next_due = DateTime::createFromFormat('Y-m-d H:i:s', $r->next, $utc);
$r->next_due = intval($next_due
->format('U'));
drupal_write_record('datereminder', $r, 'rid');
}
// Get rid of old 'next' field. Henceforth, we'll use only next_due.
db_drop_field($ret, 'datereminder', 'next');
return $ret;
}
Functions
Name![]() |
Description |
---|---|
datereminder_disable | Implements hook_disable(). |
datereminder_enable | Implements hook_enable(). |
datereminder_install | Implements hook_install(). |
datereminder_schema | Implements hook_schema(). |
datereminder_uninstall | Implements hook_uninstall(). |
datereminder_update_6003 | Adding new 'expired' field. |
datereminder_update_6200 | Convert `next` from datestamp to Unix timestamp. |