munin_api.install 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * Munin API for Drupal: installation and runtime checks.
  5. *
  6. * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  7. *
  8. * Licensed under the General Public License version 2 or later.
  9. */
  10. use Drupal\munin_api\Munin;
  11. require_once __DIR__ . '/src/Munin.php';
  12. /**
  13. * Implements hook_requirements().
  14. */
  15. function munin_api_requirements($phase) {
  16. $ret = array();
  17. $t = get_t();
  18. if ($phase == 'runtime') {
  19. $count = count(module_implements(Munin::HOOK_INFO));
  20. switch ($count) {
  21. case 0:
  22. $req = [
  23. 'title' => $t('Munin plugin modules'),
  24. 'value' => $t('No plugin found'),
  25. 'description' => $t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
  26. 'severity' => REQUIREMENT_ERROR,
  27. ];
  28. break;
  29. case 1:
  30. $req = [
  31. 'title' => $t('Munin plugin modules'),
  32. 'value' => $t('No Munin plugin module enabled beyond API'),
  33. 'description' => $t('Munin API is enabled, but no plugin module is enabled to report to it except the one built within the API. You should either <a href="!link">enable some plugin modules</a> or <a href="!link">disable and uninstall Munin API</a>.', [
  34. '!link' => url('admin/modules'),
  35. ]),
  36. 'severity' => REQUIREMENT_INFO,
  37. ];
  38. break;
  39. default:
  40. $req = [
  41. 'title' => $t('Munin plugin modules'),
  42. // Format plural although $count >= 2 because some languages have
  43. // several plural forms.
  44. 'value' => format_plural($count, '1 Munin plugin enabled.',
  45. '<a href="!link">@count Munin plugins</a> enabled.', [
  46. '!link' => url(Munin::R_REPORTS),
  47. ]
  48. ),
  49. 'severity' => REQUIREMENT_OK,
  50. ];
  51. }
  52. $ret[] = $req;
  53. }
  54. elseif ($phase != 'install') {
  55. // This should never happen and points to a severe error somewhere.
  56. watchdog(Munin::MODULE, 'Invalid phase %phase passed to %function', [
  57. '%phase' => $phase,
  58. '%function' => __FUNCTION__,
  59. ], WATCHDOG_ERROR);
  60. }
  61. /* else $phase == 'install', nothing to do. */
  62. return $ret;
  63. }
  64. /**
  65. * Implements hook_install().
  66. */
  67. function munin_api_install() {
  68. variable_set(Munin::V_INIT_PATH, Munin::D_INIT_PATH);
  69. variable_set(Munin::V_LAST, 0);
  70. // Ensure reporting is indeed opt-in, forcing default to off.
  71. variable_set(Munin::V_NEXT_REPORT, 0);
  72. variable_set(Munin::V_WATCHDOG, Munin::D_WATCHDOG);
  73. }
  74. /**
  75. * Implements hook_uninstall().
  76. */
  77. function munin_api_uninstall() {
  78. $vars = [
  79. Munin::V_INIT_PATH,
  80. Munin::V_LAST,
  81. Munin::V_NEXT_REPORT,
  82. Munin::V_WATCHDOG,
  83. ];
  84. foreach ($vars as $var) {
  85. variable_del($var);
  86. }
  87. }