Projet

Général

Profil

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

root / drupal7 / sites / all / modules / print / print_mail / print_mail.install @ 1aa883a3

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the print_mail module.
6
 *
7
 * @ingroup print
8
 */
9

    
10
/**
11
 * Implements hook_enable().
12
 */
13
function print_mail_enable() {
14
  // Module weight.
15
  db_update('system')
16
    ->fields(array(
17
      'weight' => 1,
18
    ))
19
    ->condition('type', 'module')
20
    ->condition('name', 'print_mail')
21
    ->execute();
22

    
23
  if (module_exists('mailsystem')) {
24
    mailsystem_set(array('print_mail' => 'DefaultMailSystem'));
25
  }
26
}
27

    
28
/**
29
 * Implements hook_requirements().
30
 */
31
function print_mail_requirements($phase) {
32
  $requirements = array();
33
  $t = get_t();
34
  switch ($phase) {
35
    // At runtime, make sure that a PDF generation tool is selected.
36
    case 'runtime':
37
      if (module_exists('mailsystem')) {
38
        $mail_system = mailsystem_get();
39
        if (($mail_system['default-system'] != 'DefaultMailSystem') && (!isset($mail_system['print_mail']) || ($mail_system['print_mail'] != 'DefaultMailSystem'))) {
40
          $requirements['print_mail_mailsystem'] = array(
41
            'title' => $t('Printer, email and PDF versions - Send by email'),
42
            'value' => $t('Incompatible Mail System setting detected'),
43
            'description' => $t('The send by email module requires the use of the DefaultMailSystem, please configure it in the !url.', array('!url' => l($t('Mail System Settings page'), 'admin/config/system/mailsystem'))),
44
            'severity' => REQUIREMENT_WARNING,
45
          );
46
        }
47
      }
48
  }
49

    
50
  return $requirements;
51
}
52

    
53
/**
54
 * Implements hook_disable().
55
 */
56
function print_mail_disable() {
57
  if (module_exists('mailsystem')) {
58
    mailsystem_clear(array('print_mail' => ''));
59
  }
60
}
61

    
62
/**
63
 * Implements hook_uninstall().
64
 */
65
function print_mail_uninstall() {
66
  variable_del('print_mail_display_sys_urllist');
67
  variable_del('print_mail_hourly_threshold');
68
  variable_del('print_mail_job_queue');
69
  variable_del('print_mail_link_text');
70
  variable_del('print_mail_link_text_enabled');
71
  variable_del('print_mail_send_option_default');
72
  variable_del('print_mail_teaser_choice');
73
  variable_del('print_mail_teaser_default');
74
  variable_del('print_mail_use_reply_to');
75
  variable_del('print_mail_user_recipients');
76

    
77
  variable_del('print_mail_book_link');
78
  variable_del('print_mail_link_class');
79
  variable_del('print_mail_link_pos');
80
  variable_del('print_mail_link_teaser');
81
  variable_del('print_mail_link_use_alias');
82
  variable_del('print_mail_show_link');
83
  variable_del('print_mail_sys_link_pages');
84
  variable_del('print_mail_sys_link_visibility');
85

    
86
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_mail\_display\_%'");
87
  foreach ($settings as $variable) {
88
    variable_del($variable->name);
89
  }
90
}
91

    
92
/**
93
 * Implements hook_schema().
94
 */
