123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- /**
- * @file
- * Munin API for Drupal: installation and runtime checks.
- *
- * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
- *
- * Licensed under the General Public License version 2 or later.
- */
- use Drupal\munin_api\Munin;
- require_once __DIR__ . '/src/Munin.php';
- /**
- * Implements hook_requirements().
- */
- function munin_api_requirements($phase) {
- $ret = array();
- $t = get_t();
- if ($phase == 'runtime') {
- $count = count(module_implements(Munin::HOOK_INFO));
- switch ($count) {
- case 0:
- $req = [
- 'title' => $t('Munin plugin modules'),
- 'value' => $t('No plugin found'),
- 'description' => $t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
- 'severity' => REQUIREMENT_ERROR,
- ];
- break;
- case 1:
- $req = [
- 'title' => $t('Munin plugin modules'),
- 'value' => $t('No Munin plugin module enabled beyond API'),
- '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>.', [
- '!link' => url('admin/modules'),
- ]),
- 'severity' => REQUIREMENT_INFO,
- ];
- break;
- default:
- $req = [
- 'title' => $t('Munin plugin modules'),
- // Format plural although $count >= 2 because some languages have
- // several plural forms.
- 'value' => format_plural($count, '1 Munin plugin enabled.',
- '<a href="!link">@count Munin plugins</a> enabled.', [
- '!link' => url(Munin::R_REPORTS),
- ]
- ),
- 'severity' => REQUIREMENT_OK,
- ];
- }
- $ret[] = $req;
- }
- elseif ($phase != 'install') {
- // This should never happen and points to a severe error somewhere.
- watchdog(Munin::MODULE, 'Invalid phase %phase passed to %function', [
- '%phase' => $phase,
- '%function' => __FUNCTION__,
- ], WATCHDOG_ERROR);
- }
- /* else $phase == 'install', nothing to do. */
- return $ret;
- }
- /**
- * Implements hook_install().
- */
- function munin_api_install() {
- variable_set(Munin::V_INIT_PATH, Munin::D_INIT_PATH);
- variable_set(Munin::V_LAST, 0);
- // Ensure reporting is indeed opt-in, forcing default to off.
- variable_set(Munin::V_NEXT_REPORT, 0);
- variable_set(Munin::V_WATCHDOG, Munin::D_WATCHDOG);
- }
- /**
- * Implements hook_uninstall().
- */
- function munin_api_uninstall() {
- $vars = [
- Munin::V_INIT_PATH,
- Munin::V_LAST,
- Munin::V_NEXT_REPORT,
- Munin::V_WATCHDOG,
- ];
- foreach ($vars as $var) {
- variable_del($var);
- }
- }
|