Project

General

Profile

Revision 76bdcd04

Added by Assos Assos almost 6 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/print/print_pdf/print_pdf.install
11 11
 * Implements hook_enable().
12 12
 */
13 13
function print_pdf_enable() {
14
  $t = get_t();
15

  
16
  // Module weight
14
  // Module weight.
17 15
  db_update('system')
18 16
    ->fields(array(
19 17
      'weight' => 2,
......
27 25
 * Implements hook_uninstall().
28 26
 */
29 27
function print_pdf_uninstall() {
30
  variable_del('print_pdf_settings');
31
  variable_del('print_pdf_show_link');
32
  variable_del('print_pdf_link_pos');
33
  variable_del('print_pdf_link_teaser');
34
  variable_del('print_pdf_node_link_visibility');
35
  variable_del('print_pdf_node_link_pages');
36
  variable_del('print_pdf_link_class');
37
  variable_del('print_pdf_sys_link_visibility');
38
  variable_del('print_pdf_sys_link_pages');
39
  variable_del('print_pdf_book_link');
40
  variable_del('print_pdf_pdf_tool');
28
  variable_del('print_pdf_autoconfig');
29
  variable_del('print_pdf_cache_enabled');
30
  variable_del('print_pdf_cache_lifetime');
41 31
  variable_del('print_pdf_content_disposition');
42
  variable_del('print_pdf_paper_size');
43
  variable_del('print_pdf_page_orientation');
32
  variable_del('print_pdf_display_sys_urllist');
33
  variable_del('print_pdf_filename');
44 34
  variable_del('print_pdf_images_via_file');
45
  variable_del('print_pdf_font_family');
46
  variable_del('print_pdf_font_size');
47 35
  variable_del('print_pdf_link_text');
36
  variable_del('print_pdf_link_text_enabled');
37
  variable_del('print_pdf_page_orientation');
38
  variable_del('print_pdf_paper_size');
39
  variable_del('print_pdf_pdf_tool');
40

  
41
  variable_del('print_pdf_book_link');
42
  variable_del('print_pdf_link_class');
43
  variable_del('print_pdf_link_pos');
44
  variable_del('print_pdf_link_teaser');
48 45
  variable_del('print_pdf_link_use_alias');
49
  variable_del('print_pdf_filename');
50
  variable_del('print_pdf_autoconfig');
51
  variable_del('print_pdf_dompdf_unicode');
52
  variable_del('print_pdf_wkhtmltopdf_options');
53
  variable_del('print_pdf_display_sys_urllist');
46
  variable_del('print_pdf_show_link');
47
  variable_del('print_pdf_sys_link_pages');
48
  variable_del('print_pdf_sys_link_visibility');
49

  
54 50
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
55 51
  foreach ($settings as $variable) {
56 52
    variable_del($variable->name);
......
94 90
        'size' => 'tiny',
95 91
        'description' => 'Show Printer-friendly URLs list',
96 92
      ),
93
      'size' => array(
94
        'type' => 'varchar',
95
        'length' => 9,
96
        'description' => 'Paper size',
97
      ),
98
      'orientation' => array(
99
        'type' => 'varchar',
100
        'length' => 9,
101
        'description' => 'Page orientation',
102
      ),
103

  
97 104
    ),
98 105
    'primary key' => array('nid'),
99 106
  );
......
130 137
}
131 138

  
132 139
/**
133
 * Remove hardcoded numeric deltas from all blocks
140
 * Implements hook_requirements().
141
 */
142
function print_pdf_requirements($phase) {
143
  $requirements = array();
144
  $t = get_t();
145
  switch ($phase) {
146
    // At runtime, make sure that a PDF generation tool is selected.
147
    case 'runtime':
148
      $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
149
      if (empty($print_pdf_pdf_tool)) {
150
        $requirements['print_pdf_tool'] = array(
151
          'title' => $t('Printer, email and PDF versions - PDF generation library'),
152
          'value' => $t('No PDF tool selected'),
153
          'description' => $t('Please configure it in the !url.', array('!url' => l($t('PDF settings page'), 'admin/config/user-interface/print/pdf'))),
154
          'severity' => REQUIREMENT_ERROR,
155
        );
156
      }
157
      else {
158
        // Tool is defined, get some data from it's handler module.
159
        $tool = explode('|', $print_pdf_pdf_tool);
160
        $function = $tool[0] . '_pdf_tool_info';
161
        $info = function_exists($function) ? $function() : array();
162

  
163
        // Is the file there?
164
        if (!is_file($tool[1]) || !is_readable($tool[1])) {
165
          $requirements['print_pdf_tool'] = array(
166
            'title' => $t('Printer, email and PDF versions - PDF generation library'),
167
            'value' => $t('File not found'),
168
            'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
169
            'severity' => REQUIREMENT_ERROR,
170
          );
171
        }
172
        else {
173
          // Get the version number.
174
          $function = $tool[0] . '_pdf_tool_version';
175
          if (function_exists($function)) {
176
            $version = $function($tool[1]);
177

  
178
            if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
179
              $requirements['print_pdf_tool_version'] = array(
180
                'title' => $t('Printer, email and PDF versions - PDF generation library'),
181
                'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
182
                'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.', array(
183
                  '%lib' => $info['name'],
184
                  '@version' => $version,
185
                  '!url' => l($t('newer version'), $info['url']),
186
                )),
187
                'severity' => REQUIREMENT_ERROR,
188
              );
189
            }
190
            else {
191
              $requirements['print_pdf_tool_version'] = array(
192
                'title' => $t('Printer, email and PDF versions - PDF generation library'),
193
                'value' => $info['name'] . ' ' . $version,
194
              );
195
            }
196
          }
197
        }
198

  
199
        // If auto-config is on, check for write access to the appropriate dirs.
200
        if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
201
          $directories = array();
202
          if (isset($info['public_dirs'])) {
203
            foreach ($info['public_dirs'] as $dir) {
204
              $directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
205
            }
206
          }
207
          if (isset($info['tool_dirs'])) {
208
            foreach ($info['tool_dirs'] as $dir) {
209
              $directories[] = dirname($tool[1]) . '/' . $dir;
210
            }
211
          }
212

  
213
          foreach ($directories as $dir) {
214
            if (!is_dir($dir) || !is_writable($dir)) {
215
              $requirements['print_pdf_tool_' . $dir] = array(
216
                'title' => $t('%lib directory', array('%lib' => $info['name'])),
217
                'value' => $t('Non-writable permissions'),
218
                'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
219
                'severity' => REQUIREMENT_ERROR,
220
              );
221
            }
222
          }
223
        }
224
      }
