summaryrefslogtreecommitdiff
path: root/modules/contact/contact.install
blob: 3c4e934a736b8dcdc5213817a67b84bba62c8e0b (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// $Id$

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

/**
 * Implements 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.',
        'translatable' => TRUE,
      ),
      '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,
        '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;
}

/**
 * Implements 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();
}

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

/**
 * @addtogroup updates-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() {
  // Do not use user_role_grant_permission() since it relies on
  // hook_permission(), which will not run for contact module if it is
  // disabled.
  db_merge('role_permission')
    ->key(array(
      'rid' => DRUPAL_AUTHENTICATED_RID,
      'permission' => 'access user contact forms',
      'module' => 'contact',
    ))
    ->execute();
}

/**
 * Change the weight column to normal int.
 */
function contact_update_7003() {
  db_drop_index('contact', 'list');
  db_change_field('contact', 'weight', 'weight', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => "The category's weight.",
  ), array(
    'indexes' => array(
      'list' => array('weight', 'category'),
    ),
  ));
}

/**
 * @} End of "addtogroup updates-6.x-to-7.x"
 */