Completed
Push — master ( e090e4...18d79e )
by Damian
02:26
created

code/checks/DatabaseCheck.php (1 issue)

class opening brace is on a new line.

Coding Style Informational

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Check that the connection to the database is working, by ensuring that the table exists and that
5
 * the table contains some records.
6
 */
7
class DatabaseCheck implements EnvironmentCheck {
0 ignored issues
show
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
8
	protected $checkTable;
9
10
	/**
11
	 * By default, Member will be checked.
12
	 *
13
	 * @param string $checkTable
14
	 */
15
	function __construct($checkTable = "Member") {
16
		$this->checkTable = $checkTable;
17
	}
18
19
	/**
20
	 * @inheritdoc
21
	 *
22
	 * @return array
23
	 */
24
	function check() {
25
		if(!DB::getConn()->hasTable($this->checkTable)) {
26
			return array(EnvironmentCheck::ERROR, "$this->checkTable not present in the database");
27
		}
28
29
		$count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value();
30
		
31
		if($count > 0) {
32
			return array(EnvironmentCheck::OK, "");
33
		} else {
34
			return array(EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records");
35
		}
36
	}
37
}
38