elysia_cron.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the elysia_cron module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function elysia_cron_schema() {
  10. $schema['elysia_cron'] = array(
  11. 'fields' => array(
  12. 'name' => array(
  13. 'type' => 'varchar',
  14. 'length' => 120,
  15. 'not null' => TRUE,
  16. ),
  17. 'disable' => array(
  18. 'type' => 'int',
  19. 'size' => 'tiny',
  20. 'not null' => FALSE,
  21. ),
  22. 'rule' => array(
  23. 'type' => 'varchar',
  24. 'not null' => FALSE,
  25. 'length' => 256,
  26. ),
  27. 'weight' => array(
  28. 'type' => 'int',
  29. 'not null' => FALSE,
  30. ),
  31. 'context' => array(
  32. 'type' => 'varchar',
  33. 'not null' => FALSE,
  34. 'length' => 32,
  35. ),
  36. 'running' => array(
  37. 'type' => 'int',
  38. 'not null' => TRUE,
  39. 'default' => 0,
  40. 'no export' => TRUE,
  41. ),
  42. 'last_run' => array(
  43. 'type' => 'int',
  44. 'not null' => TRUE,
  45. 'default' => 0,
  46. 'no export' => TRUE,
  47. ),
  48. 'last_aborted' => array(
  49. 'type' => 'int',
  50. 'size' => 'tiny',
  51. 'not null' => TRUE,
  52. 'default' => 0,
  53. 'no export' => TRUE,
  54. ),
  55. 'abort_count' => array(
  56. 'type' => 'int',
  57. 'not null' => TRUE,
  58. 'default' => 0,
  59. 'no export' => TRUE,
  60. ),
  61. 'last_abort_function' => array(
  62. 'type' => 'varchar',
  63. 'length' => 128,
  64. 'no export' => TRUE,
  65. ),
  66. 'last_execution_time' => array(
  67. 'type' => 'int',
  68. 'not null' => TRUE,
  69. 'default' => 0,
  70. 'no export' => TRUE,
  71. ),
  72. 'execution_count' => array(
  73. 'type' => 'int',
  74. 'not null' => TRUE,
  75. 'default' => 0,
  76. 'no export' => TRUE,
  77. ),
  78. 'avg_execution_time' => array(
  79. 'type' => 'float',
  80. 'not null' => TRUE,
  81. 'default' => 0,
  82. 'no export' => TRUE,
  83. ),
  84. 'max_execution_time' => array(
  85. 'type' => 'int',
  86. 'not null' => TRUE,
  87. 'default' => 0,
  88. 'no export' => TRUE,
  89. ),
  90. 'last_shutdown_time' => array(
  91. 'type' => 'int',
  92. 'not null' => TRUE,
  93. 'default' => 0,
  94. 'no export' => TRUE,
  95. ),
  96. ),
  97. 'primary key' => array('name'),
  98. 'export' => array(
  99. 'key' => 'name',
  100. 'key name' => 'Cron job name',
  101. 'primary key' => 'name',
  102. 'identifier' => 'cron_rule',
  103. 'object factory' => 'elysia_cron_ctools_export_object_factory',
  104. 'load callback' => 'elysia_cron_ctools_export_load',
  105. 'load all callback' => 'elysia_cron_ctools_export_load_all',
  106. 'export callback' => 'elysia_cron_ctools_export_callback',
  107. 'to hook code callback' => 'elysia_cron_ctools_to_hook_code',
  108. 'default hook' => 'default_elysia_cron_rules',
  109. 'api' => array(
  110. 'owner' => 'elysia_cron',
  111. 'api' => 'default_elysia_cron_rules',
  112. 'minimum_version' => 1,
  113. 'current_version' => 1,
  114. ),
  115. ),
  116. );
  117. return $schema;
  118. }
  119. /**
  120. * Implements hook_install().
  121. */
  122. function elysia_cron_install() {
  123. // Elysia cron MUST be the first returned by module_list.
  124. // This is to ensure elysia_cron_cron is the first hook
  125. // called by standard cron.php.
  126. $query = db_select('system');
  127. $query->addExpression('MIN(weight)');
  128. $min = $query->execute()->fetchField();
  129. $min = ($min > -65535) ? -65535 : --$min;
  130. db_update('system')
  131. ->fields(array('weight' => $min))
  132. ->condition('name', 'elysia_cron')
  133. ->execute();
  134. }
  135. /**
  136. * Implements hook_uninstall().
  137. */
  138. function elysia_cron_uninstall() {
  139. $variables = db_select('variable', 'v')
  140. ->fields('v', array('name'))
  141. ->condition('v.name', 'elysia_cron_%', 'LIKE')
  142. ->execute()
  143. ->fetchCol();
  144. foreach ($variables as $name) {
  145. variable_del($name);
  146. }
  147. }
  148. /**
  149. * Use default cron_key variable.
  150. */
  151. function elysia_cron_update_7201() {
  152. $cron_key = variable_get('elysia_cron_key', FALSE);
  153. if ($cron_key) {
  154. variable_set('cron_key', $cron_key);
  155. }
  156. variable_del('elysia_cron_key');
  157. }
  158. /**
  159. * Increase elysia_cron last_abort_function size from 32 to 128 characters.
  160. */
  161. function elysia_cron_update_7202() {
  162. db_change_field('elysia_cron', 'last_abort_function', 'last_abort_function', array(
  163. 'type' => 'varchar',
  164. 'length' => 128,
  165. 'no export' => TRUE,
  166. ));
  167. }
  168. /**
  169. * Change length property of rule to 256 characters.
  170. */
  171. function elysia_cron_update_7203() {
  172. $spec = array(
  173. 'type' => 'varchar',
  174. 'not null' => FALSE,
  175. 'length' => 256,
  176. );
  177. db_change_field('elysia_cron', 'rule', 'rule', $spec);
  178. }
  179. /**
  180. * Remove unused variables.
  181. */
  182. function elysia_cron_update_7204() {
  183. variable_del('elysia_cron_version');
  184. }
  185. /**
  186. * Rename context variable to channel.
  187. */
  188. function elysia_cron_update_7205() {
  189. if ($last = variable_get('elysia_cron_last_context')) {
  190. variable_set('elysia_cron_last_channel', $last);
  191. }
  192. variable_del('elysia_cron_last_context');
  193. }