Skip to content

Commit 3d0710b

Browse files
Added environment check #185
1 parent 8dc18fa commit 3d0710b

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

classes/check/envage.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Check env refresh age
19+
*
20+
* @package tool_task
21+
* @author 2021 Brendan Heywood ([email protected])
22+
* @copyright Catalyst IT Pty Ltd
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
namespace local_envbar\check;
27+
28+
defined('MOODLE_INTERNAL') || die();
29+
30+
use core\check\check;
31+
use core\check\result;
32+
use local_envbar\local\envbarlib;
33+
34+
/**
35+
* Check env refresh age
36+
*
37+
* @package tool_task
38+
* @author 2021 Brendan Heywood ([email protected])
39+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40+
*/
41+
class envage extends check {
42+
43+
/**
44+
* Constructor
45+
*/
46+
public function __construct() {
47+
global $CFG;
48+
$this->id = 'envage';
49+
$this->name = get_string('checkenvage', 'local_envbar');
50+
}
51+
52+
/**
53+
* A link to a place to action this
54+
*
55+
* @return action_link|null
56+
*/
57+
public function get_action_link(): ?\action_link {
58+
return new \action_link(
59+
new \moodle_url('/local/envbar/index.php'),
60+
get_string('menuenvsettings', 'local_envbar'));
61+
}
62+
63+
/**
64+
* Return result
65+
* @return result
66+
*/
67+
public function get_result() : result {
68+
global $CFG;
69+
70+
if (envbarlib::getprodwwwroot() === $CFG->wwwroot) {
71+
return new result(result::NA, get_string('prodwwwroottext', 'local_envbar'), '');
72+
}
73+
74+
$lastrefresh = get_config('local_envbar', 'prodlastcheck');
75+
76+
if ($lastrefresh && $lastrefresh > 0) {
77+
$format = get_string('strftimedatemonthabbr', 'langconfig');
78+
$summary = userdate($lastrefresh, get_string('strftimedaydate', 'langconfig'));
79+
80+
$show = format_time(time() - $lastrefresh);
81+
$num = strtok($show, ' ');
82+
$unit = strtok(' ');
83+
$show = "$num $unit";
84+
$summary .= ' - ' . get_string('refreshedago', 'local_envbar', $show);
85+
} else {
86+
$summary = get_string('refreshednever', 'local_envbar');
87+
}
88+
89+
return new result(result::INFO, $summary, '');
90+
}
91+
}
92+

lang/en/local_envbar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
$string['addfields'] = 'Add another environment';
2727
$string['bgcolour'] = 'Background colour';
2828
$string['cachedef_records'] = 'The environment bar database records';
29+
$string['checkenvage'] = 'Check environment refresh age';
2930
$string['colourerror'] = 'Invalid HTML color code specified.';
3031
$string['colourplaceholder'] = 'HTML color code. e.g. #fff OR #000000';
3132
$string['configureinprod'] = 'Edit config';

lib.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828

2929
defined('MOODLE_INTERNAL') || die;
3030

31+
/**
32+
* Add cron related service status checks
33+
*
34+
* @return array of check objects
35+
*/
36+
function local_envbar_security_checks() : array {
37+
return [
38+
new \local_envbar\check\envage(),
39+
];
40+
}
41+
3142
/**
3243
* This is the hook enables the plugin to insert a chunk of html at the start of the html document.
3344
*/

service/updatelastrefresh.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
use local_envbar\local\envbarlib;
3030

31+
define('NO_MOODLE_COOKIES', true);
32+
3133
require_once(dirname(__FILE__) . '/../../../config.php');
3234

3335
$wwwroot = required_param('wwwroot', PARAM_RAW);

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
3030
}
3131

32-
$plugin->version = 2021011911; // The current plugin version (Date: YYYYMMDDXX).
33-
$plugin->release = 2021011910; // Same as version
32+
$plugin->version = 2021122110; // The current plugin version (Date: YYYYMMDDXX).
33+
$plugin->release = 2021122110; // Same as version
3434
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
3535
$plugin->component = "local_envbar";
3636
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)