background_process.install 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * @file
  4. * This is the installation file for the Background Process module
  5. */
  6. /**
  7. * Implements of hook_enable().
  8. */
  9. function background_process_enable() {
  10. $_SESSION['background_process_determine_default_service_host'] = TRUE;
  11. }
  12. /**
  13. * Implements of hook_schema().
  14. */
  15. function background_process_schema() {
  16. $schema = array();
  17. $schema['background_process'] = array(
  18. 'fields' => array(
  19. 'handle' => array(
  20. 'type' => 'varchar',
  21. 'length' => 255,
  22. 'not null' => TRUE,
  23. 'default' => '',
  24. ),
  25. 'callback' => array(
  26. 'type' => 'text',
  27. 'not null' => FALSE,
  28. ),
  29. 'args' => array(
  30. 'type' => 'blob',
  31. 'not null' => FALSE,
  32. ),
  33. 'uid' => array(
  34. 'type' => 'int',
  35. 'not null' => TRUE,
  36. 'default' => 0,
  37. ),
  38. 'token' => array(
  39. 'type' => 'varchar',
  40. 'length' => 32,
  41. 'not null' => TRUE,
  42. 'default' => '',
  43. ),
  44. 'service_host' => array(
  45. 'type' => 'varchar',
  46. 'length' => 64,
  47. 'not null' => TRUE,
  48. 'default' => '',
  49. ),
  50. 'start_stamp' => array(
  51. 'type' => 'varchar',
  52. 'length' => '18',
  53. 'not null' => FALSE,
  54. ),
  55. 'exec_status' => array(
  56. 'type' => 'int',
  57. 'size' => 'normal',
  58. 'not null' => TRUE,
  59. 'default' => 0,
  60. ),
  61. ),
  62. 'primary key' => array('handle'),
  63. );
  64. return $schema;
  65. }
  66. /**
  67. * Implements hook_uninstall().
  68. */
  69. function background_process_uninstall() {
  70. // Removing process variables.
  71. variable_del('background_process_service_timeout');
  72. variable_del('background_process_connection_timeout');
  73. variable_del('background_process_stream_timeout');
  74. variable_del('background_process_service_groups');
  75. variable_del('background_process_default_service_group');
  76. variable_del('background_process_service_hosts');
  77. variable_del('background_process_default_service_host');
  78. variable_del('background_process_cleanup_age');
  79. variable_del('background_process_queues');
  80. variable_del('background_process_derived_default_host');
  81. variable_del('background_process_token');
  82. }
  83. /**
  84. * Implements hook_requirements().
  85. */
  86. function background_process_requirements($phase) {
  87. $response = array();
  88. switch ($phase) {
  89. case 'install':
  90. return $response;
  91. case 'runtime':
  92. $response['title'] = 'Background Process';
  93. $response['value'] = t('OK');
  94. $response['severity'] = REQUIREMENT_OK;
  95. if (ini_get('safe_mode')) {
  96. $desc = t('Safe mode enabled. Background Process is unable to control maximum execution time for background processes. This may cause background processes to end prematurely.');
  97. if ($response['severity'] < REQUIREMENT_WARNING) {
  98. $response['severity'] = REQUIREMENT_WARNING;
  99. $response['value'] = t('Safe mode enabled');
  100. $response['description'] = $desc;
  101. }
  102. else {
  103. $response['description'] .= '<br/>' . $desc;
  104. }
  105. }
  106. $result = array();
  107. $result['background_process'] = $response;
  108. return $result;
  109. }
  110. }
  111. /**
  112. * Major version upgrade of Drupal
  113. */
  114. function background_process_update_7000(&$context) {
  115. $context['sandbox']['major_version_upgrade'] = array(
  116. 7101 => TRUE,
  117. 7102 => TRUE,
  118. 7103 => TRUE,
  119. 7104 => TRUE,
  120. 7105 => TRUE,
  121. 7106 => TRUE,
  122. );
  123. }
  124. /**
  125. * Add status column to background_process table.
  126. */
  127. function background_process_update_7101() {
  128. if (!empty($context['sandbox']['major_version_upgrade'][7101])) {
  129. // This udate is already part of latest 6.x
  130. return;
  131. }
  132. db_add_field('background_process', 'status', array(
  133. 'type' => 'int',
  134. 'size' => 'normal',
  135. 'not null' => TRUE,
  136. 'default' => 0,
  137. ));
  138. }
  139. /**
  140. * Determine default service host
  141. */
  142. function background_process_update_7102() {
  143. }
  144. /**
  145. * Determine default service host
  146. */
  147. function background_process_update_7103() {
  148. }
  149. /**
  150. * Change start column from double to numeric
  151. */
  152. function background_process_update_7104() {
  153. if (!empty($context['sandbox']['major_version_upgrade'][7104])) {
  154. // This udate is already part of latest 6.x
  155. return;
  156. }
  157. db_change_field('background_process', 'start', 'start', array(
  158. 'type' => 'numeric',
  159. 'precision' => '16',
  160. 'scale' => '6',
  161. 'not null' => FALSE,
  162. ));
  163. }
  164. /**
  165. * Re-determine default service host.
  166. */
  167. function background_process_update_7105() {
  168. if (!empty($context['sandbox']['major_version_upgrade'][7105])) {
  169. // This udate is already part of latest 6.x
  170. return;
  171. }
  172. $_SESSION['background_process_determine_default_service_host'] = TRUE;
  173. }
  174. /**
  175. * Change schema to SQL 99 compliance
  176. */
  177. function background_process_update_7106() {
  178. if (!empty($context['sandbox']['major_version_upgrade'][7106])) {
  179. // This udate is already part of latest 6.x
  180. return;
  181. }
  182. db_change_field('background_process', 'start', 'start_stamp', array(
  183. 'type' => 'varchar',
  184. 'length' => '18',
  185. 'not null' => FALSE,
  186. ));
  187. db_change_field('background_process', 'status', 'exec_status', array(
  188. 'type' => 'int',
  189. 'size' => 'normal',
  190. 'not null' => TRUE,
  191. 'default' => 0,
  192. ));
  193. }