print_pdf.install 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the print_pdf module.
  5. *
  6. * @ingroup print
  7. */
  8. /**
  9. * Implements hook_enable().
  10. */
  11. function print_pdf_enable() {
  12. $t = get_t();
  13. // Module weight
  14. db_update('system')
  15. ->fields(array(
  16. 'weight' => 2,
  17. ))
  18. ->condition('type', 'module')
  19. ->condition('name', 'print_pdf')
  20. ->execute();
  21. }
  22. /**
  23. * Implements hook_uninstall().
  24. */
  25. function print_pdf_uninstall() {
  26. variable_del('print_pdf_autoconfig');
  27. variable_del('print_pdf_cache_enabled');
  28. variable_del('print_pdf_cache_lifetime');
  29. variable_del('print_pdf_content_disposition');
  30. variable_del('print_pdf_display_sys_urllist');
  31. variable_del('print_pdf_filename');
  32. variable_del('print_pdf_images_via_file');
  33. variable_del('print_pdf_link_text');
  34. variable_del('print_pdf_link_text_enabled');
  35. variable_del('print_pdf_page_orientation');
  36. variable_del('print_pdf_paper_size');
  37. variable_del('print_pdf_pdf_tool');
  38. variable_del('print_pdf_book_link');
  39. variable_del('print_pdf_link_class');
  40. variable_del('print_pdf_link_pos');
  41. variable_del('print_pdf_link_teaser');
  42. variable_del('print_pdf_link_use_alias');
  43. variable_del('print_pdf_show_link');
  44. variable_del('print_pdf_sys_link_pages');
  45. variable_del('print_pdf_sys_link_visibility');
  46. $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
  47. foreach ($settings as $variable) {
  48. variable_del($variable->name);
  49. }
  50. }
  51. /**
  52. * Implements hook_schema().
  53. */
  54. function print_pdf_schema() {
  55. $schema['print_pdf_node_conf'] = array(
  56. 'description' => 'PDF version node-specific configuration settings',
  57. 'fields' => array(
  58. 'nid' => array(
  59. 'type' => 'int',
  60. 'unsigned' => TRUE,
  61. 'not null' => TRUE,
  62. 'description' => 'The {node}.nid of the node.',
  63. ),
  64. 'link' => array(
  65. 'type' => 'int',
  66. 'unsigned' => TRUE,
  67. 'not null' => TRUE,
  68. 'default' => 1,
  69. 'size' => 'tiny',
  70. 'description' => 'Show link',
  71. ),
  72. 'comments' => array(
  73. 'type' => 'int',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'default' => 1,
  77. 'size' => 'tiny',
  78. 'description' => 'Show link in individual comments',
  79. ),
  80. 'url_list' => array(
  81. 'type' => 'int',
  82. 'unsigned' => TRUE,
  83. 'not null' => TRUE,
  84. 'default' => 1,
  85. 'size' => 'tiny',
  86. 'description' => 'Show Printer-friendly URLs list',
  87. ),
  88. 'size' => array(
  89. 'type' => 'varchar',
  90. 'length' => 9,
  91. 'description' => 'Paper size',
  92. ),
  93. 'orientation' => array(
  94. 'type' => 'varchar',
  95. 'length' => 9,
  96. 'description' => 'Page orientation',
  97. ),
  98. ),
  99. 'primary key' => array('nid'),
  100. );
  101. $schema['print_pdf_page_counter'] = array(
  102. 'description' => 'PDF version access counter',
  103. 'fields' => array(
  104. 'path' => array(
  105. 'type' => 'varchar',
  106. 'length' => 255,
  107. 'not null' => TRUE,
  108. 'description' => 'Page path',
  109. ),
  110. 'totalcount' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not null' => TRUE,
  114. 'default' => 0,
  115. 'size' => 'big',
  116. 'description' => 'Number of page accesses',
  117. ),
  118. 'timestamp' => array(
  119. 'type' => 'int',
  120. 'unsigned' => TRUE,
  121. 'not null' => TRUE,
  122. 'default' => 0,
  123. 'description' => 'Last access',
  124. ),
  125. ),
  126. 'primary key' => array('path'),
  127. );
  128. return $schema;
  129. }
  130. /**
  131. * Remove hardcoded numeric deltas from all blocks
  132. */
  133. function print_pdf_update_7000(&$sandbox) {
  134. $renamed_deltas = array(
  135. 'print_pdf' => array(
  136. '0' => 'print_pdf-top',
  137. ),
  138. );
  139. update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
  140. if (variable_get('print_pdf_filename', '') == '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]') {
  141. variable_set('print_pdf_filename', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
  142. }
  143. }
  144. /**
  145. * Delete old variables
  146. */
  147. function print_pdf_update_7200(&$sandbox) {
  148. variable_del('print_pdf_settings');
  149. variable_del('print_pdf_node_link_pages');
  150. variable_del('print_pdf_node_link_visibility');
  151. }
  152. /**
  153. * Update pdf_tool variable to new module|path format
  154. */
  155. function print_pdf_update_7201(&$sandbox) {
  156. $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
  157. if (count($tool) == 1) {
  158. // Not an array yet, update variable to new format
  159. if (preg_match('!dompdf_config.inc.php$!', $tool[0])) {
  160. $tool[0] = 'print_pdf_dompdf|' . $tool[0];
  161. }
  162. elseif (preg_match('!tcpdf.php$!', $tool[0])) {
  163. $tool[0] = 'print_pdf_tcpdf|' . $tool[0];
  164. }
  165. elseif (preg_match('!wkhtmltopdf!', $tool[0])) {
  166. $tool[0] = 'print_pdf_wkhtmltopdf|' . $tool[0];
  167. }
  168. else {
  169. $tool[0] = PRINT_PDF_PDF_TOOL_DEFAULT;
  170. }
  171. variable_set('print_pdf_pdf_tool', $tool[0]);
  172. }
  173. }
  174. /**
  175. * Enable block and help area links
  176. */
  177. function print_pdf_update_7202(&$sandbox) {
  178. $link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
  179. $link_pos['block'] = 'block';
  180. $link_pos['help'] = 'help';
  181. variable_set('print_pdf_link_pos', $link_pos);
  182. }
  183. /**
  184. * Add Size and Orientation fields for per content type Size and Orientation
  185. */
  186. function print_pdf_update_7203(&$sandbox) {
  187. $spec = array(
  188. 'type' => 'varchar',
  189. 'length' => 9,
  190. 'description' => 'Paper size',
  191. );
  192. db_add_field('print_pdf_node_conf', 'size', $spec);
  193. $spec = array(
  194. 'type' => 'varchar',
  195. 'length' => 9,
  196. 'description' => 'Page orientation',
  197. );
  198. db_add_field('print_pdf_node_conf', 'orientation', $spec);
  199. }
  200. /**
  201. * Enable the PDF generation sub-module being used
  202. */
  203. function print_pdf_update_7204(&$sandbox) {
  204. // Since update_7201 already has stored the correct module in the array, use that
  205. $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
  206. if (count($tool) == 2) {
  207. module_enable(array($tool[0]), FALSE);
  208. }
  209. }
  210. /**
  211. * Increase size of the path field in the print_pdf_page_counter table
  212. */
  213. function print_pdf_update_7205(&$sandbox) {
  214. db_drop_primary_key('print_pdf_page_counter');
  215. db_change_field('print_pdf_page_counter', 'path', 'path',
  216. array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
  217. array('primary key' => array('path')));
  218. }