more checkstyle fixes
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -43,29 +43,29 @@ class Database
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_link = null;
|
||||
private static $link = null;
|
||||
|
||||
/**
|
||||
* indicator whether to use root-connection or not
|
||||
*/
|
||||
private static $_needroot = false;
|
||||
private static $needroot = false;
|
||||
|
||||
/**
|
||||
* indicator which database-server we're on (not really used)
|
||||
*/
|
||||
private static $_dbserver = 0;
|
||||
private static $dbserver = 0;
|
||||
|
||||
/**
|
||||
* used database-name
|
||||
*/
|
||||
private static $_dbname = null;
|
||||
private static $dbname = null;
|
||||
|
||||
/**
|
||||
* sql-access data
|
||||
*/
|
||||
private static $_needsqldata = false;
|
||||
private static $needsqldata = false;
|
||||
|
||||
private static $_sqldata = null;
|
||||
private static $sqldata = null;
|
||||
|
||||
/**
|
||||
* Wrapper for PDOStatement::execute so we can catch the PDOException
|
||||
@@ -82,7 +82,7 @@ class Database
|
||||
try {
|
||||
$stmt->execute($params);
|
||||
} catch (\PDOException $e) {
|
||||
self::_showerror($e, $showerror, $json_response, $stmt);
|
||||
self::showerror($e, $showerror, $json_response, $stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class Database
|
||||
*/
|
||||
public static function getDbName()
|
||||
{
|
||||
return self::$_dbname;
|
||||
return self::$dbname;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,8 +139,8 @@ class Database
|
||||
{
|
||||
// force re-connecting to the db with corresponding user
|
||||
// and set the $dbserver (mostly to 0 = default)
|
||||
self::_setServer($dbserver);
|
||||
self::$_needroot = $needroot;
|
||||
self::setServer($dbserver);
|
||||
self::$needroot = $needroot;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,9 +153,9 @@ class Database
|
||||
*/
|
||||
public static function needSqlData()
|
||||
{
|
||||
self::$_needsqldata = true;
|
||||
self::$_sqldata = array();
|
||||
self::$_link = null;
|
||||
self::$needsqldata = true;
|
||||
self::$sqldata = array();
|
||||
self::$link = null;
|
||||
// we need a connection here because
|
||||
// if getSqlData() is called RIGHT after
|
||||
// this function and no "real" PDO
|
||||
@@ -174,11 +174,11 @@ class Database
|
||||
public static function getSqlData()
|
||||
{
|
||||
$return = false;
|
||||
if (self::$_sqldata !== null && is_array(self::$_sqldata) && isset(self::$_sqldata['user'])) {
|
||||
$return = self::$_sqldata;
|
||||
if (self::$sqldata !== null && is_array(self::$sqldata) && isset(self::$sqldata['user'])) {
|
||||
$return = self::$sqldata;
|
||||
// automatically disable sql-data
|
||||
self::$_sqldata = null;
|
||||
self::$_needsqldata = false;
|
||||
self::$sqldata = null;
|
||||
self::$needsqldata = false;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ class Database
|
||||
try {
|
||||
$result = call_user_func_array($callback, $args);
|
||||
} catch (\PDOException $e) {
|
||||
self::_showerror($e);
|
||||
self::showerror($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -212,10 +212,10 @@ class Database
|
||||
*
|
||||
* @param int $dbserver
|
||||
*/
|
||||
private static function _setServer($dbserver = 0)
|
||||
private static function setServer($dbserver = 0)
|
||||
{
|
||||
self::$_dbserver = $dbserver;
|
||||
self::$_link = null;
|
||||
self::$dbserver = $dbserver;
|
||||
self::$link = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,20 +229,20 @@ class Database
|
||||
private static function getDB()
|
||||
{
|
||||
if (! extension_loaded('pdo') || in_array("mysql", \PDO::getAvailableDrivers()) == false) {
|
||||
self::_showerror(new \Exception("The php PDO extension or PDO-MySQL driver is not available"));
|
||||
self::showerror(new \Exception("The php PDO extension or PDO-MySQL driver is not available"));
|
||||
}
|
||||
|
||||
// do we got a connection already?
|
||||
if (self::$_link) {
|
||||
if (self::$link) {
|
||||
// return it
|
||||
return self::$_link;
|
||||
return self::$link;
|
||||
}
|
||||
|
||||
// include userdata.inc.php
|
||||
require \Froxlor\Froxlor::getInstallDir() . "/lib/userdata.inc.php";
|
||||
|
||||
// le format
|
||||
if (self::$_needroot == true && isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) {
|
||||
if (self::$needroot == true && isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) {
|
||||
$sql_root = array(
|
||||
0 => array(
|
||||
'caption' => 'Default',
|
||||
@@ -257,13 +257,13 @@ class Database
|
||||
}
|
||||
|
||||
// either root or unprivileged user
|
||||
if (self::$_needroot) {
|
||||
$caption = $sql_root[self::$_dbserver]['caption'];
|
||||
$user = $sql_root[self::$_dbserver]['user'];
|
||||
$password = $sql_root[self::$_dbserver]['password'];
|
||||
$host = $sql_root[self::$_dbserver]['host'];
|
||||
$socket = isset($sql_root[self::$_dbserver]['socket']) ? $sql_root[self::$_dbserver]['socket'] : null;
|
||||
$port = isset($sql_root[self::$_dbserver]['port']) ? $sql_root[self::$_dbserver]['port'] : '3306';
|
||||
if (self::$needroot) {
|
||||
$caption = $sql_root[self::$dbserver]['caption'];
|
||||
$user = $sql_root[self::$dbserver]['user'];
|
||||
$password = $sql_root[self::$dbserver]['password'];
|
||||
$host = $sql_root[self::$dbserver]['host'];
|
||||
$socket = isset($sql_root[self::$dbserver]['socket']) ? $sql_root[self::$dbserver]['socket'] : null;
|
||||
$port = isset($sql_root[self::$dbserver]['port']) ? $sql_root[self::$dbserver]['port'] : '3306';
|
||||
} else {
|
||||
$caption = 'localhost';
|
||||
$user = $sql["user"];
|
||||
@@ -274,8 +274,8 @@ class Database
|
||||
}
|
||||
|
||||
// save sql-access-data if needed
|
||||
if (self::$_needsqldata) {
|
||||
self::$_sqldata = array(
|
||||
if (self::$needsqldata) {
|
||||
self::$sqldata = array(
|
||||
'user' => $user,
|
||||
'passwd' => $password,
|
||||
'host' => $host,
|
||||
@@ -308,7 +308,7 @@ class Database
|
||||
$dbconf["dsn"]['port'] = $port;
|
||||
}
|
||||
|
||||
self::$_dbname = $sql["db"];
|
||||
self::$dbname = $sql["db"];
|
||||
|
||||
// add options to dsn-string
|
||||
foreach ($dbconf["dsn"] as $k => $v) {
|
||||
@@ -320,25 +320,25 @@ class Database
|
||||
|
||||
// try to connect
|
||||
try {
|
||||
self::$_link = new \PDO($dsn, $user, $password, $options);
|
||||
self::$link = new \PDO($dsn, $user, $password, $options);
|
||||
} catch (\PDOException $e) {
|
||||
self::_showerror($e);
|
||||
self::showerror($e);
|
||||
}
|
||||
|
||||
// set attributes
|
||||
foreach ($attributes as $k => $v) {
|
||||
self::$_link->setAttribute(constant("PDO::" . $k), constant("PDO::" . $v));
|
||||
self::$link->setAttribute(constant("PDO::" . $k), constant("PDO::" . $v));
|
||||
}
|
||||
|
||||
$version_server = self::$_link->getAttribute(\PDO::ATTR_SERVER_VERSION);
|
||||
$version_server = self::$link->getAttribute(\PDO::ATTR_SERVER_VERSION);
|
||||
$sql_mode = 'NO_ENGINE_SUBSTITUTION';
|
||||
if (version_compare($version_server, '8.0.11', '<')) {
|
||||
$sql_mode .= ',NO_AUTO_CREATE_USER';
|
||||
}
|
||||
self::$_link->exec('SET sql_mode = "' . $sql_mode . '"');
|
||||
self::$link->exec('SET sql_mode = "' . $sql_mode . '"');
|
||||
|
||||
// return PDO instance
|
||||
return self::$_link;
|
||||
return self::$link;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,7 +348,7 @@ class Database
|
||||
* @param bool $showerror
|
||||
* if set to false, the error will be logged but we go on
|
||||
*/
|
||||
private static function _showerror($error, $showerror = true, $json_response = false, \PDOStatement $stmt = null)
|
||||
private static function showerror($error, $showerror = true, $json_response = false, \PDOStatement $stmt = null)
|
||||
{
|
||||
global $userinfo, $theme, $linker;
|
||||
|
||||
@@ -377,9 +377,9 @@ class Database
|
||||
$error_message = $error->getMessage();
|
||||
$error_trace = $error->getTraceAsString();
|
||||
// error-message
|
||||
$error_message = self::_substitute($error_message, $substitutions);
|
||||
$error_message = self::substitute($error_message, $substitutions);
|
||||
// error-trace
|
||||
$error_trace = self::_substitute($error_trace, $substitutions);
|
||||
$error_trace = self::substitute($error_trace, $substitutions);
|
||||
|
||||
if ($error->getCode() == 2003) {
|
||||
$error_message = "Unable to connect to database. Either the mysql-server is not running or your user/password is wrong.";
|
||||
@@ -471,12 +471,12 @@ class Database
|
||||
* @param int $minLength
|
||||
* @return string
|
||||
*/
|
||||
private static function _substitute($content, array $substitutions, $minLength = 6)
|
||||
private static function substitute($content, array $substitutions, $minLength = 6)
|
||||
{
|
||||
$replacements = array();
|
||||
|
||||
foreach ($substitutions as $search => $replace) {
|
||||
$replacements = $replacements + self::_createShiftedSubstitutions($search, $replace, $minLength);
|
||||
$replacements = $replacements + self::createShiftedSubstitutions($search, $replace, $minLength);
|
||||
}
|
||||
|
||||
$content = str_replace(array_keys($replacements), array_values($replacements), $content);
|
||||
@@ -501,7 +501,7 @@ class Database
|
||||
* @param int $minLength
|
||||
* @return array
|
||||
*/
|
||||
private static function _createShiftedSubstitutions($search, $replace, $minLength)
|
||||
private static function createShiftedSubstitutions($search, $replace, $minLength)
|
||||
{
|
||||
$substitutions = array();
|
||||
$length = strlen($search);
|
||||
|
||||
@@ -41,14 +41,14 @@ class DbManager
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $_log = null;
|
||||
private $log = null;
|
||||
|
||||
/**
|
||||
* Manager object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $_manager = null;
|
||||
private $manager = null;
|
||||
|
||||
/**
|
||||
* main constructor
|
||||
@@ -57,8 +57,8 @@ class DbManager
|
||||
*/
|
||||
public function __construct($log = null)
|
||||
{
|
||||
$this->_log = $log;
|
||||
$this->_setManager();
|
||||
$this->log = $log;
|
||||
$this->setManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,12 +98,12 @@ class DbManager
|
||||
|
||||
// now create the database itself
|
||||
$this->getManager()->createDatabase($username);
|
||||
$this->_log->logAction(USR_ACTION, LOG_INFO, "created database '" . $username . "'");
|
||||
$this->log->logAction(USR_ACTION, LOG_INFO, "created database '" . $username . "'");
|
||||
|
||||
// and give permission to the user on every access-host we have
|
||||
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
|
||||
$this->getManager()->grantPrivilegesTo($username, $password, $mysql_access_host);
|
||||
$this->_log->logAction(USR_ACTION, LOG_NOTICE, "grant all privileges for '" . $username . "'@'" . $mysql_access_host . "'");
|
||||
$this->log->logAction(USR_ACTION, LOG_NOTICE, "grant all privileges for '" . $username . "'@'" . $mysql_access_host . "'");
|
||||
}
|
||||
|
||||
$this->getManager()->flushPrivileges();
|
||||
@@ -119,7 +119,7 @@ class DbManager
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
return $this->_manager;
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,10 +128,10 @@ class DbManager
|
||||
*
|
||||
* sets private $_manager variable
|
||||
*/
|
||||
private function _setManager()
|
||||
private function setManager()
|
||||
{
|
||||
// TODO read different dbms from settings later
|
||||
$this->_manager = new \Froxlor\Database\Manager\DbManagerMySQL($this->_log);
|
||||
$this->manager = new \Froxlor\Database\Manager\DbManagerMySQL($this->log);
|
||||
}
|
||||
|
||||
public static function correctMysqlUsers($mysql_access_host_array)
|
||||
|
||||
@@ -27,7 +27,7 @@ class IntegrityCheck
|
||||
public $available = array();
|
||||
|
||||
// logger object
|
||||
private $_log = null;
|
||||
private $log = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -41,7 +41,7 @@ class IntegrityCheck
|
||||
'loginname' => 'integrity-check'
|
||||
);
|
||||
}
|
||||
$this->_log = \Froxlor\FroxlorLogger::getInstanceOf($userinfo);
|
||||
$this->log = \Froxlor\FroxlorLogger::getInstanceOf($userinfo);
|
||||
$this->available = get_class_methods($this);
|
||||
unset($this->available[array_search('__construct', $this->available)]);
|
||||
unset($this->available[array_search('checkAll', $this->available)]);
|
||||
@@ -91,7 +91,7 @@ class IntegrityCheck
|
||||
));
|
||||
$charset = isset($resp['default_character_set_name']) ? $resp['default_character_set_name'] : null;
|
||||
if (! empty($charset) && strtolower($charset) != 'utf8') {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "database charset seems to be different from UTF-8, integrity-check can fix that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "database charset seems to be different from UTF-8, integrity-check can fix that");
|
||||
if ($fix) {
|
||||
// fix database
|
||||
Database::query('ALTER DATABASE `' . Database::getDbName() . '` CHARACTER SET utf8 COLLATE utf8_general_ci');
|
||||
@@ -101,7 +101,7 @@ class IntegrityCheck
|
||||
$table = $row[0];
|
||||
Database::query('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;');
|
||||
}
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "database charset was different from UTF-8, integrity-check fixed that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "database charset was different from UTF-8, integrity-check fixed that");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -176,9 +176,9 @@ class IntegrityCheck
|
||||
'domainid' => $row['id_domain'],
|
||||
'ipandportid' => $row['id_ipandports']
|
||||
));
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found an ip/port-id in domain <> ip table which does not exist, integrity check fixed this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "found an ip/port-id in domain <> ip table which does not exist, integrity check fixed this");
|
||||
} else {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found an ip/port-id in domain <> ip table which does not exist, integrity check can fix this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "found an ip/port-id in domain <> ip table which does not exist, integrity check can fix this");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -188,9 +188,9 @@ class IntegrityCheck
|
||||
'domainid' => $row['id_domain'],
|
||||
'ipandportid' => $row['id_ipandports']
|
||||
));
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found a domain-id in domain <> ip table which does not exist, integrity check fixed this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "found a domain-id in domain <> ip table which does not exist, integrity check fixed this");
|
||||
} else {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found a domain-id in domain <> ip table which does not exist, integrity check can fix this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "found a domain-id in domain <> ip table which does not exist, integrity check can fix this");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -208,9 +208,9 @@ class IntegrityCheck
|
||||
'ipandportid' => $defaultip
|
||||
));
|
||||
}
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found a domain-id with no entry in domain <> ip table, integrity check fixed this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "found a domain-id with no entry in domain <> ip table, integrity check fixed this");
|
||||
} else {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found a domain-id with no entry in domain <> ip table, integrity check can fix this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "found a domain-id with no entry in domain <> ip table, integrity check can fix this");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -292,10 +292,10 @@ class IntegrityCheck
|
||||
Database::pexecute($upd_stmt, array(
|
||||
'domainid' => $id
|
||||
));
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check fixed this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check fixed this");
|
||||
} else {
|
||||
// It's just the check, let the function fail
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check can fix this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check can fix this");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -376,10 +376,10 @@ class IntegrityCheck
|
||||
Database::pexecute($upd_stmt, array(
|
||||
'domainid' => $id
|
||||
));
|
||||
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check fixed this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_WARNING, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check fixed this");
|
||||
} else {
|
||||
// It's just the check, let the function fail
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check can fix this");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check can fix this");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -415,7 +415,7 @@ class IntegrityCheck
|
||||
));
|
||||
|
||||
if ($cwg_stmt->rowCount() > 0) {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "Customers are missing the webserver-user as group-member, integrity-check can fix that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "Customers are missing the webserver-user as group-member, integrity-check can fix that");
|
||||
if ($fix) {
|
||||
// prepare update statement
|
||||
$upd_stmt = Database::prepare("
|
||||
@@ -430,7 +430,7 @@ class IntegrityCheck
|
||||
$upd_data['id'] = $cwg_row['id'];
|
||||
Database::pexecute($upd_stmt, $upd_data);
|
||||
}
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "Customers were missing the webserver-user as group-member, integrity-check fixed that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "Customers were missing the webserver-user as group-member, integrity-check fixed that");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ class IntegrityCheck
|
||||
));
|
||||
|
||||
if ($cwg_stmt->rowCount() > 0) {
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "Customers are missing the local froxlor-user as group-member, integrity-check can fix that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "Customers are missing the local froxlor-user as group-member, integrity-check can fix that");
|
||||
if ($fix) {
|
||||
// prepare update statement
|
||||
$upd_stmt = Database::prepare("
|
||||
@@ -498,7 +498,7 @@ class IntegrityCheck
|
||||
$upd_data['id'] = $cwg_row['id'];
|
||||
Database::pexecute($upd_stmt, $upd_data);
|
||||
}
|
||||
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "Customers were missing the local froxlor-user as group-member, integrity-check fixed that");
|
||||
$this->log->logAction(ADM_ACTION, LOG_NOTICE, "Customers were missing the local froxlor-user as group-member, integrity-check fixed that");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user