95
function print_mail_schema() {
96
  $schema['print_mail_node_conf'] = array(
97
    'description' => 'Send by email node-specific configuration settings',
98
    'fields' => array(
99
      'nid' => array(
100
        'type' => 'int',
101
        'unsigned' => TRUE,
102
        'not null' => TRUE,
103
        'description' => 'The {node}.nid of the node.',
104
      ),
105
      'link' => array(
106
        'type' => 'int',
107
        'unsigned' => TRUE,
108
        'not null' => TRUE,
109
        'default' => 1,
110
        'size' => 'tiny',
111
        'description' => 'Show link',
112
      ),
113
      'comments' => array(
114
        'type' => 'int',
115
        'unsigned' => TRUE,
116
        'not null' => TRUE,
117
        'default' => 1,
118
        'size' => 'tiny',
119
        'description' => 'Show link in individual comments',
120
      ),
121
      'url_list' => array(
122
        'type' => 'int',
123
        'unsigned' => TRUE,
124
        'not null' => TRUE,
125
        'default' => 1,
126
        'size' => 'tiny',
127
        'description' => 'Show Printer-friendly URLs list',
128
      ),
129
    ),
130
    'primary key' => array('nid'),
131
  );
132

    
133
  $schema['print_mail_page_counter'] = array(
134
    'description' => 'Send by email version access counter',
135
    'fields' => array(
136
      'path' => array(
137
        'type' => 'varchar',
138
        'length' => 255,
139
        'not null' => TRUE,
140
        'description' => 'Page path',
141
      ),
142
      'totalcount' => array(
143
        'type' => 'int',
144
        'unsigned' => TRUE,
145
        'not null' => TRUE,
146
        'default' => 0,
147
        'size' => 'big',
148
        'description' => 'Number of page accesses',
149
      ),
150
      'timestamp' => array(
151
        'type' => 'int',
152
        'unsigned' => TRUE,
153
        'not null' => TRUE,
154
        'default' => 0,
155
        'description' => 'Last access',
156
      ),
157
      'sentcount' => array(
158
        'type' => 'int',
159
        'unsigned' => TRUE,
160
        'not null' => TRUE,
161
        'default' => 0,
162
        'size' => 'big',
163
        'description' => 'Number of sent emails',
164
      ),
165
      'sent_timestamp' => array(
166
        'type' => 'int',
167
        'unsigned' => TRUE,
168
        'not null' => TRUE,
169
        'default' => 0,
170
        'description' => 'Last email sent',
171
      ),
172
    ),
173
    'primary key' => array('path'),
174
  );
175

    
176
  return $schema;
177
}
178

    
179
/**
180
 * Remove hardcoded numeric deltas from all blocks.
181
 */
182
function print_mail_update_7000(&$sandbox) {
183
  $renamed_deltas = array(
184
    'print_mail' => array(
185
      '0' => 'print_mail-top',
186
    ),
187
  );
188

    
189
  update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
190
}
191

    
192
/**
193
 * Disable MimeMailSystem for now.
194
 */
195
function print_mail_update_7100(&$sandbox) {
196
  if (module_exists('mailsystem')) {
197
    mailsystem_set(array('print_mail' => 'DefaultMailSystem'));
198
  }
199
}
200

    
201
/**
202
 * Update permissions to new spellings.
203
 */
204
function print_mail_update_7101(&$sandbox) {
205
  db_update('role_permission')
206
    ->fields(array('permission' => 'access send by email'))
207
    ->condition('permission', 'access send to friend')
208
    ->execute();
209
  db_update('role_permission')
210
    ->fields(array('permission' => 'send unlimited emails'))
211
    ->condition('permission', 'send unlimited e-mails')
212
    ->execute();
213
}
214

    
215
/**
216
 * Delete old variables.
217
 */
218
function print_mail_update_7200(&$sandbox) {
219
  variable_del('print_mail_settings');
220

    
221
  variable_del('print_mail_node_link_pages');
222
  variable_del('print_mail_node_link_visibility');
223

    
224
  variable_del('print_mail_text_title');
225
  variable_del('print_mail_text_confirmation');
226
  variable_del('print_mail_text_message');
227
  variable_del('print_mail_text_subject');
228
  variable_del('print_mail_text_content');
229
}
230

    
231
/**
232
 * Enable block and help area links.
233
 */
234
function print_mail_update_7202(&$sandbox) {
235
  $link_pos = variable_get('print_mail_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
236
  $link_pos['block'] = 'block';
237
  $link_pos['help'] = 'help';
238
  variable_set('print_mail_link_pos', $link_pos);
239
}
240

    
241
/**
242
 * Increase size of the path field in the print_mail_page_counter table.
243
 */
244
function print_mail_update_7203(&$sandbox) {
245
  db_drop_primary_key('print_mail_page_counter');
246
  db_change_field('print_mail_page_counter', 'path', 'path',
247
    array(
248
      'type' => 'varchar',
249
      'length' => 255,
250
      'not null' => TRUE,
251
      'description' => 'Page path',
252
    ),
253
    array('primary key' => array('path')));
254
}