print_epub.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the print_epub module.
  5. *
  6. * @ingroup print
  7. */
  8. /**
  9. * Implements hook_enable().
  10. */
  11. function print_epub_enable() {
  12. $t = get_t();
  13. // Module weight
  14. db_update('system')
  15. ->fields(array(
  16. 'weight' => 4,
  17. ))
  18. ->condition('type', 'module')
  19. ->condition('name', 'print_epub')
  20. ->execute();
  21. }
  22. /**
  23. * Implements hook_uninstall().
  24. */
  25. function print_epub_uninstall() {
  26. variable_del('print_epub_display_sys_urllist');
  27. variable_del('print_epub_filename');
  28. variable_del('print_epub_images_via_file');
  29. variable_del('print_epub_link_text');
  30. variable_del('print_epub_link_text_enabled');
  31. variable_del('print_epub_epub_tool');
  32. variable_del('print_epub_book_link');
  33. variable_del('print_epub_link_class');
  34. variable_del('print_epub_link_pos');
  35. variable_del('print_epub_link_teaser');
  36. variable_del('print_epub_link_use_alias');
  37. variable_del('print_epub_show_link');
  38. variable_del('print_epub_sys_link_pages');
  39. variable_del('print_epub_sys_link_visibility');
  40. $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_epub\_display\_%'");
  41. foreach ($settings as $variable) {
  42. variable_del($variable->name);
  43. }
  44. }
  45. /**
  46. * Implements hook_schema().
  47. */
  48. function print_epub_schema() {
  49. $schema['print_epub_node_conf'] = array(
  50. 'description' => 'EPUB version node-specific configuration settings',
  51. 'fields' => array(
  52. 'nid' => array(
  53. 'type' => 'int',
  54. 'unsigned' => TRUE,
  55. 'not null' => TRUE,
  56. 'description' => 'The {node}.nid of the node.',
  57. ),
  58. 'link' => array(
  59. 'type' => 'int',
  60. 'unsigned' => TRUE,
  61. 'not null' => TRUE,
  62. 'default' => 1,
  63. 'size' => 'tiny',
  64. 'description' => 'Show link',
  65. ),
  66. 'comments' => array(
  67. 'type' => 'int',
  68. 'unsigned' => TRUE,
  69. 'not null' => TRUE,
  70. 'default' => 1,
  71. 'size' => 'tiny',
  72. 'description' => 'Show link in individual comments',
  73. ),
  74. 'url_list' => array(
  75. 'type' => 'int',
  76. 'unsigned' => TRUE,
  77. 'not null' => TRUE,
  78. 'default' => 1,
  79. 'size' => 'tiny',
  80. 'description' => 'Show Printer-friendly URLs list',
  81. ),
  82. ),
  83. 'primary key' => array('nid'),
  84. );
  85. $schema['print_epub_page_counter'] = array(
  86. 'description' => 'EPUB version access counter',
  87. 'fields' => array(
  88. 'path' => array(
  89. 'type' => 'varchar',
  90. 'length' => 255,
  91. 'not null' => TRUE,
  92. 'description' => 'Page path',
  93. ),
  94. 'totalcount' => array(
  95. 'type' => 'int',
  96. 'unsigned' => TRUE,
  97. 'not null' => TRUE,
  98. 'default' => 0,
  99. 'size' => 'big',
  100. 'description' => 'Number of page accesses',
  101. ),
  102. 'timestamp' => array(
  103. 'type' => 'int',
  104. 'unsigned' => TRUE,
  105. 'not null' => TRUE,
  106. 'default' => 0,
  107. 'description' => 'Last access',
  108. ),
  109. ),
  110. 'primary key' => array('path'),
  111. );
  112. return $schema;
  113. }
  114. /**
  115. * Remove hardcoded numeric deltas from all blocks
  116. */
  117. function print_epub_update_7000(&$sandbox) {
  118. $renamed_deltas = array(
  119. 'print_epub' => array(
  120. '0' => 'print_epub-top',
  121. ),
  122. );
  123. update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
  124. if (variable_get('print_epub_filename', '') == '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]') {
  125. variable_set('print_epub_filename', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
  126. }
  127. }
  128. /**
  129. * Enable block and help area links
  130. */
  131. function print_epub_update_7202(&$sandbox) {
  132. $link_pos = variable_get('print_epub_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
  133. $link_pos['block'] = 'block';
  134. $link_pos['help'] = 'help';
  135. variable_set('print_epub_link_pos', $link_pos);
  136. }
  137. /**
  138. * Increase size of the path field in the print_epub_page_counter table
  139. */
  140. function print_epub_update_7203(&$sandbox) {
  141. db_drop_primary_key('print_epub_page_counter');
  142. db_change_field('print_epub_page_counter', 'path', 'path',
  143. array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
  144. array('primary key' => array('path')));
  145. }