225
      break;
226
  }
227
  return $requirements;
228
}
229

  
230
/**
231
 * Remove hardcoded numeric deltas from all blocks.
134 232
 */
135 233
function print_pdf_update_7000(&$sandbox) {
136 234
  $renamed_deltas = array(
......
147 245
}
148 246

  
149 247
/**
150
 * Enable block and help area links
248
 * Delete old variables.
249
 */
250
function print_pdf_update_7200(&$sandbox) {
251
  variable_del('print_pdf_settings');
252

  
253
  variable_del('print_pdf_node_link_pages');
254
  variable_del('print_pdf_node_link_visibility');
255
}
256

  
257
/**
258
 * Update pdf_tool variable to new module|path format.
259
 */
260
function print_pdf_update_7201(&$sandbox) {
261
  $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
262

  
263
  if (count($tool) == 1) {
264
    // Not an array yet, update variable to new format.
265
    if (preg_match('!dompdf_config.inc.php$!', $tool[0])) {
266
      $tool[0] = 'print_pdf_dompdf|' . $tool[0];
267
    }
268
    elseif (preg_match('!tcpdf.php$!', $tool[0])) {
269
      $tool[0] = 'print_pdf_tcpdf|' . $tool[0];
270
    }
271
    elseif (preg_match('!wkhtmltopdf!', $tool[0])) {
272
      $tool[0] = 'print_pdf_wkhtmltopdf|' . $tool[0];
273
    }
274
    else {
275
      $tool[0] = PRINT_PDF_PDF_TOOL_DEFAULT;
276
    }
277

  
278
    variable_set('print_pdf_pdf_tool', $tool[0]);
279
  }
280
}
281

  
282
/**
283
 * Enable block and help area links.
151 284
 */
152
function print_pdf_update_7101(&$sandbox) {
285
function print_pdf_update_7202(&$sandbox) {
153 286
  $link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
154 287
  $link_pos['block'] = 'block';
155 288
  $link_pos['help'] = 'help';
......
157 290
}
158 291

  
159 292
/**
160
 * Increase size of the path field in the print_pdf_page_counter table
293
 * Add Size and Orientation fields for per content type Size and Orientation.
161 294
 */
162
function print_pdf_update_7105(&$sandbox) {
295
function print_pdf_update_7203(&$sandbox) {
296
  $spec = array(
297
    'type' => 'varchar',
298
    'length' => 9,
299
    'description' => 'Paper size',
300
  );
301
  db_add_field('print_pdf_node_conf', 'size', $spec);
302
  $spec = array(
303
    'type' => 'varchar',
304
    'length' => 9,
305
    'description' => 'Page orientation',
306
  );
307
  db_add_field('print_pdf_node_conf', 'orientation', $spec);
308
}
309

  
310
/**
311
 * Enable the PDF generation sub-module being used.
312
 */
313
function print_pdf_update_7204(&$sandbox) {
314
  // Since update_7201 already stored the correct module in the array, use that.
315
  $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
316

  
317
  if (count($tool) == 2) {
318
    module_enable(array($tool[0]), FALSE);
319
  }
320
}
321

  
322
/**
323
 * Increase size of the path field in the print_pdf_page_counter table.
324
 */
325
function print_pdf_update_7205(&$sandbox) {
163 326
  db_drop_primary_key('print_pdf_page_counter');
164 327
  db_change_field('print_pdf_page_counter', 'path', 'path',
165
    array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
328
    array(
329
      'type' => 'varchar',
330
      'length' => 255,
331
      'not null' => TRUE,
332
      'description' => 'Page path',
333
    ),
166 334
    array('primary key' => array('path')));
167 335
}

Also available in: Unified diff