fix compatibility with php72

This commit is contained in:
xiaomlove
2021-01-04 20:47:22 +08:00
parent d8a3f5270f
commit 752e26000c
6 changed files with 40 additions and 34 deletions

View File

@@ -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)

View File

@@ -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)
{

View File

@@ -2,11 +2,11 @@
class DB
{
private DBInterface $driver;
private $driver;
private static $instance;
private static array $queries = [];
private static $queries = [];
private function __construct()
{

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}