diff --git a/classes/class_cache_redis.php b/classes/class_cache_redis.php index 9913f6c1..eee8047b 100644 --- a/classes/class_cache_redis.php +++ b/classes/class_cache_redis.php @@ -19,7 +19,7 @@ class RedisCache { public $redis; function __construct() { - $success = $this->createRedisClient(); // Connect to Redis + $success = $this->connect($host = 'localhost', $port = 6379); // Connect to Redis if ($success) { $this->isEnabled = 1; } else { @@ -27,9 +27,9 @@ class RedisCache { } } - private function createRedisClient() + private function connect($host, $port) { - global $BASIC; + global $BASIC, $TWEAK; $redis = new Redis(); $params = [ $BASIC['redis_host'], @@ -40,29 +40,26 @@ class RedisCache { if (!empty($BASIC['redis_timeout'])) { $params[] = $BASIC['redis_timeout']; } - $connectResult = $redis->connect(...$params); - $auth = []; - if (!empty($BASIC['redis_password'])) { - $auth['pass'] = $BASIC['redis_password']; - if (!empty($BASIC['redis_username'])) { - $auth['user'] = $BASIC['redis_username']; + try { + $connectResult = $redis->connect(...$params); + $auth = []; + if (!empty($BASIC['redis_password'])) { + $auth['pass'] = $BASIC['redis_password']; + if (!empty($BASIC['redis_username'])) { + $auth['user'] = $BASIC['redis_username']; + } + $connectResult = $connectResult && $redis->auth($auth); } - $connectResult = $connectResult && $redis->auth($auth); - } - if ($connectResult) { - if (is_numeric($BASIC['redis_database'])) { - $selectDatabaseResult = $redis->select($BASIC['redis_database']); - if (!$selectDatabaseResult) { - $msg = "select redis database: {$BASIC['redis_database']} fail"; - write_log($msg); - throw new \RuntimeException($msg); + if ($connectResult) { + $this->redis = $redis; + if (is_numeric($BASIC['redis_database'])) { + $redis->select($BASIC['redis_database']); } } - $this->redis = $redis; - } else { - write_log(sprintf('connect to redis with params: %s , with auth: %s fail', json_encode($params), json_encode($auth))); + return $connectResult; + } catch (\Exception $exception) { + return false; } - return $connectResult; } function getIsEnabled() { @@ -205,6 +202,9 @@ class RedisCache { // Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour function cache_value($Key, $Value, $Duration = 3600){ + if (!$this->getIsEnabled()) { + return; + } $Value = $this->serialize($Value); // $this->set($Key,$Value, 0, $Duration); $this->redis->set($Key, $Value, $Duration); @@ -263,6 +263,9 @@ class RedisCache { // Wrapper for Memcache::get. Why? Because wrappers are cool. function get_value($Key) { + if (!$this->getIsEnabled()) { + return false; + } if($this->getClearCache()){ $this->delete_value($Key); return false; @@ -282,6 +285,9 @@ class RedisCache { // Wrapper for Memcache::delete. For a reason, see above. function delete_value($Key, $AllLang = false){ + if (!$this->getIsEnabled()) { + return 0; + } if ($AllLang){ $langfolder_array = $this->getLanguageFolderArray(); foreach($langfolder_array as $lf) diff --git a/forums.php b/forums.php index 8c62098e..8dc51145 100644 --- a/forums.php +++ b/forums.php @@ -474,7 +474,7 @@ if ($action == "viewtopic") $topicid = $_GET["topicid"] ?? 0; int_check($topicid,true); - $page = $_GET["page"] ?? ''; + $page = $_GET["page"] ?? 0; $authorid = $_GET["authorid"] ?? 0; if ($authorid) { diff --git a/include/database/class_db.php b/include/database/class_db.php index 842b8a14..10352b14 100644 --- a/include/database/class_db.php +++ b/include/database/class_db.php @@ -2,11 +2,11 @@ class DB { - private DBInterface $driver; + private $driver; private static $instance; - private static array $queries = []; + private static $queries = []; private function __construct() { diff --git a/include/database/class_db_mysqli.php b/include/database/class_db_mysqli.php index 13698dd8..3c165105 100644 --- a/include/database/class_db_mysqli.php +++ b/include/database/class_db_mysqli.php @@ -2,7 +2,7 @@ class DBMysqli implements DBInterface { - private mysqli $mysqli; + private $mysqli; public function connect($host, $username, $password, $database, $port) { @@ -43,17 +43,17 @@ class DBMysqli implements DBInterface return $this->mysqli->select_db($database); } - public function fetchAssoc($mysqliResult): array|null + public function fetchAssoc($mysqliResult) { return $mysqliResult->fetch_assoc(); } - public function fetchRow($mysqliResult): array|null + public function fetchRow($mysqliResult) { return $mysqliResult->fetch_row(); } - public function fetchArray($mysqliResult, $type): array|null + public function fetchArray($mysqliResult, $type) { if (is_null($type)) { $type = MYSQLI_BOTH; diff --git a/include/database/interface_db.php b/include/database/interface_db.php index 4eeca962..f5940776 100644 --- a/include/database/interface_db.php +++ b/include/database/interface_db.php @@ -14,11 +14,11 @@ interface DBInterface public function selectDb($database); - public function fetchAssoc($result): array|null; + public function fetchAssoc($result); - public function fetchRow($result): array|null; + public function fetchRow($result); - public function fetchArray($result, $type): array|null; + public function fetchArray($result, $type); public function affectedRows(): int; diff --git a/index.php b/index.php index 8451c5c6..5f643f30 100644 --- a/index.php +++ b/index.php @@ -300,12 +300,12 @@ if ($CURUSER && $showpolls_main == "yes") $os = array(); // Count votes - while (($arr2 = mysql_fetch_row($res) !== null) && isset($vs[$arr2[0]])) + while (($arr2 = mysql_fetch_row($res) !== null) && isset($arr2[0]) && isset($vs[$arr2[0]])) $vs[$arr2[0]] ++; reset($o); for ($i = 0; $i < count($o); ++$i){ - if ($o[$i]) + if (isset($vs[$i]) && isset($o[$i]) && $o[$i]) $os[$i] = array($vs[$i], $o[$i], $i); }