Projet

Général

Profil

Paste
Télécharger (6,36 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / comment_notify / comment_notify.install @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * comment_notify.install.
5
 */
6

    
7
/**
8
 * Implements hook_install().
9
 */
10
function comment_notify_install() {
11

    
12
  // Create entries for existing comments.
13

    
14
  $comments_select = db_select('comment', 'c');
15
  $comments_select->join('users', 'u', 'c.uid = u.uid');
16
  $comments_select->addField('c', 'cid');
17
  $comments_select->addExpression('0', 'notify');
18
  // Mix in a random string to all values.
19
  $salt = uniqid(mt_rand(), TRUE);
20
  if (db_driver() == 'pgsql') {
21
    $comments_select->addExpression("MD5(:salt || c.mail || COALESCE(u.mail, u.init) || c.uid || c.name || c.nid || c.hostname || c.cid)", 'notify_hash', array(':salt' => $salt));
22
  }
23
  else {
24
    $comments_select->addExpression("MD5(CONCAT(:salt, c.mail, COALESCE(u.mail, u.init), c.uid, c.name, c.nid, c.hostname, c.cid))", 'notify_hash', array(':salt' => $salt));
25
  }
26

    
27
  // Set module weight low so that other modules act on the comment first.
28
  db_insert('comment_notify')->from($comments_select)->execute();
29
  db_update('system')->
30
    fields(array(
31
    'weight' => 10
32
    ))
33
    ->condition('name', 'comment_notify');
34
}
35

    
36
/**
37
 * Implements hook_uninstall().
38
 */
39
function comment_notify_uninstall() {
40
  variable_del('node_notify_default_mailtext');
41
  db_delete('variable')
42
    ->where('name', "comment_notify_%", 'LIKE');
43
}
44

    
45
/**
46
 * Implements hook_schema().
47
 */
48
function comment_notify_schema() {
49
  $schema['comment_notify'] = array(
50
    'description' => t('Stores information about which commenters on the site have subscriped to followup emails.'),
51
    'fields' => array(
52
      'cid' => array(
53
        'type' => 'int',
54
        'unsigned' => TRUE,
55
        'description' => 'The comment id from {comments}.cid',
56
        'not null' => TRUE,
57
        'disp-width' => '11'),
58
      'notify' => array(
59
        'type' => 'int',
60
        'description' => 'An integer indicating the type of subscription: 0 means not subscribed, 1 means subscribed to all comments, and 2 means only subscribed to replies of this comment.',
61
        'size' => 'tiny',
62
        'not null' => TRUE,
63
        'disp-width' => '11'),
64
      'notify_hash' => array(
65
        'type' => 'varchar',
66
        'description' => 'A hash of unique information about the commenter.  Used for unsubscribing users.',
67
        'length' => '128',
68
        'not null' => TRUE,
69
        'default' => ''),
70
      'notified' => array(
71
        'type' => 'int',
72
        'description' => 'A boolean indicator for whether or not a notification for the comment has been sent: 1 means yes, 0 means no.',
73
        'size' => 'tiny',
74
        'not null' => TRUE,
75
        'default' => 0,
76
        'disp-width' => '11'),
77
    ),
78
    'primary key' => array('cid'),
79
    'indexes' => array(
80
      'notify_hash' => array('notify_hash')),
81
  );
82
  $schema['comment_notify_user_settings'] = array(
83
    'fields' => array(
84
        'uid' => array(
85
          'type' => 'int',
86
          'unsigned' => TRUE,
87
          'description' => 'The user id from {users}.cid',
88
          'not null' => TRUE,
89
          'disp-width' => '11'),
90
        'node_notify' => array(
91
          'type' => 'int',
92
          'description' => 'An integer indicating the default type of subscription: 0 means not subscribed, 1 means subscribed to all comments, and 2 means only subscribed to replies of this comment.',
93
          'size' => 'tiny',
94
          'not null' => TRUE,
95
          'default' => 0,
96
          'disp-width' => '11'),
97
        'comment_notify' => array(
98
          'type' => 'int',
99
          'description' => 'An integer indicating the default type of subscription: 0 means not subscribed, 1 means subscribed to all comments, and 2 means only subscribed to replies of this comment.',
100
          'size' => 'tiny',
101
          'not null' => TRUE,
102
          'default' => 0,
103
          'disp-width' => '11'),
104
    ),
105
    'primary key' => array('uid'),
106
  );
107

    
108
  return $schema;
109
}
110

    
111
/**
112
 * Head 2 head update for the new size of the hash field.
113
 */
114
function comment_notify_update_7002() {
115
  $new_spec = array(
116
    'type' => 'varchar',
117
    'description' => 'A hash of unique information about the commenter.  Used for unsubscribing users.',
118
    'length' => '128',
119
    'not null' => TRUE,
120
    'default' => ''
121
  );
122
  $keys = array(
123
    'indexes' => array('notify_hash' => array('notify_hash')),
124
  );
125
  db_drop_index('comment_notify', 'notify_hash');
126
  db_change_field('comment_notify', 'notify_hash', 'notify_hash', $new_spec, $keys);
127
}
128

    
129
/**
130
 * Fix tokens in comment subscriber e-mail template.
131
 */
132
function comment_notify_update_7003() {
133
  $variables = array(
134
    'comment_notify_author_subject' => 'author',
135
    'comment_notify_node_notify_default_mailtext' => 'author',
136
    'comment_notify_watcher_subject' => 'commenter',
137
    'comment_notify_comment_notify_default_mailtext' => 'commenter',
138
  );
139
  foreach ($variables as $variable => $context) {
140
    // If the variable is using the default value, this will return NULL and we
141
    // can skip it.
142
    if ($text = variable_get($variable)) {
143
      $replacements = array(
144
        '[comment:unsubscribe-url]' => '[comment-subscribed:unsubscribe-url]',
145
        '[comment:name]' => '[comment:author]',
146
        '[node:' => '[comment:node:', // Replace all node tokens with comment:node.
147
      );
148
      if ($context == 'author') {
149
        $replacements['[user:name]'] = '[comment:node:author]';
150
        $replacements['[user:'] = '[comment:node:author:';
151
      }
152
      elseif ($context == 'commenter') {
153
        $replacements['[user:name]'] = '[comment-subscribed:author]';
154
        $replacements['[user:'] = '[comment-subscribed:author:';
155
      }
156
      $text = strtr($text, $replacements);
157
      variable_set($variable, $text);
158
    }
159
  }
160
  return 'Comment Notify token strings updated.';
161
}
162

    
163
/**
164
 * Fix a missing default causes warnings for Postgresql and some MySQL.
165
 */
166
function comment_notify_update_7004() {
167
  db_change_field('comment_notify', 'notified', 'notified',  array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
168
}
169

    
170
/**
171
 * Fix minor schema inconsistencies caused by the last update.
172
 */
173
function comment_notify_update_7005() {
174
  // Previous update altered size and unsigned unnecessarily.
175
  $notified_field = array(
176
    'type' => 'int',
177
    'description' => 'A boolean indicator for whether or not a notification for the comment has been sent: 1 means yes, 0 means no.',
178
    'size' => 'tiny',
179
    'not null' => TRUE,
180
    'default' => 0,
181
    'disp-width' => '11',
182
  );
183
  db_change_field('comment_notify', 'notified', 'notified', $notified_field);
184
}