@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class DevHealthController extends Controller |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - private static $allowed_actions = [ |
|
| 19 | - 'index' |
|
| 20 | - ]; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + private static $allowed_actions = [ |
|
| 19 | + 'index' |
|
| 20 | + ]; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return EnvironmentChecker |
|
| 24 | - * |
|
| 25 | - * @throws HTTPResponse_Exception |
|
| 26 | - */ |
|
| 27 | - public function index() |
|
| 28 | - { |
|
| 29 | - // health check does not require permission to run |
|
| 22 | + /** |
|
| 23 | + * @return EnvironmentChecker |
|
| 24 | + * |
|
| 25 | + * @throws HTTPResponse_Exception |
|
| 26 | + */ |
|
| 27 | + public function index() |
|
| 28 | + { |
|
| 29 | + // health check does not require permission to run |
|
| 30 | 30 | |
| 31 | - $checker = new EnvironmentChecker('health', 'Site health'); |
|
| 32 | - $checker->setErrorCode(500); |
|
| 31 | + $checker = new EnvironmentChecker('health', 'Site health'); |
|
| 32 | + $checker->setErrorCode(500); |
|
| 33 | 33 | |
| 34 | - return $checker; |
|
| 35 | - } |
|
| 34 | + return $checker; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -12,38 +12,38 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class DevCheckController extends Controller |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - private static $allowed_actions = [ |
|
| 19 | - 'index' |
|
| 20 | - ]; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Permission code to check for access to this controller. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - private static $permission = 'ADMIN'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param HTTPRequest $request |
|
| 31 | - * |
|
| 32 | - * @return EnvironmentChecker |
|
| 33 | - * |
|
| 34 | - * @throws HTTPResponse_Exception |
|
| 35 | - */ |
|
| 36 | - public function index($request) |
|
| 37 | - { |
|
| 38 | - $suite = 'check'; |
|
| 39 | - |
|
| 40 | - if ($name = $request->param('Suite')) { |
|
| 41 | - $suite = $name; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $checker = new EnvironmentChecker($suite, 'Environment status'); |
|
| 45 | - $checker->init($this->config()->permission); |
|
| 46 | - |
|
| 47 | - return $checker; |
|
| 48 | - } |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + private static $allowed_actions = [ |
|
| 19 | + 'index' |
|
| 20 | + ]; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Permission code to check for access to this controller. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + private static $permission = 'ADMIN'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param HTTPRequest $request |
|
| 31 | + * |
|
| 32 | + * @return EnvironmentChecker |
|
| 33 | + * |
|
| 34 | + * @throws HTTPResponse_Exception |
|
| 35 | + */ |
|
| 36 | + public function index($request) |
|
| 37 | + { |
|
| 38 | + $suite = 'check'; |
|
| 39 | + |
|
| 40 | + if ($name = $request->param('Suite')) { |
|
| 41 | + $suite = $name; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $checker = new EnvironmentChecker($suite, 'Environment status'); |
|
| 45 | + $checker->init($this->config()->permission); |
|
| 46 | + |
|
| 47 | + return $checker; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -14,112 +14,112 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EnvironmentCheckSuiteResult extends ViewableData |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var ArrayList |
|
| 19 | - */ |
|
| 20 | - protected $details; |
|
| 17 | + /** |
|
| 18 | + * @var ArrayList |
|
| 19 | + */ |
|
| 20 | + protected $details; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var int |
|
| 24 | - */ |
|
| 25 | - protected $worst = 0; |
|
| 22 | + /** |
|
| 23 | + * @var int |
|
| 24 | + */ |
|
| 25 | + protected $worst = 0; |
|
| 26 | 26 | |
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - parent::__construct(); |
|
| 30 | - $this->details = new ArrayList(); |
|
| 31 | - } |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + parent::__construct(); |
|
| 30 | + $this->details = new ArrayList(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param int $status |
|
| 35 | - * @param string $message |
|
| 36 | - * @param string $checkIdentifier |
|
| 37 | - */ |
|
| 38 | - public function addResult($status, $message, $checkIdentifier) |
|
| 39 | - { |
|
| 40 | - $this->details->push(new ArrayData([ |
|
| 41 | - 'Check' => $checkIdentifier, |
|
| 42 | - 'Status' => $this->statusText($status), |
|
| 43 | - 'StatusCode' => $status, |
|
| 44 | - 'Message' => $message, |
|
| 45 | - ])); |
|
| 33 | + /** |
|
| 34 | + * @param int $status |
|
| 35 | + * @param string $message |
|
| 36 | + * @param string $checkIdentifier |
|
| 37 | + */ |
|
| 38 | + public function addResult($status, $message, $checkIdentifier) |
|
| 39 | + { |
|
| 40 | + $this->details->push(new ArrayData([ |
|
| 41 | + 'Check' => $checkIdentifier, |
|
| 42 | + 'Status' => $this->statusText($status), |
|
| 43 | + 'StatusCode' => $status, |
|
| 44 | + 'Message' => $message, |
|
| 45 | + ])); |
|
| 46 | 46 | |
| 47 | - $this->worst = max($this->worst, $status); |
|
| 48 | - } |
|
| 47 | + $this->worst = max($this->worst, $status); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Returns true if there are no errors. |
|
| 52 | - * |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - public function ShouldPass() |
|
| 56 | - { |
|
| 57 | - return $this->worst <= EnvironmentCheck::WARNING; |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Returns true if there are no errors. |
|
| 52 | + * |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + public function ShouldPass() |
|
| 56 | + { |
|
| 57 | + return $this->worst <= EnvironmentCheck::WARNING; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Returns overall (i.e. worst) status as a string. |
|
| 62 | - * |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function Status() |
|
| 66 | - { |
|
| 67 | - return $this->statusText($this->worst); |
|
| 68 | - } |
|
| 60 | + /** |
|
| 61 | + * Returns overall (i.e. worst) status as a string. |
|
| 62 | + * |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function Status() |
|
| 66 | + { |
|
| 67 | + return $this->statusText($this->worst); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Returns detailed status information about each check. |
|
| 72 | - * |
|
| 73 | - * @return ArrayList |
|
| 74 | - */ |
|
| 75 | - public function Details() |
|
| 76 | - { |
|
| 77 | - return $this->details; |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * Returns detailed status information about each check. |
|
| 72 | + * |
|
| 73 | + * @return ArrayList |
|
| 74 | + */ |
|
| 75 | + public function Details() |
|
| 76 | + { |
|
| 77 | + return $this->details; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Convert the final result status and details to JSON. |
|
| 82 | - * |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function toJSON() |
|
| 86 | - { |
|
| 87 | - $result = [ |
|
| 88 | - 'Status' => $this->Status(), |
|
| 89 | - 'ShouldPass' => $this->ShouldPass(), |
|
| 90 | - 'Checks' => [] |
|
| 91 | - ]; |
|
| 92 | - foreach ($this->details as $detail) { |
|
| 93 | - $result['Checks'][] = $detail->toMap(); |
|
| 94 | - } |
|
| 95 | - return json_encode($result); |
|
| 96 | - } |
|
| 80 | + /** |
|
| 81 | + * Convert the final result status and details to JSON. |
|
| 82 | + * |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function toJSON() |
|
| 86 | + { |
|
| 87 | + $result = [ |
|
| 88 | + 'Status' => $this->Status(), |
|
| 89 | + 'ShouldPass' => $this->ShouldPass(), |
|
| 90 | + 'Checks' => [] |
|
| 91 | + ]; |
|
| 92 | + foreach ($this->details as $detail) { |
|
| 93 | + $result['Checks'][] = $detail->toMap(); |
|
| 94 | + } |
|
| 95 | + return json_encode($result); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Return a text version of a status code. |
|
| 100 | - * |
|
| 101 | - * @param int $status |
|
| 102 | - * @return string |
|
| 103 | - * @throws InvalidArgumentException |
|
| 104 | - */ |
|
| 105 | - protected function statusText($status) |
|
| 106 | - { |
|
| 107 | - switch ($status) { |
|
| 108 | - case EnvironmentCheck::ERROR: |
|
| 109 | - return 'ERROR'; |
|
| 110 | - break; |
|
| 111 | - case EnvironmentCheck::WARNING: |
|
| 112 | - return 'WARNING'; |
|
| 113 | - break; |
|
| 114 | - case EnvironmentCheck::OK: |
|
| 115 | - return 'OK'; |
|
| 116 | - break; |
|
| 117 | - case 0: |
|
| 118 | - return 'NO CHECKS'; |
|
| 119 | - break; |
|
| 120 | - default: |
|
| 121 | - throw new InvalidArgumentException("Bad environment check status '$status'"); |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - } |
|
| 98 | + /** |
|
| 99 | + * Return a text version of a status code. |
|
| 100 | + * |
|
| 101 | + * @param int $status |
|
| 102 | + * @return string |
|
| 103 | + * @throws InvalidArgumentException |
|
| 104 | + */ |
|
| 105 | + protected function statusText($status) |
|
| 106 | + { |
|
| 107 | + switch ($status) { |
|
| 108 | + case EnvironmentCheck::ERROR: |
|
| 109 | + return 'ERROR'; |
|
| 110 | + break; |
|
| 111 | + case EnvironmentCheck::WARNING: |
|
| 112 | + return 'WARNING'; |
|
| 113 | + break; |
|
| 114 | + case EnvironmentCheck::OK: |
|
| 115 | + return 'OK'; |
|
| 116 | + break; |
|
| 117 | + case 0: |
|
| 118 | + return 'NO CHECKS'; |
|
| 119 | + break; |
|
| 120 | + default: |
|
| 121 | + throw new InvalidArgumentException("Bad environment check status '$status'"); |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -16,25 +16,25 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | interface EnvironmentCheck |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var int |
|
| 21 | - */ |
|
| 22 | - const ERROR = 3; |
|
| 19 | + /** |
|
| 20 | + * @var int |
|
| 21 | + */ |
|
| 22 | + const ERROR = 3; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 27 | - const WARNING = 2; |
|
| 24 | + /** |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | + const WARNING = 2; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 32 | - const OK = 1; |
|
| 29 | + /** |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | + const OK = 1; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return array Result with 'status' and 'message' keys. |
|
| 36 | - * |
|
| 37 | - * Status is EnvironmentCheck::ERROR, EnvironmentCheck::WARNING, or EnvironmentCheck::OK. |
|
| 38 | - */ |
|
| 39 | - public function check(); |
|
| 34 | + /** |
|
| 35 | + * @return array Result with 'status' and 'message' keys. |
|
| 36 | + * |
|
| 37 | + * Status is EnvironmentCheck::ERROR, EnvironmentCheck::WARNING, or EnvironmentCheck::OK. |
|
| 38 | + */ |
|
| 39 | + public function check(); |
|
| 40 | 40 | } |
@@ -13,67 +13,67 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SMTPConnectCheck implements EnvironmentCheck |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $host; |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $host; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var int |
|
| 23 | - */ |
|
| 24 | - protected $port; |
|
| 21 | + /** |
|
| 22 | + * @var int |
|
| 23 | + */ |
|
| 24 | + protected $port; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Timeout (in seconds). |
|
| 28 | - * |
|
| 29 | - * @var int |
|
| 30 | - */ |
|
| 31 | - protected $timeout; |
|
| 26 | + /** |
|
| 27 | + * Timeout (in seconds). |
|
| 28 | + * |
|
| 29 | + * @var int |
|
| 30 | + */ |
|
| 31 | + protected $timeout; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param null|string $host |
|
| 35 | - * @param null|int $port |
|
| 36 | - * @param int $timeout |
|
| 37 | - */ |
|
| 38 | - public function __construct($host = null, $port = null, $timeout = 15) |
|
| 39 | - { |
|
| 40 | - $this->host = ($host) ? $host : ini_get('SMTP'); |
|
| 41 | - if (!$this->host) { |
|
| 42 | - $this->host = 'localhost'; |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * @param null|string $host |
|
| 35 | + * @param null|int $port |
|
| 36 | + * @param int $timeout |
|
| 37 | + */ |
|
| 38 | + public function __construct($host = null, $port = null, $timeout = 15) |
|
| 39 | + { |
|
| 40 | + $this->host = ($host) ? $host : ini_get('SMTP'); |
|
| 41 | + if (!$this->host) { |
|
| 42 | + $this->host = 'localhost'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $this->port = ($port) ? $port : ini_get('smtp_port'); |
|
| 46 | - if (!$this->port) { |
|
| 47 | - $this->port = 25; |
|
| 48 | - } |
|
| 45 | + $this->port = ($port) ? $port : ini_get('smtp_port'); |
|
| 46 | + if (!$this->port) { |
|
| 47 | + $this->port = 25; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $this->timeout = $timeout; |
|
| 51 | - } |
|
| 50 | + $this->timeout = $timeout; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - public function check() |
|
| 59 | - { |
|
| 60 | - $f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 61 | - if (!$f) { |
|
| 62 | - return [ |
|
| 63 | - EnvironmentCheck::ERROR, |
|
| 64 | - sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr) |
|
| 65 | - ]; |
|
| 66 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + public function check() |
|
| 59 | + { |
|
| 60 | + $f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 61 | + if (!$f) { |
|
| 62 | + return [ |
|
| 63 | + EnvironmentCheck::ERROR, |
|
| 64 | + sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr) |
|
| 65 | + ]; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - fwrite($f, "HELO its_me\r\n"); |
|
| 69 | - $response = fread($f, 26); |
|
| 70 | - if (substr($response, 0, 3) != '220') { |
|
| 71 | - return [ |
|
| 72 | - EnvironmentCheck::ERROR, |
|
| 73 | - sprintf('Invalid mail server response: %s', $response) |
|
| 74 | - ]; |
|
| 75 | - } |
|
| 68 | + fwrite($f, "HELO its_me\r\n"); |
|
| 69 | + $response = fread($f, 26); |
|
| 70 | + if (substr($response, 0, 3) != '220') { |
|
| 71 | + return [ |
|
| 72 | + EnvironmentCheck::ERROR, |
|
| 73 | + sprintf('Invalid mail server response: %s', $response) |
|
| 74 | + ]; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return [EnvironmentCheck::OK, '']; |
|
| 78 | - } |
|
| 77 | + return [EnvironmentCheck::OK, '']; |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -13,38 +13,38 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class DatabaseCheck implements EnvironmentCheck |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $checkTable; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * By default, Member will be checked. |
|
| 23 | - * |
|
| 24 | - * @param string $checkTable |
|
| 25 | - */ |
|
| 26 | - public function __construct($checkTable = 'Member') |
|
| 27 | - { |
|
| 28 | - $this->checkTable = $checkTable; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * {@inheritDoc} |
|
| 33 | - * |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - public function check() |
|
| 37 | - { |
|
| 38 | - if (!DB::get_schema()->hasTable($this->checkTable)) { |
|
| 39 | - return [EnvironmentCheck::ERROR, "$this->checkTable not present in the database"]; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value(); |
|
| 43 | - |
|
| 44 | - if ($count > 0) { |
|
| 45 | - return [EnvironmentCheck::OK, '']; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return [EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records"]; |
|
| 49 | - } |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $checkTable; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * By default, Member will be checked. |
|
| 23 | + * |
|
| 24 | + * @param string $checkTable |
|
| 25 | + */ |
|
| 26 | + public function __construct($checkTable = 'Member') |
|
| 27 | + { |
|
| 28 | + $this->checkTable = $checkTable; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * {@inheritDoc} |
|
| 33 | + * |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + public function check() |
|
| 37 | + { |
|
| 38 | + if (!DB::get_schema()->hasTable($this->checkTable)) { |
|
| 39 | + return [EnvironmentCheck::ERROR, "$this->checkTable not present in the database"]; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value(); |
|
| 43 | + |
|
| 44 | + if ($count > 0) { |
|
| 45 | + return [EnvironmentCheck::OK, '']; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return [EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records"]; |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -11,29 +11,29 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class HasFunctionCheck implements EnvironmentCheck |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $functionName; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $functionName; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $functionName The name of the function to look for. |
|
| 21 | - */ |
|
| 22 | - public function __construct($functionName) |
|
| 23 | - { |
|
| 24 | - $this->functionName = $functionName; |
|
| 25 | - } |
|
| 19 | + /** |
|
| 20 | + * @param string $functionName The name of the function to look for. |
|
| 21 | + */ |
|
| 22 | + public function __construct($functionName) |
|
| 23 | + { |
|
| 24 | + $this->functionName = $functionName; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * {@inheritDoc} |
|
| 29 | - * |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function check() |
|
| 33 | - { |
|
| 34 | - if (function_exists($this->functionName)) { |
|
| 35 | - return [EnvironmentCheck::OK, $this->functionName . '() exists']; |
|
| 36 | - } |
|
| 37 | - return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist']; |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * {@inheritDoc} |
|
| 29 | + * |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function check() |
|
| 33 | + { |
|
| 34 | + if (function_exists($this->functionName)) { |
|
| 35 | + return [EnvironmentCheck::OK, $this->functionName . '() exists']; |
|
| 36 | + } |
|
| 37 | + return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist']; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -28,170 +28,170 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class FileAccessibilityAndValidationCheck implements EnvironmentCheck |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - const CHECK_SINGLE = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var int |
|
| 38 | - */ |
|
| 39 | - const CHECK_ALL = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Absolute path to a file or folder, compatible with glob(). |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $path; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Constant, check for a single file to match age criteria, or all of them. |
|
| 50 | - * |
|
| 51 | - * @var int |
|
| 52 | - */ |
|
| 53 | - protected $fileTypeValidateFunc; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Constant, check for a single file to match age criteria, or all of them. |
|
| 57 | - * |
|
| 58 | - * @var int |
|
| 59 | - */ |
|
| 60 | - protected $checkType; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string $path |
|
| 64 | - * @param string $fileTypeValidateFunc |
|
| 65 | - * @param null|int $checkType |
|
| 66 | - */ |
|
| 67 | - public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null) |
|
| 68 | - { |
|
| 69 | - $this->path = $path; |
|
| 70 | - $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc : 'noVidation'; |
|
| 71 | - $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * {@inheritDoc} |
|
| 76 | - * |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function check() |
|
| 80 | - { |
|
| 81 | - $origStage = Versioned::get_reading_mode(); |
|
| 82 | - Versioned::set_reading_mode(Versioned::LIVE); |
|
| 83 | - |
|
| 84 | - $files = $this->getFiles(); |
|
| 85 | - if ($files) { |
|
| 86 | - $fileTypeValidateFunc = $this->fileTypeValidateFunc; |
|
| 87 | - if (method_exists($this, $fileTypeValidateFunc)) { |
|
| 88 | - $invalidFiles = []; |
|
| 89 | - $validFiles = []; |
|
| 90 | - |
|
| 91 | - foreach ($files as $file) { |
|
| 92 | - if ($this->$fileTypeValidateFunc($file)) { |
|
| 93 | - $validFiles[] = $file; |
|
| 94 | - } else { |
|
| 95 | - $invalidFiles[] = $file; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // If at least one file was valid, count as passed |
|
| 100 | - if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) { |
|
| 101 | - $validFileList = PHP_EOL; |
|
| 102 | - foreach ($validFiles as $vf) { |
|
| 103 | - $validFileList .= $vf . PHP_EOL; |
|
| 104 | - } |
|
| 105 | - if ($fileTypeValidateFunc == 'noVidation') { |
|
| 106 | - $checkReturn = [ |
|
| 107 | - EnvironmentCheck::OK, |
|
| 108 | - sprintf('At least these file(s) accessible: %s', $validFileList) |
|
| 109 | - ]; |
|
| 110 | - } else { |
|
| 111 | - $checkReturn = [ |
|
| 112 | - EnvironmentCheck::OK, |
|
| 113 | - sprintf( |
|
| 114 | - 'At least these file(s) passed file type validate function "%s": %s', |
|
| 115 | - $fileTypeValidateFunc, |
|
| 116 | - $validFileList |
|
| 117 | - ) |
|
| 118 | - ]; |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - if (count($invalidFiles) == 0) { |
|
| 122 | - $checkReturn = [EnvironmentCheck::OK, 'All files valideted']; |
|
| 123 | - } else { |
|
| 124 | - $invalidFileList = PHP_EOL; |
|
| 125 | - foreach ($invalidFiles as $vf) { |
|
| 126 | - $invalidFileList .= $vf . PHP_EOL; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($fileTypeValidateFunc == 'noVidation') { |
|
| 130 | - $checkReturn = [ |
|
| 131 | - EnvironmentCheck::ERROR, |
|
| 132 | - sprintf('File(s) not accessible: %s', $invalidFileList) |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - $checkReturn = [ |
|
| 136 | - EnvironmentCheck::ERROR, |
|
| 137 | - sprintf( |
|
| 138 | - 'File(s) not passing the file type validate function "%s": %s', |
|
| 139 | - $fileTypeValidateFunc, |
|
| 140 | - $invalidFileList |
|
| 141 | - ) |
|
| 142 | - ]; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } else { |
|
| 147 | - $checkReturn = array( |
|
| 148 | - EnvironmentCheck::ERROR, |
|
| 149 | - sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - } else { |
|
| 153 | - $checkReturn = array( |
|
| 154 | - EnvironmentCheck::ERROR, |
|
| 155 | - sprintf("No files accessible at path %s", $this->path) |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - Versioned::set_reading_mode($origStage); |
|
| 160 | - |
|
| 161 | - return $checkReturn; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param string $file |
|
| 166 | - * |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - private function jsonValidate($file) |
|
| 170 | - { |
|
| 171 | - $json = json_decode(file_get_contents($file)); |
|
| 172 | - if (!$json) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - return true; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param string $file |
|
| 180 | - * |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - protected function noVidation($file) |
|
| 184 | - { |
|
| 185 | - return true; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Gets a list of absolute file paths. |
|
| 190 | - * |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 193 | - protected function getFiles() |
|
| 194 | - { |
|
| 195 | - return glob($this->path); |
|
| 196 | - } |
|
| 31 | + /** |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + const CHECK_SINGLE = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var int |
|
| 38 | + */ |
|
| 39 | + const CHECK_ALL = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Absolute path to a file or folder, compatible with glob(). |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $path; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Constant, check for a single file to match age criteria, or all of them. |
|
| 50 | + * |
|
| 51 | + * @var int |
|
| 52 | + */ |
|
| 53 | + protected $fileTypeValidateFunc; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Constant, check for a single file to match age criteria, or all of them. |
|
| 57 | + * |
|
| 58 | + * @var int |
|
| 59 | + */ |
|
| 60 | + protected $checkType; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string $path |
|
| 64 | + * @param string $fileTypeValidateFunc |
|
| 65 | + * @param null|int $checkType |
|
| 66 | + */ |
|
| 67 | + public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null) |
|
| 68 | + { |
|
| 69 | + $this->path = $path; |
|
| 70 | + $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc : 'noVidation'; |
|
| 71 | + $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * {@inheritDoc} |
|
| 76 | + * |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function check() |
|
| 80 | + { |
|
| 81 | + $origStage = Versioned::get_reading_mode(); |
|
| 82 | + Versioned::set_reading_mode(Versioned::LIVE); |
|
| 83 | + |
|
| 84 | + $files = $this->getFiles(); |
|
| 85 | + if ($files) { |
|
| 86 | + $fileTypeValidateFunc = $this->fileTypeValidateFunc; |
|
| 87 | + if (method_exists($this, $fileTypeValidateFunc)) { |
|
| 88 | + $invalidFiles = []; |
|
| 89 | + $validFiles = []; |
|
| 90 | + |
|
| 91 | + foreach ($files as $file) { |
|
| 92 | + if ($this->$fileTypeValidateFunc($file)) { |
|
| 93 | + $validFiles[] = $file; |
|
| 94 | + } else { |
|
| 95 | + $invalidFiles[] = $file; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // If at least one file was valid, count as passed |
|
| 100 | + if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) { |
|
| 101 | + $validFileList = PHP_EOL; |
|
| 102 | + foreach ($validFiles as $vf) { |
|
| 103 | + $validFileList .= $vf . PHP_EOL; |
|
| 104 | + } |
|
| 105 | + if ($fileTypeValidateFunc == 'noVidation') { |
|
| 106 | + $checkReturn = [ |
|
| 107 | + EnvironmentCheck::OK, |
|
| 108 | + sprintf('At least these file(s) accessible: %s', $validFileList) |
|
| 109 | + ]; |
|
| 110 | + } else { |
|
| 111 | + $checkReturn = [ |
|
| 112 | + EnvironmentCheck::OK, |
|
| 113 | + sprintf( |
|
| 114 | + 'At least these file(s) passed file type validate function "%s": %s', |
|
| 115 | + $fileTypeValidateFunc, |
|
| 116 | + $validFileList |
|
| 117 | + ) |
|
| 118 | + ]; |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + if (count($invalidFiles) == 0) { |
|
| 122 | + $checkReturn = [EnvironmentCheck::OK, 'All files valideted']; |
|
| 123 | + } else { |
|
| 124 | + $invalidFileList = PHP_EOL; |
|
| 125 | + foreach ($invalidFiles as $vf) { |
|
| 126 | + $invalidFileList .= $vf . PHP_EOL; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($fileTypeValidateFunc == 'noVidation') { |
|
| 130 | + $checkReturn = [ |
|
| 131 | + EnvironmentCheck::ERROR, |
|
| 132 | + sprintf('File(s) not accessible: %s', $invalidFileList) |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + $checkReturn = [ |
|
| 136 | + EnvironmentCheck::ERROR, |
|
| 137 | + sprintf( |
|
| 138 | + 'File(s) not passing the file type validate function "%s": %s', |
|
| 139 | + $fileTypeValidateFunc, |
|
| 140 | + $invalidFileList |
|
| 141 | + ) |
|
| 142 | + ]; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } else { |
|
| 147 | + $checkReturn = array( |
|
| 148 | + EnvironmentCheck::ERROR, |
|
| 149 | + sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + } else { |
|
| 153 | + $checkReturn = array( |
|
| 154 | + EnvironmentCheck::ERROR, |
|
| 155 | + sprintf("No files accessible at path %s", $this->path) |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + Versioned::set_reading_mode($origStage); |
|
| 160 | + |
|
| 161 | + return $checkReturn; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param string $file |
|
| 166 | + * |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + private function jsonValidate($file) |
|
| 170 | + { |
|
| 171 | + $json = json_decode(file_get_contents($file)); |
|
| 172 | + if (!$json) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + return true; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param string $file |
|
| 180 | + * |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + protected function noVidation($file) |
|
| 184 | + { |
|
| 185 | + return true; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Gets a list of absolute file paths. |
|
| 190 | + * |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | + protected function getFiles() |
|
| 194 | + { |
|
| 195 | + return glob($this->path); |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -14,50 +14,50 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class URLCheck implements EnvironmentCheck |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $url; |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $url; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $testString; |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $testString; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param string $url The URL to check, relative to the site (homepage is ''). |
|
| 29 | - * @param string $testString An optional piece of text to search for on the homepage. |
|
| 30 | - */ |
|
| 31 | - public function __construct($url = '', $testString = '') |
|
| 32 | - { |
|
| 33 | - $this->url = $url; |
|
| 34 | - $this->testString = $testString; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * @param string $url The URL to check, relative to the site (homepage is ''). |
|
| 29 | + * @param string $testString An optional piece of text to search for on the homepage. |
|
| 30 | + */ |
|
| 31 | + public function __construct($url = '', $testString = '') |
|
| 32 | + { |
|
| 33 | + $this->url = $url; |
|
| 34 | + $this->testString = $testString; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * {@inheritDoc} |
|
| 39 | - * |
|
| 40 | - * @return array |
|
| 41 | - * @throws HTTPResponse_Exception |
|
| 42 | - */ |
|
| 43 | - public function check() |
|
| 44 | - { |
|
| 45 | - $response = Director::test($this->url); |
|
| 37 | + /** |
|
| 38 | + * {@inheritDoc} |
|
| 39 | + * |
|
| 40 | + * @return array |
|
| 41 | + * @throws HTTPResponse_Exception |
|
| 42 | + */ |
|
| 43 | + public function check() |
|
| 44 | + { |
|
| 45 | + $response = Director::test($this->url); |
|
| 46 | 46 | |
| 47 | - if ($response->getStatusCode() != 200) { |
|
| 48 | - return [ |
|
| 49 | - EnvironmentCheck::ERROR, |
|
| 50 | - sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode()) |
|
| 51 | - ]; |
|
| 52 | - } elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) { |
|
| 53 | - return [ |
|
| 54 | - EnvironmentCheck::WARNING, |
|
| 55 | - sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString) |
|
| 56 | - ]; |
|
| 57 | - } |
|
| 58 | - return [ |
|
| 59 | - EnvironmentCheck::OK, |
|
| 60 | - sprintf('Success retrieving "%s"', $this->url) |
|
| 61 | - ]; |
|
| 62 | - } |
|
| 47 | + if ($response->getStatusCode() != 200) { |
|
| 48 | + return [ |
|
| 49 | + EnvironmentCheck::ERROR, |
|
| 50 | + sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode()) |
|
| 51 | + ]; |
|
| 52 | + } elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) { |
|
| 53 | + return [ |
|
| 54 | + EnvironmentCheck::WARNING, |
|
| 55 | + sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString) |
|
| 56 | + ]; |
|
| 57 | + } |
|
| 58 | + return [ |
|
| 59 | + EnvironmentCheck::OK, |
|
| 60 | + sprintf('Success retrieving "%s"', $this->url) |
|
| 61 | + ]; |
|
| 62 | + } |
|
| 63 | 63 | } |