node_registration.install in Node registration 7
Install, uninstall, enable and disable hooks and schema.
File
node_registration.installView source
<?php
/**
* @file
* Install, uninstall, enable and disable hooks and schema.
*/
/**
* Implements hook_uninstall().
*
* Delete variables.
*/
function node_registration_uninstall() {
// Delete variables.
$vars = db_query('SELECT name FROM {variable} WHERE name LIKE ?', array(
'node\\_registration\\_%',
));
foreach ($vars as $var) {
watchdog('registration', 'deleting var: @var', array(
'@var' => $var->name,
));
variable_del($var->name);
}
}
/**
* Implements hook_schema().
*
* Define 2 tables: node_registration, node_registration_node.
*/
function node_registration_schema() {
$schema['node_registration'] = array(
'description' => 'The base table for node_registration module.',
'fields' => array(
'registration_id' => array(
'description' => 'The primary identifier for a registration.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The bundle type of this registration.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'node_type' => array(
'description' => "The node type of this registrations.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'nid' => array(
'description' => 'The id of the entity this registration is associated with.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'email' => array(
'description' => "User's e-mail address.",
'type' => 'varchar',
'length' => 254,
'not null' => TRUE,
'default' => '',
),
'slots' => array(
'description' => 'How many slots this registration should use towards the total capacity for this event.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'author_uid' => array(
'description' => 'The uid of the user who created this registration.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'The uid of the registree.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'The Unix timestamp when the registration was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'updated' => array(
'description' => 'The Unix timestamp when the registration was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'attended' => array(
'description' => 'Whether the registree attended the event.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'secret' => array(
'description' => 'A secret for anonymous users to cancel etc with.',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
),
'reminder_sent' => array(
'description' => 'The timestamp when a reminder was sent to the registree.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'verified' => array(
'description' => 'Whether the user was verified.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'cancelled' => array(
'description' => 'The timestamp when this registration was cancelled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'waitinglist' => array(
'description' => 'Whether this registration is on the waitinglist.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'weight' => array(
'description' => 'Used for waitinglist execution order and display.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'registration_updated' => array(
'updated',
),
'registration_created' => array(
'created',
),
'registration_type' => array(
array(
'type',
4,
),
),
'registration_cancelled' => array(
'cancelled',
),
),
'foreign keys' => array(
'registration_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
),
),
'registration_author' => array(
'table' => 'users',
'columns' => array(
'author_uid' => 'uid',
),
),
),
'unique keys' => array(),
'primary key' => array(
'registration_id',
),
);
$schema['node_registration_node'] = array(
'description' => 'Node registration node settings.',
'fields' => array(
'nid' => array(
'description' => 'Node id these registration settings are for.',
'type' => 'int',
'not null' => TRUE,
),
'capacity' => array(
'description' => 'Maximum number of users who can signup for this event.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
),
'status' => array(
'description' => 'Boolean indicating if signups are open (1) or closed (0) for the given node',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'start_date' => array(
'description' => 'DEPRECATED: Start date (opening) of registrations',
'type' => 'text',
'mysql_type' => 'date',
'pgsql_type' => 'date',
'not null' => FALSE,
'default' => NULL,
),
'private_fields' => array(
'description' => 'Whether this node has node specific fields.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
),
'settings' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized object that stores additional registration settings.',
),
),
'foreign keys' => array(
'registration_node_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
),
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
/**
* Drop UNIQUE index `nid-email`.
*/
function node_registration_update_6() {
db_drop_index('node_registration', 'nid_mail');
}
/**
* Add column `waitinglist` to `node_registration`.
*/
function node_registration_update_7() {
db_add_field('node_registration', 'waitinglist', array(
'description' => 'Whether this registration is on the waitinglist.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Make column `capacity` nullable.
*/
function node_registration_update_8() {
db_change_field('node_registration_node', 'capacity', 'capacity', array(
'description' => 'Maximum number of users who can signup for this event.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
));
}
/**
* Add column `private_fields`.
*/
function node_registration_update_9() {
db_add_field('node_registration_node', 'private_fields', array(
'description' => 'Whether this node has node specific fields.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
));
}
/**
* Add column `node_type`.
*/
function node_registration_update_10() {
db_add_field('node_registration', 'node_type', array(
'description' => "The registration's node type.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
}
/**
* Remove `registration_email` fields and notify about deprecated tokens.
*/
function node_registration_update_11() {
// Find field instances: `registration_email`.
$instances = field_read_instances(array(
'field_name' => 'registration_email',
));
// Delete those instances.
foreach ($instances as $instance) {
field_delete_instance($instance);
}
$token_warnings = array();
// Find tokens in registration type settings.
$bundles_info = field_info_bundles('node_registration');
$vars = db_query('SELECT name FROM {variable} WHERE name LIKE :name AND value LIKE :value', array(
':name' => 'node\\_registration\\_%',
':value' => '%[node-registration:registration_email]%',
));
foreach ($vars as $var_name) {
$var_name = $var_name->name;
$registration_type_name = substr($var_name, strlen('node_registration_type_settings_'));
if (isset($bundles_info[$registration_type_name])) {
$registration_type = $bundles_info[$registration_type_name];
$title = $registration_type['label'];
$href = 'admin/structure/node_registration/manage/' . $registration_type_name . '/settings';
$token_warnings[] = l($title, $href);
}
}
// Find tokens in node settings.
$nodes = db_query('SELECT nid FROM {node_registration_node} WHERE settings LIKE :value', array(
':value' => '%[node-registration:registration_email]%',
));
foreach ($nodes as $node_settings) {
$title = 'Node ' . $node_settings->nid;
$href = 'node/' . $node_settings->nid . '/node_registration/settings';
$token_warnings[] = l($title, $href);
}
// Notify about these settings.
if ($token_warnings) {
$t = get_t();
$message = $t('The following settings still use the token "[node-registration:registration_email]" or "[node-registration:registration-email]": !settings_links. That\'s deprecated and MUST be changed to "[node-registration:email]".', array(
'!settings_links' => implode(', ', $token_warnings),
));
return $message;
}
}
/**
* Enable nr_fields IF private fields are being used anywhere.
*/
function node_registration_update_12() {
$count = db_query('SELECT COUNT(1) FROM {node_registration_node} WHERE private_fields <> 0');
if ($count) {
module_enable(array(
'nr_fields',
));
}
}
/**
* Create `weight` column and fill it.
*/
function node_registration_update_13() {
db_add_field('node_registration', 'weight', array(
'description' => 'Used for waitinglist execution order and display.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
$registrations = db_query('SELECT registration_id, nid FROM {node_registration} ORDER BY nid ASC, registration_id ASC')
->fetchAllKeyed();
$weight = $last_nid = 0;
foreach ($registrations as $rid => $nid) {
if ($nid != $last_nid) {
$weight = 0;
}
$last_nid = $nid;
db_update('node_registration')
->fields(array(
'weight' => $weight,
))
->condition('registration_id', $rid)
->execute();
$weight++;
}
}
/**
* WARN about removing custom mail action, USE SYSTEM MAIL ACTION!
*/
function node_registration_update_14() {
drupal_set_message(t("Node Registration REMOVED THE CUSTOM MAIL ACTION. If you want to mail registrees, USE THE SYSTEM MAIL ACTION."));
}
Functions
Name | Description |
---|---|
node_registration_schema | Implements hook_schema(). |
node_registration_uninstall | Implements hook_uninstall(). |
node_registration_update_10 | Add column `node_type`. |
node_registration_update_11 | Remove `registration_email` fields and notify about deprecated tokens. |
node_registration_update_12 | Enable nr_fields IF private fields are being used anywhere. |
node_registration_update_13 | Create `weight` column and fill it. |
node_registration_update_14 | WARN about removing custom mail action, USE SYSTEM MAIL ACTION! |
node_registration_update_6 | Drop UNIQUE index `nid-email`. |
node_registration_update_7 | Add column `waitinglist` to `node_registration`. |
node_registration_update_8 | Make column `capacity` nullable. |
node_registration_update_9 | Add column `private_fields`. |