elysia_cron.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. function elysia_cron_schema() {
  3. $schema['elysia_cron'] = array(
  4. 'fields' => array(
  5. 'name' => array(
  6. 'type' => 'varchar',
  7. 'length' => 120,
  8. 'not null' => TRUE,
  9. ),
  10. 'disable' => array(
  11. 'type' => 'int',
  12. 'size' => 'tiny',
  13. 'not null' => FALSE,
  14. ),
  15. 'rule' => array(
  16. 'type' => 'varchar',
  17. 'not null' => FALSE,
  18. 'length' => 32,
  19. ),
  20. 'weight' => array(
  21. 'type' => 'int',
  22. 'not null' => FALSE,
  23. ),
  24. 'context' => array(
  25. 'type' => 'varchar',
  26. 'not null' => FALSE,
  27. 'length' => 32,
  28. ),
  29. 'running' => array(
  30. 'type' => 'int',
  31. 'not null' => TRUE,
  32. 'default' => 0,
  33. 'no export' => TRUE,
  34. ),
  35. 'last_run' => array(
  36. 'type' => 'int',
  37. 'not null' => TRUE,
  38. 'default' => 0,
  39. 'no export' => TRUE,
  40. ),
  41. 'last_aborted' => array(
  42. 'type' => 'int',
  43. 'size' => 'tiny',
  44. 'not null' => TRUE,
  45. 'default' => 0,
  46. 'no export' => TRUE,
  47. ),
  48. 'abort_count' => array(
  49. 'type' => 'int',
  50. 'not null' => TRUE,
  51. 'default' => 0,
  52. 'no export' => TRUE,
  53. ),
  54. 'last_abort_function' => array(
  55. 'type' => 'varchar',
  56. 'length' => 32,
  57. 'no export' => TRUE,
  58. ),
  59. 'last_execution_time' => array(
  60. 'type' => 'int',
  61. 'not null' => TRUE,
  62. 'default' => 0,
  63. 'no export' => TRUE,
  64. ),
  65. 'execution_count' => array(
  66. 'type' => 'int',
  67. 'not null' => TRUE,
  68. 'default' => 0,
  69. 'no export' => TRUE,
  70. ),
  71. 'avg_execution_time' => array(
  72. 'type' => 'float',
  73. 'not null' => TRUE,
  74. 'default' => 0,
  75. 'no export' => TRUE,
  76. ),
  77. 'max_execution_time' => array(
  78. 'type' => 'int',
  79. 'not null' => TRUE,
  80. 'default' => 0,
  81. 'no export' => TRUE,
  82. ),
  83. 'last_shutdown_time' => array(
  84. 'type' => 'int',
  85. 'not null' => TRUE,
  86. 'default' => 0,
  87. 'no export' => TRUE,
  88. ),
  89. ),
  90. 'primary key' => array('name'),
  91. 'export' => array(
  92. 'key' => 'name',
  93. 'key name' => 'Cron job name',
  94. 'primary key' => 'name',
  95. 'identifier' => 'cron_rule',
  96. 'object factory' => 'elysia_cron_ctools_export_object_factory',
  97. 'load callback' => 'elysia_cron_ctools_export_load',
  98. 'load all callback' => 'elysia_cron_ctools_export_load_all',
  99. //'save callback' => 'elysia_cron_ctools_export_save',
  100. 'export callback' => 'elysia_cron_ctools_export_callback',
  101. //'import callback' => 'elysia_cron_ctools_import_callback',
  102. 'to hook code callback' => 'elysia_cron_ctools_to_hook_code',
  103. 'default hook' => 'default_elysia_cron_rules',
  104. 'api' => array(
  105. 'owner' => 'elysia_cron',
  106. 'api' => 'default_elysia_cron_rules',
  107. 'minimum_version' => 1,
  108. 'current_version' => 1,
  109. ),
  110. ),
  111. );
  112. return $schema;
  113. }
  114. /**
  115. * Implementation of hook_install().
  116. */
  117. function elysia_cron_install() {
  118. //drupal_install_schema('elysia_cron');
  119. // elysia_cron MUST be the first returned by module_list
  120. // This is to ensure elysia_cron_cron is the first hook called by standard cron.php.
  121. $min = db_query("select min(weight) from {system}")->fetchField();
  122. if ($min > -65535) {
  123. $min = -65535;
  124. }
  125. else {
  126. $min--;
  127. }
  128. db_update('system')->fields(array('weight' => $min))->condition('name', 'elysia_cron')->execute();
  129. variable_set('elysia_cron_version', elysia_cron_version());
  130. drupal_set_message('Elysia cron installed. Setup could be found at ' . l(t('Settings page'), 'admin/config/system/cron') . '. See INSTALL.TXT for more info.');
  131. }
  132. /**
  133. * Implementation of hook_uninstall().
  134. */
  135. function elysia_cron_uninstall() {
  136. $rs = db_query("select name from {variable} where name like 'elysia_cron_%%'");
  137. foreach ($rs as $o) {
  138. variable_del($o->name);
  139. }
  140. //drupal_uninstall_schema('elysia_cron');
  141. drupal_set_message('Elysia cron uninstalled.');
  142. }
  143. function elysia_cron_update_1() {
  144. $cron_key = variable_get('elysia_cron_key', false);
  145. if ($cron_key) {
  146. variable_set('cron_key', $cron_key);
  147. }
  148. variable_del('elysia_cron_key');
  149. }