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 Dec 21, 2021
1 parent 8dc18fa commit 3d0710b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
92 changes: 92 additions & 0 deletions classes/check/envage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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 tool_task
* @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 tool_task
* @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');

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 @@ -28,6 +28,17 @@

defined('MOODLE_INTERNAL') || die;

/**
* 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
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}

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

0 comments on commit 3d0710b

Please sign in to comment.