Skip to content

Commit

Permalink
Add BinaryExistsCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Aug 24, 2015
1 parent db4d4cd commit 6285033
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
19 changes: 10 additions & 9 deletions README.md
Expand Up @@ -72,19 +72,20 @@ EnvironmentCheckSuite:

## Available checks

* `DatabaseCheck`: Check that the connection to the database is working, by ensuring that the table exists and that the table contain some records.
* `DatabaseCheck`: Check that the connection to the database is working, by ensuring that the table exists and that
the table contain some records.
* `URLCheck`: Check that a given URL is functioning, by default, the homepage.
* `HasFunctionCheck`: Check that the given function exists.
This can be used to check that PHP modules or features are installed.
* `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.
* `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.
* `HasFunctionCheck`: Check that the given function exists. This can be used to check that PHP modules or features
are installed.
* `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 writable.
* `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.
* `ExternalURLCheck`: Checks that one or more URLs are reachable via HTTP.
* `SMTPConnectCheck`: Checks if the SMTP connection configured through PHP.ini works as expected.
* `SolrIndexCheck`: Checks if the Solr cores of given class are available.
* `BinaryExistsCheck`: Checks if a binary is available on the server

## Authentication

Expand Down
4 changes: 3 additions & 1 deletion code/DevCheckController.php
Expand Up @@ -18,7 +18,9 @@ class DevCheckController extends Controller {
function index($request) {
$suiteName = $request->param('Suite') ? $request->param('Suite') : 'check';
$e = new EnvironmentChecker($suiteName, 'Environment status');
$e->init($this->config()->permission); //check for admin permissions before running this check

$e->init($this->config()->permission); // check for admin permissions before running this check

return $e;
}
}
43 changes: 43 additions & 0 deletions code/checks/BinaryExistsCheck.php
@@ -0,0 +1,43 @@
<?php

/**
* @package environmentcheck
*/

class BinaryExistsCheck implements EnvironmentCheck {

protected $binary;

function __construct($binary = "Member") {
$this->binary = $binary;
}

function check() {
$command = (PHP_OS == 'WINNT') ? 'where' : 'which';
$binary = $this->binary;

$process = proc_open(
"$command $binary",
array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
),
$pipes
);

if ($process !== false) {
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);

if($stdout != '') {
return array(EnvironmentCheck::OK, '');
}
}

return array(EnvironmentCheck::ERROR, 'Could not execute '. $this->binary . ' in ');
}
}
7 changes: 2 additions & 5 deletions code/checks/DatabaseCheck.php
@@ -1,17 +1,14 @@
<?php
/**
* This file contains a number of default environment checks that you can use.
*/


/**
* Check that the connection to the database is working, by ensuring that the table exists and that
* the table contain some records.
* By default, Member will be checked.
*
* @param $checkTable The table that will be checked.
* @package environmentcheck
*/
class DatabaseCheck implements EnvironmentCheck {

protected $checkTable;

function __construct($checkTable = "Member") {
Expand Down

0 comments on commit 6285033

Please sign in to comment.