print_pdf.install in Printer, email and PDF versions 7.2
Same filename and directory in other branches
Install, update and uninstall functions for the print_pdf module.
File
print_pdf/print_pdf.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the print_pdf module.
*
* @ingroup print
*/
/**
* Implements hook_enable().
*/
function print_pdf_enable() {
// Module weight.
db_update('system')
->fields(array(
'weight' => 2,
))
->condition('type', 'module')
->condition('name', 'print_pdf')
->execute();
}
/**
* Implements hook_uninstall().
*/
function print_pdf_uninstall() {
variable_del('print_pdf_autoconfig');
variable_del('print_pdf_cache_enabled');
variable_del('print_pdf_cache_lifetime');
variable_del('print_pdf_content_disposition');
variable_del('print_pdf_display_sys_urllist');
variable_del('print_pdf_filename');
variable_del('print_pdf_images_via_file');
variable_del('print_pdf_link_text');
variable_del('print_pdf_link_text_enabled');
variable_del('print_pdf_page_orientation');
variable_del('print_pdf_paper_size');
variable_del('print_pdf_pdf_tool');
variable_del('print_pdf_book_link');
variable_del('print_pdf_link_class');
variable_del('print_pdf_link_pos');
variable_del('print_pdf_link_teaser');
variable_del('print_pdf_link_use_alias');
variable_del('print_pdf_show_link');
variable_del('print_pdf_sys_link_pages');
variable_del('print_pdf_sys_link_visibility');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\\_pdf\\_display\\_%'");
foreach ($settings as $variable) {
variable_del($variable->name);
}
}
/**
* Implements hook_schema().
*/
function print_pdf_schema() {
$schema['print_pdf_node_conf'] = array(
'description' => 'PDF version node-specific configuration settings',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The {node}.nid of the node.',
),
'link' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show link',
),
'comments' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show link in individual comments',
),
'url_list' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show Printer-friendly URLs list',
),
'size' => array(
'type' => 'varchar',
'length' => 9,
'description' => 'Paper size',
),
'orientation' => array(
'type' => 'varchar',
'length' => 9,
'description' => 'Page orientation',
),
),
'primary key' => array(
'nid',
),
);
$schema['print_pdf_page_counter'] = array(
'description' => 'PDF version access counter',
'fields' => array(
'path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Page path',
),
'totalcount' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'big',
'description' => 'Number of page accesses',
),
'timestamp' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Last access',
),
),
'primary key' => array(
'path',
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function print_pdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected.
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (empty($print_pdf_pdf_tool)) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('No PDF tool selected'),
'description' => $t('Please configure it in the !url.', array(
'!url' => l($t('PDF settings page'), 'admin/config/user-interface/print/pdf'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Tool is defined, get some data from it's handler module.
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
$info = function_exists($function) ? $function() : array();
// Is the file there?
if (!is_file($tool[1]) || !is_readable($tool[1])) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('File not found'),
'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array(
'%file' => $tool[1],
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Get the version number.
$function = $tool[0] . '_pdf_tool_version';
if (function_exists($function)) {
$version = $function($tool[1]);
if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported %lib version', array(
'%lib' => $info['name'],
)),
'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to !url.', array(
'%lib' => $info['name'],
'@version' => $version,
'!url' => l($t('version @min or newer', array(
'@min' => $info['min_version'],
)), $info['url']),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $info['name'] . ' ' . $version,
);
}
}
}
// If auto-config is on, check for write access to the appropriate dirs.
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directories = array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
}
}
if (isset($info['tool_dirs'])) {
foreach ($info['tool_dirs'] as $dir) {
$directories[] = dirname($tool[1]) . '/' . $dir;
}
}
foreach ($directories as $dir) {
if (!is_dir($dir) || !is_writable($dir)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('%lib directory', array(
'%lib' => $info['name'],
)),
'value' => $t('Non-writable permissions'),
'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,
)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
}
/**
* Remove hardcoded numeric deltas from all blocks.
*/
function print_pdf_update_7000(&$sandbox) {
$renamed_deltas = array(
'print_pdf' => array(
'0' => 'print_pdf-top',
),
);
update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
if (variable_get('print_pdf_filename', '') == '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]') {
variable_set('print_pdf_filename', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
}
}
/**
* Delete old variables.
*/
function print_pdf_update_7200(&$sandbox) {
variable_del('print_pdf_settings');
variable_del('print_pdf_node_link_pages');
variable_del('print_pdf_node_link_visibility');
}
/**
* Update pdf_tool variable to new module|path format.
*/
function print_pdf_update_7201(&$sandbox) {
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 1) {
// Not an array yet, update variable to new format.
if (preg_match('!dompdf_config.inc.php$!', $tool[0])) {
$tool[0] = 'print_pdf_dompdf|' . $tool[0];
}
elseif (preg_match('!tcpdf.php$!', $tool[0])) {
$tool[0] = 'print_pdf_tcpdf|' . $tool[0];
}
elseif (preg_match('!wkhtmltopdf!', $tool[0])) {
$tool[0] = 'print_pdf_wkhtmltopdf|' . $tool[0];
}
else {
$tool[0] = PRINT_PDF_PDF_TOOL_DEFAULT;
}
variable_set('print_pdf_pdf_tool', $tool[0]);
}
}
/**
* Enable block and help area links.
*/
function print_pdf_update_7202(&$sandbox) {
$link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
$link_pos['block'] = 'block';
$link_pos['help'] = 'help';
variable_set('print_pdf_link_pos', $link_pos);
}
/**
* Add Size and Orientation fields for per content type Size and Orientation.
*/
function print_pdf_update_7203(&$sandbox) {
$spec = array(
'type' => 'varchar',
'length' => 9,
'description' => 'Paper size',
);
db_add_field('print_pdf_node_conf', 'size', $spec);
$spec = array(
'type' => 'varchar',
'length' => 9,
'description' => 'Page orientation',
);
db_add_field('print_pdf_node_conf', 'orientation', $spec);
}
/**
* Enable the PDF generation sub-module being used.
*/
function print_pdf_update_7204(&$sandbox) {
// Since update_7201 already stored the correct module in the array, use that.
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 2) {
module_enable(array(
$tool[0],
), FALSE);
}
}
/**
* Increase size of the path field in the print_pdf_page_counter table.
*/
function print_pdf_update_7205(&$sandbox) {
db_drop_primary_key('print_pdf_page_counter');
db_change_field('print_pdf_page_counter', 'path', 'path', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Page path',
), array(
'primary key' => array(
'path',
),
));
}
Functions
Name | Description |
---|---|
print_pdf_enable | Implements hook_enable(). |
print_pdf_requirements | Implements hook_requirements(). |
print_pdf_schema | Implements hook_schema(). |
print_pdf_uninstall | Implements hook_uninstall(). |
print_pdf_update_7000 | Remove hardcoded numeric deltas from all blocks. |
print_pdf_update_7200 | Delete old variables. |
print_pdf_update_7201 | Update pdf_tool variable to new module|path format. |
print_pdf_update_7202 | Enable block and help area links. |
print_pdf_update_7203 | Add Size and Orientation fields for per content type Size and Orientation. |
print_pdf_update_7204 | Enable the PDF generation sub-module being used. |
print_pdf_update_7205 | Increase size of the path field in the print_pdf_page_counter table. |