mass_contact.install in Mass Contact 7
Same filename and directory in other branches
Install, update and uninstall functions for the Mass Contact module.
This module enables users to send messages (contact) to multiple users through selected roles.
File
mass_contact.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Mass Contact module.
*
* This module enables users to send messages (contact) to multiple users
* through selected roles.
*/
/**
* Implements hook_schema().
*/
function mass_contact_schema() {
$schema['mass_contact'] = array(
'description' => 'The base table for nodes.',
'fields' => array(
'cid' => array(
'description' => 'The primary id field for the category table.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'category' => array(
'description' => 'The name of the category.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'recipients' => array(
'description' => 'Field that has information about users to receive the message.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'reply' => array(
'description' => '.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'weight' => array(
'description' => 'The order this category is in.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
'selected' => array(
'description' => 'Whether this category is selected by default or not.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'cid',
),
'unique keys' => array(
'category' => array(
'category',
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function mass_contact_install() {
// Use get_t() to get the name of the localization function for translation
// during install. For use when t() is not available.
$t = get_t();
// Define the node type.
$node_type_definition = array(
'type' => 'mass_contact',
'name' => $t('Mass Contact message'),
'base' => 'node_content',
'description' => $t('Archived copies of mass email messages sent from this site.'),
'custom' => 1,
'modified' => 1,
'title_label' => $t('Subject'),
'status' => 0,
'promote' => 0,
'sticky' => 0,
'comment' => 0,
);
// Complete the node type definition by setting any defaults not explicitly
// declared above.
$mass_contact_node_type = node_type_set_defaults($node_type_definition);
// Add the body field to the node type.
node_add_body_field($mass_contact_node_type, $t('Message body'));
// Save the node type.
node_type_save($mass_contact_node_type);
// Load the instance definition for the node type's body.
$body_instance = field_info_instance('node', 'body', 'mass_contact');
// Save the changes to the body field instance.
field_update_instance($body_instance);
// Create all the fields that are being adding to the node type.
foreach (_mass_contact_fields() as $field) {
field_create_field($field);
}
// Create all the instances for the fields.
foreach (_mass_contact_field_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = $node_type_definition['type'];
field_create_instance($instance);
}
}
/**
* Returns a structured array, defining the fields created by this node type.
*/
function _mass_contact_fields() {
return array(
'field_mass_contact_from' => array(
'field_name' => 'field_mass_contact_from',
'type' => 'text',
),
'field_mass_contact_category' => array(
'field_name' => 'field_mass_contact_category',
'type' => 'text',
),
'field_mass_contact_to' => array(
'field_name' => 'field_mass_contact_to',
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
'field_mass_contact_bcc' => array(
'field_name' => 'field_mass_contact_bcc',
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
'field_mass_contact_headers' => array(
'field_name' => 'field_mass_contact_headers',
'type' => 'text_long',
),
'field_mass_contact_result' => array(
'field_name' => 'field_mass_contact_result',
'type' => 'text_long',
),
'field_mass_contact_attachments' => array(
'field_name' => 'field_mass_contact_attachments',
'type' => 'file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
);
}
/**
* Returns a structured array, defining the instances for this node type.
*/
function _mass_contact_field_instances() {
$t = get_t();
return array(
'field_mass_contact_from' => array(
'field_name' => 'field_mass_contact_from',
'label' => $t('From'),
'description' => $t('The person who sent the message.'),
'required' => 1,
'widget' => array(
'type' => 'text_textfield',
'weight' => -10,
),
'display' => array(
'default' => array(
'weight' => -10,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_category' => array(
'field_name' => 'field_mass_contact_category',
'label' => $t('Category'),
'description' => $t('The Mass Contact category of users sent to.'),
'widget' => array(
'type' => 'text_textfield',
'weight' => -9,
),
'display' => array(
'default' => array(
'weight' => -9,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_to' => array(
'field_name' => 'field_mass_contact_to',
'label' => $t('To'),
'description' => $t('The person or people the message was sent to.'),
'required' => 1,
'widget' => array(
'type' => 'text_textfield',
'weight' => -8,
),
'display' => array(
'default' => array(
'weight' => -8,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_bcc' => array(
'field_name' => 'field_mass_contact_bcc',
'label' => $t('BCC'),
'description' => $t('The person or people the message was blind copied to.'),
'widget' => array(
'type' => 'text_textfield',
'weight' => -7,
),
'display' => array(
'default' => array(
'weight' => -7,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_headers' => array(
'field_name' => 'field_mass_contact_headers',
'label' => $t('Headers'),
'description' => $t('Any other headers that were created by the Mass Contact module.'),
'widget' => array(
'type' => 'text_textarea',
'weight' => -6,
),
'display' => array(
'default' => array(
'weight' => -6,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_result' => array(
'field_name' => 'field_mass_contact_result',
'label' => $t('Result'),
'description' => $t('The result of sending this message.'),
'widget' => array(
'type' => 'text_textarea',
'weight' => 5,
),
'display' => array(
'default' => array(
'weight' => 5,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
'field_mass_contact_attachments' => array(
'field_name' => 'field_mass_contact_attachments',
'label' => $t('Attachments'),
'description' => $t('Any attachments that were included in the message.'),
'widget' => array(
'type' => 'file',
'weight' => 10,
),
'display' => array(
'default' => array(
'weight' => 10,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
);
}
/**
* Implements hook_uninstall().
*/
function mass_contact_uninstall() {
// Delete all of the variables defined by this module.
db_delete('variable')
->condition('name', 'mass_contact_%', 'LIKE')
->execute();
// Delete all of the fields defined by this module.
foreach (array_keys(_mass_contact_fields()) as $field) {
field_delete_field($field);
}
// Delete all the field instances attached to the mass_contact node type.
$instances = field_info_instances('node', 'mass_contact');
foreach ($instances as $instance) {
field_delete_instance($instance);
}
// Delete the node type.
node_type_delete('mass_contact');
// Purge all field information.
field_purge_batch(1000);
}
/**
* Update the Attachment location setting, when upgrading from 6.x.
*/
function mass_contact_update_7000(&$sandbox) {
$attachment_location = variable_get('mass_contact_attachment_location');
// If the setting was set to the 6.x default, update it to the 7.x default.
if (!empty($attachment_location) && $attachment_location == 'sites/default/files/mass_contact_attachments') {
variable_set('mass_contact_attachment_location', 'mass_contact_attachments');
}
else {
drupal_set_message(t('The path to the Mass Contact attachments was not set to the default setting. Since Drupal
7 changed the way it handles paths from Drupal 6, please check the <a href="@attachment-page">Attachment
location</a> setting and change it to something that will work with Drupal 7.', array(
'@attachment-page' => url('admin/config/system/mass_contact/settings/body'),
)), 'warning');
}
}
/**
* Remove variables that were converted into permissions.
*
* Read CHANGELOG.txt before continuing.
*/
function mass_contact_update_7100(&$sandbox) {
variable_del('mass_contact_bcc_d_override');
variable_del('mass_contact_default_sender_changable');
variable_del('mass_contact_html_format_override');
variable_del('mass_contact_nodecc_d_override');
}
/**
* Move mass_contact.recipients database field to serialized data.
*/
function mass_contact_update_7101(&$sandbox) {
$records = db_query('SELECT cid, recipients FROM {mass_contact}');
foreach ($records as $record) {
$recipients = serialize(array(
'mass_contact_role' => explode(',', $record->recipients),
));
db_query('UPDATE {mass_contact} SET recipients = :recipients WHERE cid = :cid', array(
':cid' => $record->cid,
':recipients' => $recipients,
));
}
}
Functions
Name | Description |
---|---|
mass_contact_install | Implements hook_install(). |
mass_contact_schema | Implements hook_schema(). |
mass_contact_uninstall | Implements hook_uninstall(). |
mass_contact_update_7000 | Update the Attachment location setting, when upgrading from 6.x. |
mass_contact_update_7100 | Remove variables that were converted into permissions. |
mass_contact_update_7101 | Move mass_contact.recipients database field to serialized data. |
_mass_contact_fields | Returns a structured array, defining the fields created by this node type. |
_mass_contact_field_instances | Returns a structured array, defining the instances for this node type. |