Skip to content

Commit

Permalink
Added environment check #185
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Jan 19, 2022
1 parent 0930d5b commit d8039ec
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
94 changes: 94 additions & 0 deletions classes/check/envage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Check env refresh age
*
* @package local_envbar
* @author 2021 Brendan Heywood ([email protected])
* @copyright Catalyst IT Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_envbar\check;

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

use core\check\check;
use core\check\result;
use local_envbar\local\envbarlib;

/**
* Check env refresh age
*
* @package local_envbar
* @author 2021 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class envage extends check {

/**
* Constructor
*/
public function __construct() {
global $CFG;
$this->id = 'envage';
$this->name = get_string('checkenvage', 'local_envbar');
}

/**
* A link to a place to action this
*
* @return \action_link|null
*/
public function get_action_link(): ?\action_link {
return new \action_link(
new \moodle_url('/local/envbar/index.php'),
get_string('menuenvsettings', 'local_envbar'));
}

/**
* Return result
* @return result
*/
public function get_result(): result {
global $CFG;

if (envbarlib::getprodwwwroot() === $CFG->wwwroot) {
return new result(result::NA, get_string('prodwwwroottext', 'local_envbar'), '');
}

$lastrefresh = get_config('local_envbar', 'prodlastcheck');

// This takes the lastrefresh timestamp and displays it similar to how it appears in
// the headers such as 'Friday, 27 August 2021 - 144 days old.'.
if ($lastrefresh && $lastrefresh > 0) {
$format = get_string('strftimedatemonthabbr', 'langconfig');
$summary = userdate($lastrefresh, get_string('strftimedaydate', 'langconfig'));

$show = format_time(time() - $lastrefresh);
$num = strtok($show, ' ');
$unit = strtok(' ');
$show = "$num $unit";
$summary .= ' - ' . get_string('refreshedago', 'local_envbar', $show);
} else {
$summary = get_string('refreshednever', 'local_envbar');
}

return new result(result::INFO, $summary, '');
}
}

1 change: 1 addition & 0 deletions lang/en/local_envbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$string['addfields'] = 'Add another environment';
$string['bgcolour'] = 'Background colour';
$string['cachedef_records'] = 'The environment bar database records';
$string['checkenvage'] = 'Check environment refresh age';
$string['colourerror'] = 'Invalid HTML color code specified.';
$string['colourplaceholder'] = 'HTML color code. e.g. #fff OR #000000';
$string['configureinprod'] = 'Edit config';
Expand Down
11 changes: 11 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@

use local_envbar\local\envbarlib;

/**
* Add cron related service status checks
*
* @return array of check objects
*/
function local_envbar_security_checks(): array {
return [
new \local_envbar\check\envage(),
];
}

/**
* This is the hook enables the plugin to insert a chunk of html at the start of the html document.
*/
Expand Down
2 changes: 2 additions & 0 deletions service/updatelastrefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

use local_envbar\local\envbarlib;

define('NO_MOODLE_COOKIES', true);

require_once(dirname(__FILE__) . '/../../../config.php');

$wwwroot = required_param('wwwroot', PARAM_RAW);
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}

$plugin->version = 2022011400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022011400; // Same as version
$plugin->version = 2022011401; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022011401; // Same as version
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
$plugin->component = "local_envbar";
$plugin->component = 'local_envbar';
$plugin->maturity = MATURITY_STABLE;
$plugin->supported = [310, 311]; // A range of branch numbers of supported moodle versions.

0 comments on commit d8039ec

Please sign in to comment.