summaryrefslogtreecommitdiff
path: root/modules/contact/contact.install
blob: ac245d5866589ffcfb5a47a15c86a835af3f2341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the contact module.
 */

/**
 * Implement hook_schema().
 */
function contact_schema() {
  $schema['contact'] = array(
    'description' => 'Contact form category settings.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique category ID.',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Category name.',
      ),
      'recipients' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Comma-separated list of recipient e-mail addresses.',
      ),
      'reply' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Text of the auto-reply message.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => "The category's weight.",
      ),
      'selected' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)',
      ),
    ),
    'primary key' => array('cid'),
    'unique keys' => array(
      'category' => array('category'),
    ),
    'indexes' => array(
      'list' => array('weight', 'category'),
    ),
  );

  return $schema;
}

/**
 * Implement hook_install().
 */
function contact_install() {
  // Insert a default contact category.
  db_insert('contact')
    ->fields(array(
      'category' => 'Website feedback',
      'recipients' => variable_get('site_mail', ini_get('sendmail_from')),
      'selected' => 1,
      'reply' => '',
    ))
    ->execute();
}

/**
 * Implement hook_uninstall().
 */
function contact_uninstall() {
  variable_del('contact_default_status');
  variable_del('contact_threshold_limit');
  variable_del('contact_threshold_window');
}

/**
 * @defgroup updates-6.x-to-7.x Contact updates from 6.x to 7.x
 * @{
 */

/**
 * Rename the threshold limit variable.
 */
function contact_update_7000() {
  variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
  variable_del('contact_hourly_threshold');
}

/**
 * Rename the administer contact forms permission.
 */
function contact_update_7001() {
  db_update('role_permission')
    ->fields(array('permission' => 'administer contact forms'))
    ->condition('permission', 'administer site-wide contact form')
    ->execute();
}

/**
 * Enable the 'access user contact forms' for registered users by default.
 */
function contact_update_7002() {
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access user contact forms'));
}

/**
 * @} End of "defgroup updates-6.x-to-7.x"
 * The next series of updates should start at 8000.
 */