Compare commits
28 Commits
Author | SHA1 | Date |
---|---|---|
Michal Kleiner | 9881c03c22 | |
Guy Sartorelli | e8517ebfb0 | |
Michal Kleiner | 28ca036345 | |
Guy Sartorelli | 16caad30b2 | |
Maxime Rainville | 6f6c30bdcc | |
Guy Sartorelli | f918209e35 | |
Maxime Rainville | 714de64252 | |
Steve Boyd | d9d245a0da | |
Guy Sartorelli | 9d5f8fce7d | |
Guy Sartorelli | f12698f47f | |
Guy Sartorelli | 6f0d1c84f2 | |
Guy Sartorelli | 15a8bca241 | |
Steve Boyd | 94ff5b621c | |
Will Rossiter | 0e4867f736 | |
Steve Boyd | 7e59b7e88b | |
Steve Boyd | e4b8934148 | |
Guy Sartorelli | 737ac0d8ed | |
Steve Boyd | 3378dc7a99 | |
Steve Boyd | 58caa67c96 | |
Steve Boyd | 7be4c0dbf3 | |
Guy Sartorelli | 7ba4acc4b2 | |
Steve Boyd | a76c3b89ea | |
Guy Sartorelli | 7f6c03b0cb | |
Will Rossiter | 3e3907d14c | |
Guy Sartorelli | d3d20e5539 | |
Steve Boyd | b7554a5fc9 | |
Daniel Hensby | cb13f4ec12 | |
Steve Boyd | 3902a1d688 |
|
@ -0,0 +1,11 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
|
|
@ -0,0 +1,16 @@
|
|||
name: Dispatch CI
|
||||
|
||||
on:
|
||||
# At 1:20 PM UTC, only on Wednesday and Thursday
|
||||
schedule:
|
||||
- cron: '20 13 * * 3,4'
|
||||
|
||||
jobs:
|
||||
dispatch-ci:
|
||||
name: Dispatch CI
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dispatch CI
|
||||
uses: silverstripe/gha-dispatch-ci@v1
|
|
@ -0,0 +1,17 @@
|
|||
name: Keepalive
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# The 4th of every month at 10:50am UTC
|
||||
schedule:
|
||||
- cron: '50 10 4 * *'
|
||||
|
||||
jobs:
|
||||
keepalive:
|
||||
name: Keepalive
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Keepalive
|
||||
uses: silverstripe/gha-keepalive@v1
|
|
@ -1,15 +0,0 @@
|
|||
inherit: true
|
||||
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
tests:
|
||||
override: [php-scrutinizer-run]
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [src/*, tests/*]
|
|
@ -1,4 +0,0 @@
|
|||
version: ~> 1.0
|
||||
|
||||
import:
|
||||
- silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml
|
|
@ -1,11 +1,7 @@
|
|||
# SilverStripe Environment Checker Module
|
||||
# Silverstripe Environment Checker Module
|
||||
|
||||
[![Build Status](https://api.travis-ci.com/silverstripe/silverstripe-environmentcheck.svg?branch=2)](https://travis-ci.com/silverstripe/silverstripe-environmentcheck)
|
||||
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
[![Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/?branch=master)
|
||||
[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck)
|
||||
[![Version](http://img.shields.io/packagist/v/silverstripe/environmentcheck.svg?style=flat-square)](https://packagist.org/packages/silverstripe/environmentcheck)
|
||||
[![License](http://img.shields.io/packagist/l/silverstripe/environmentcheck.svg?style=flat-square)](LICENSE.md)
|
||||
[![CI](https://github.com/silverstripe/silverstripe-environmentcheck/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-environmentcheck/actions/workflows/ci.yml)
|
||||
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
|
||||
This module adds an API for running environment checks to your API.
|
||||
|
||||
|
@ -15,10 +11,10 @@ This module adds an API for running environment checks to your API.
|
|||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 4.x
|
||||
* Silverstripe 4.x
|
||||
* PHP 7.3
|
||||
|
||||
For SilverStripe 3.x support, please use a `1.x` tagged release.
|
||||
For Silverstripe 3.x support, please use a `1.x` tagged release.
|
||||
|
||||
## Aren't these just unit tests?
|
||||
|
||||
|
@ -86,6 +82,7 @@ SilverStripe\EnvironmentCheck\EnvironmentCheckSuite:
|
|||
* `HasClassCheck`: Check that the given class exists.
|
||||
This can be used to check that PHP modules or features are installed.
|
||||
* `FileWriteableCheck`: Check that the given file is writeable.
|
||||
* `FileAccessibilityAndValidationCheck`: Check that a given file is accessible and optionally matches a given format.
|
||||
* `FileAgeCheck`: Checks for the maximum age of one or more files or folders.
|
||||
Useful for files which should be frequently auto-generated,
|
||||
like static caches, as well as for backup files and folders.
|
||||
|
@ -111,7 +108,7 @@ SilverStripe\EnvironmentCheck\EnvironmentChecker:
|
|||
from_email_address: admin@test.com
|
||||
```
|
||||
|
||||
Errors can be logged via the standard SilverStripe PSR-3 compatible logging. Each check will cause an individual log
|
||||
Errors can be logged via the standard Silverstripe PSR-3 compatible logging. Each check will cause an individual log
|
||||
entry. You can choose to enable logging separately for warnings and errors, identified through the
|
||||
result of `EnvironmentCheck->check()`.
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"php": "^7.4 || ^8.0",
|
||||
"silverstripe/framework": "^4.10",
|
||||
"silverstripe/versioned": "^1.0",
|
||||
"guzzlehttp/guzzle": "^6.3.3 || ^7"
|
||||
|
@ -38,4 +38,4 @@
|
|||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
|
||||
|
||||
<testsuites>
|
||||
|
|
|
@ -109,9 +109,9 @@ class CacheHeadersCheck implements EnvironmentCheck
|
|||
// Filter good messages
|
||||
$goodTypes = [ValidationResult::TYPE_GOOD, ValidationResult::TYPE_INFO];
|
||||
$good = array_filter(
|
||||
$this->result->getMessages(),
|
||||
$this->result->getMessages() ?? [],
|
||||
function ($val, $key) use ($goodTypes) {
|
||||
if (in_array($val['messageType'], $goodTypes)) {
|
||||
if (in_array($val['messageType'], $goodTypes ?? [])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -119,15 +119,15 @@ class CacheHeadersCheck implements EnvironmentCheck
|
|||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
if (!empty($good)) {
|
||||
$ret .= "GOOD: " . implode('; ', array_column($good, 'message')) . " ";
|
||||
$ret .= "GOOD: " . implode('; ', array_column($good ?? [], 'message')) . " ";
|
||||
}
|
||||
|
||||
// Filter bad messages
|
||||
$badTypes = [ValidationResult::TYPE_ERROR, ValidationResult::TYPE_WARNING];
|
||||
$bad = array_filter(
|
||||
$this->result->getMessages(),
|
||||
$this->result->getMessages() ?? [],
|
||||
function ($val, $key) use ($badTypes) {
|
||||
if (in_array($val['messageType'], $badTypes)) {
|
||||
if (in_array($val['messageType'], $badTypes ?? [])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -135,7 +135,7 @@ class CacheHeadersCheck implements EnvironmentCheck
|
|||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
if (!empty($bad)) {
|
||||
$ret .= "BAD: " . implode('; ', array_column($bad, 'message'));
|
||||
$ret .= "BAD: " . implode('; ', array_column($bad ?? [], 'message'));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
@ -173,32 +173,32 @@ class CacheHeadersCheck implements EnvironmentCheck
|
|||
private function checkCacheControl(ResponseInterface $response)
|
||||
{
|
||||
$cacheControl = $response->getHeaderLine('Cache-Control');
|
||||
$vals = array_map('trim', explode(',', $cacheControl));
|
||||
$vals = array_map('trim', explode(',', $cacheControl ?? ''));
|
||||
$fullURL = Controller::join_links(Director::absoluteBaseURL(), $this->url);
|
||||
|
||||
// All entries from must contain should be present
|
||||
if ($this->mustInclude == array_intersect($this->mustInclude, $vals)) {
|
||||
if ($this->mustInclude == array_intersect($this->mustInclude ?? [], $vals)) {
|
||||
$matched = implode(",", $this->mustInclude);
|
||||
$this->result->addMessage(
|
||||
"$fullURL includes all settings: {$matched}",
|
||||
ValidationResult::TYPE_GOOD
|
||||
);
|
||||
} else {
|
||||
$missing = implode(",", array_diff($this->mustInclude, $vals));
|
||||
$missing = implode(",", array_diff($this->mustInclude ?? [], $vals));
|
||||
$this->result->addError(
|
||||
"$fullURL is excluding some settings: {$missing}"
|
||||
);
|
||||
}
|
||||
|
||||
// All entries from must exclude should not be present
|
||||
if (empty(array_intersect($this->mustExclude, $vals))) {
|
||||
if (empty(array_intersect($this->mustExclude ?? [], $vals))) {
|
||||
$missing = implode(",", $this->mustExclude);
|
||||
$this->result->addMessage(
|
||||
"$fullURL excludes all settings: {$missing}",
|
||||
ValidationResult::TYPE_GOOD
|
||||
);
|
||||
} else {
|
||||
$matched = implode(",", array_intersect($this->mustExclude, $vals));
|
||||
$matched = implode(",", array_intersect($this->mustExclude ?? [], $vals));
|
||||
$this->result->addError(
|
||||
"$fullURL is including some settings: {$matched}"
|
||||
);
|
||||
|
|
|
@ -37,7 +37,7 @@ class ExternalURLCheck implements EnvironmentCheck
|
|||
public function __construct($urls, $timeout = 15)
|
||||
{
|
||||
if ($urls) {
|
||||
$this->urls = explode(' ', $urls);
|
||||
$this->urls = explode(' ', $urls ?? '');
|
||||
}
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class ExternalURLCheck implements EnvironmentCheck
|
|||
foreach ($urls as $url) {
|
||||
$ch = curl_init();
|
||||
$chs[] = $ch;
|
||||
curl_setopt_array($ch, $this->getCurlOpts($url));
|
||||
curl_setopt_array($ch, $this->getCurlOpts($url) ?? []);
|
||||
}
|
||||
// Parallel execution for faster performance
|
||||
$mh = curl_multi_init();
|
||||
|
|
|
@ -96,7 +96,7 @@ class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
|||
$files = $this->getFiles();
|
||||
if ($files) {
|
||||
$fileTypeValidateFunc = $this->fileTypeValidateFunc;
|
||||
if (method_exists($this, $fileTypeValidateFunc)) {
|
||||
if (method_exists($this, $fileTypeValidateFunc ?? '')) {
|
||||
$invalidFiles = [];
|
||||
$validFiles = [];
|
||||
|
||||
|
@ -109,7 +109,7 @@ class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
|||
}
|
||||
|
||||
// If at least one file was valid, count as passed
|
||||
if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
|
||||
if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles ?? []) < count($files ?? [])) {
|
||||
$validFileList = PHP_EOL;
|
||||
foreach ($validFiles as $vf) {
|
||||
$validFileList .= $vf . PHP_EOL;
|
||||
|
@ -130,7 +130,7 @@ class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
|||
];
|
||||
}
|
||||
} else {
|
||||
if (count($invalidFiles) == 0) {
|
||||
if (count($invalidFiles ?? []) == 0) {
|
||||
$checkReturn = [EnvironmentCheck::OK, 'All files valideted'];
|
||||
} else {
|
||||
$invalidFileList = PHP_EOL;
|
||||
|
@ -180,7 +180,7 @@ class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
|||
*/
|
||||
private function jsonValidate($file)
|
||||
{
|
||||
$json = json_decode(file_get_contents($file));
|
||||
$json = json_decode(file_get_contents($file ?? '') ?? '');
|
||||
if (!$json) {
|
||||
return false;
|
||||
}
|
||||
|
@ -204,6 +204,6 @@ class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
|||
*/
|
||||
protected function getFiles()
|
||||
{
|
||||
return glob($this->path);
|
||||
return glob($this->path ?? '');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ class FileAgeCheck implements EnvironmentCheck
|
|||
*/
|
||||
public function check()
|
||||
{
|
||||
$cutoffTime = strtotime($this->relativeAge, DBDatetime::now()->Format('U'));
|
||||
$cutoffTime = strtotime($this->relativeAge ?? '', DBDatetime::now()->Format('U'));
|
||||
$files = $this->getFiles();
|
||||
$invalidFiles = [];
|
||||
$validFiles = [];
|
||||
|
@ -127,10 +127,10 @@ class FileAgeCheck implements EnvironmentCheck
|
|||
}
|
||||
|
||||
// If at least one file was valid, count as passed
|
||||
if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
|
||||
if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles ?? []) < count($files ?? [])) {
|
||||
return [EnvironmentCheck::OK, ''];
|
||||
}
|
||||
if (count($invalidFiles) == 0) {
|
||||
if (count($invalidFiles ?? []) == 0) {
|
||||
return [EnvironmentCheck::OK, ''];
|
||||
}
|
||||
return [
|
||||
|
@ -146,6 +146,6 @@ class FileAgeCheck implements EnvironmentCheck
|
|||
*/
|
||||
protected function getFiles()
|
||||
{
|
||||
return glob($this->path);
|
||||
return glob($this->path ?? '');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,22 +34,22 @@ class FileWriteableCheck implements EnvironmentCheck
|
|||
if ($this->path[0] == '/') {
|
||||
$filename = $this->path;
|
||||
} else {
|
||||
$filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
|
||||
$filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path ?? '');
|
||||
}
|
||||
|
||||
if (file_exists($filename)) {
|
||||
$isWriteable = is_writeable($filename);
|
||||
if (file_exists($filename ?? '')) {
|
||||
$isWriteable = is_writeable($filename ?? '');
|
||||
} else {
|
||||
$isWriteable = is_writeable(dirname($filename));
|
||||
$isWriteable = is_writeable(dirname($filename ?? ''));
|
||||
}
|
||||
|
||||
if (!$isWriteable) {
|
||||
if (function_exists('posix_getgroups')) {
|
||||
$userID = posix_geteuid();
|
||||
$user = posix_getpwuid($userID);
|
||||
$user = posix_getpwuid($userID ?? 0);
|
||||
|
||||
$currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
|
||||
$currentOwner = posix_getpwuid($currentOwnerID);
|
||||
$currentOwnerID = fileowner(file_exists($filename ?? '') ? $filename : dirname($filename ?? ''));
|
||||
$currentOwner = posix_getpwuid($currentOwnerID ?? 0);
|
||||
|
||||
$message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is "
|
||||
. "currently owned by '$currentOwner[name]'. ";
|
||||
|
@ -60,8 +60,8 @@ class FileWriteableCheck implements EnvironmentCheck
|
|||
$groups = posix_getgroups();
|
||||
$groupList = [];
|
||||
foreach ($groups as $group) {
|
||||
$groupInfo = posix_getgrgid($group);
|
||||
if (in_array($currentOwner['name'], $groupInfo['members'])) {
|
||||
$groupInfo = posix_getgrgid($group ?? 0);
|
||||
if (in_array($currentOwner['name'], $groupInfo['members'] ?? [])) {
|
||||
$groupList[] = $groupInfo['name'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class HasClassCheck implements EnvironmentCheck
|
|||
*/
|
||||
public function check()
|
||||
{
|
||||
if (class_exists($this->className)) {
|
||||
if (class_exists($this->className ?? '')) {
|
||||
return [EnvironmentCheck::OK, 'Class ' . $this->className.' exists'];
|
||||
}
|
||||
return [EnvironmentCheck::ERROR, 'Class ' . $this->className.' doesn\'t exist'];
|
||||
|
|
|
@ -31,7 +31,7 @@ class HasFunctionCheck implements EnvironmentCheck
|
|||
*/
|
||||
public function check()
|
||||
{
|
||||
if (function_exists($this->functionName)) {
|
||||
if (function_exists($this->functionName ?? '')) {
|
||||
return [EnvironmentCheck::OK, $this->functionName . '() exists'];
|
||||
}
|
||||
return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist'];
|
||||
|
|
|
@ -57,7 +57,7 @@ class SMTPConnectCheck implements EnvironmentCheck
|
|||
*/
|
||||
public function check()
|
||||
{
|
||||
$f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
|
||||
$f = @fsockopen($this->host ?? '', $this->port ?? 0, $errno, $errstr, $this->timeout);
|
||||
if (!$f) {
|
||||
return [
|
||||
EnvironmentCheck::ERROR,
|
||||
|
@ -67,7 +67,7 @@ class SMTPConnectCheck implements EnvironmentCheck
|
|||
|
||||
fwrite($f, "HELO its_me\r\n");
|
||||
$response = fread($f, 26);
|
||||
if (substr($response, 0, 3) != '220') {
|
||||
if (substr($response ?? '', 0, 3) != '220') {
|
||||
return [
|
||||
EnvironmentCheck::ERROR,
|
||||
sprintf('Invalid mail server response: %s', $response)
|
||||
|
|
|
@ -62,7 +62,7 @@ class SessionCheck implements EnvironmentCheck
|
|||
$cookies = $response->getHeader('Set-Cookie');
|
||||
|
||||
foreach ($cookies as $cookie) {
|
||||
if (strpos($cookie, 'SESSID') !== false) {
|
||||
if (strpos($cookie ?? '', 'SESSID') !== false) {
|
||||
$result = $cookie;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class SolrIndexCheck implements EnvironmentCheck
|
|||
if (!empty($brokenCores)) {
|
||||
return [
|
||||
EnvironmentCheck::ERROR,
|
||||
'The following indexes are unavailable: ' . implode($brokenCores, ', ')
|
||||
'The following indexes are unavailable: ' . implode(', ', $brokenCores)
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class URLCheck implements EnvironmentCheck
|
|||
EnvironmentCheck::ERROR,
|
||||
sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode())
|
||||
];
|
||||
} elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) {
|
||||
} elseif ($this->testString && (strpos($response->getBody() ?? '', $this->testString ?? '') === false)) {
|
||||
return [
|
||||
EnvironmentCheck::WARNING,
|
||||
sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString)
|
||||
|
|
|
@ -43,8 +43,11 @@ class DevCheckController extends Controller
|
|||
$suite = $name;
|
||||
}
|
||||
|
||||
$checker = new EnvironmentChecker($suite, 'Environment status');
|
||||
$checker->setRequest($request);
|
||||
/** @var EnvironmentChecker */
|
||||
$checker = EnvironmentChecker::create($suite, 'Environment status')
|
||||
->setRequest($request)
|
||||
->setIncludeDetails(true);
|
||||
|
||||
$checker->init($this->config()->permission);
|
||||
|
||||
return $checker;
|
||||
|
|
|
@ -28,7 +28,6 @@ class DevHealthController extends Controller
|
|||
public function index()
|
||||
{
|
||||
// health check does not require permission to run
|
||||
|
||||
$checker = new EnvironmentChecker('health', 'Site health');
|
||||
$checker->setErrorCode(500);
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ class EnvironmentChecker extends RequestHandler
|
|||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $includeDetails = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -172,19 +177,31 @@ class EnvironmentChecker extends RequestHandler
|
|||
$response->setStatusCode($this->errorCode);
|
||||
}
|
||||
|
||||
$resultText = $result->customise([
|
||||
$data = [
|
||||
'URL' => Director::absoluteBaseURL(),
|
||||
'Title' => $this->title,
|
||||
'Name' => $this->checkSuiteName,
|
||||
'ErrorCode' => $this->errorCode,
|
||||
])->renderWith(__CLASS__);
|
||||
'ErrorCode' => $this->errorCode
|
||||
];
|
||||
|
||||
$emailContent = $result->customise(array_merge($data, [
|
||||
'IncludeDetails' => true
|
||||
]))->renderWith(__CLASS__);
|
||||
|
||||
if (!$this->includeDetails) {
|
||||
$webContent = $result->customise(array_merge($data, [
|
||||
'IncludeDetails' => false
|
||||
]))->renderWith(__CLASS__);
|
||||
} else {
|
||||
$webContent = $emailContent;
|
||||
}
|
||||
|
||||
if ($this->config()->get('email_results') && !$result->ShouldPass()) {
|
||||
$email = new Email(
|
||||
$this->config()->get('from_email_address'),
|
||||
$this->config()->get('to_email_address'),
|
||||
$this->title,
|
||||
$resultText
|
||||
$emailContent
|
||||
);
|
||||
$email->send();
|
||||
}
|
||||
|
@ -206,14 +223,14 @@ class EnvironmentChecker extends RequestHandler
|
|||
|
||||
// output the result as JSON if requested
|
||||
if ($this->getRequest()->getExtension() == 'json'
|
||||
|| strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false
|
||||
|| strpos($this->getRequest()->getHeader('Accept') ?? '', 'application/json') !== false
|
||||
) {
|
||||
$response->setBody($result->toJSON());
|
||||
$response->addHeader('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->setBody($resultText);
|
||||
$response->setBody($webContent);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
@ -229,73 +246,92 @@ class EnvironmentChecker extends RequestHandler
|
|||
Injector::inst()->get(LoggerInterface::class)->log($level, $message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the HTTP status code that should be returned when there's an error.
|
||||
*
|
||||
* @param int $errorCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setErrorCode($errorCode)
|
||||
{
|
||||
$this->errorCode = $errorCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Set whether to include the full breakdown of services
|
||||
*
|
||||
* @param bool $includeDetails
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIncludeDetails($includeDetails)
|
||||
{
|
||||
$this->includeDetails = $includeDetails;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @param string $from
|
||||
*/
|
||||
public static function set_from_email_address($from)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
static::config()->set('from_email_address', $from);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @return null|string
|
||||
*/
|
||||
public static function get_from_email_address()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
return static::config()->get('from_email_address');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @param string $to
|
||||
*/
|
||||
public static function set_to_email_address($to)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
static::config()->set('to_email_address', $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @return null|string
|
||||
*/
|
||||
public static function get_to_email_address()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
return static::config()->get('to_email_address');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @param bool $results
|
||||
*/
|
||||
public static function set_email_results($results)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
static::config()->set('email_results', $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 2.0.0 Use config API instead
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_email_results()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use config API instead');
|
||||
Deprecation::notice('2.0.0', 'Use config API instead');
|
||||
return static::config()->get('email_results');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,16 +64,18 @@
|
|||
<h1 class="$Status">$Title: $Status</h1>
|
||||
<h2 class="website">Site: $URL</h2>
|
||||
|
||||
<% if $IncludeDetails %>
|
||||
<table>
|
||||
<tr><th>Check</th> <th>Status</th> <th>Message</th></tr>
|
||||
<% loop $Details %>
|
||||
<tr><td>$Check</td> <td class="$Status">$Status</td> <td>$Message.XML</td></tr>
|
||||
<% end_loop %>
|
||||
</table>
|
||||
<% end_if %>
|
||||
|
||||
<% if $ShouldPass %>
|
||||
<p>Site is available</p>
|
||||
<p class="subtext">(you may check for the presence of the text 'Site is available' rather than an HTTP $ErrorCode error on this page, if you prefer.)</p>
|
||||
<p>Site is available</p>
|
||||
<p class="subtext">(you may check for the presence of the text 'Site is available' rather than an HTTP $ErrorCode error on this page, if you prefer.<% if not $IncludeDetails %> Full details are available for logged in users at <a href="{$AbsoluteBaseURL}dev/check/">dev/check</a><% end_if %>)</p>
|
||||
<% else %>
|
||||
<% if $Name == "check" %>
|
||||
<p><b>A subsystem of the site is unavailable, but the site remains operational</b></p>
|
||||
|
|
|
@ -28,4 +28,14 @@ class DevCheckControllerTest extends SapphireTest
|
|||
|
||||
$this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
|
||||
}
|
||||
|
||||
public function testCheckIncludesDetails()
|
||||
{
|
||||
$controller = new DevCheckController();
|
||||
$request = new HTTPRequest('GET', 'example.com');
|
||||
|
||||
$response = $controller->index($request)->index();
|
||||
|
||||
$this->assertStringContainsString('<table>', $response->getBody());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,15 @@ class DevHealthControllerTest extends SapphireTest
|
|||
|
||||
$this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
|
||||
}
|
||||
|
||||
|
||||
public function testHealthDoesNotIncludeDetails()
|
||||
{
|
||||
$controller = new DevHealthController();
|
||||
$request = new HTTPRequest('GET', 'example.com');
|
||||
|
||||
$response = $controller->index($request)->index();
|
||||
|
||||
$this->assertFalse(strpos($response->getBody(), '<table>'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue