From 2bec4ca11b7f1254469b62ce0a84a1941f4374d3 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 19 Feb 2025 13:14:35 +0100 Subject: [PATCH] Avoid global variables in plugins drivers --- plugins/drivers/clickhouse.php | 10 +++++----- plugins/drivers/elastic.php | 2 +- plugins/drivers/elastic5.php | 2 +- plugins/drivers/firebird.php | 12 ++++++------ plugins/drivers/simpledb.php | 15 ++++++++------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index a9666645..48a2e68d 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -210,7 +210,7 @@ if (isset($_GET["clickhouse"])) { } function connect() { - global $adminer; + $adminer = adminer(); $connection = new Min_DB; list($server, $username, $password) = $adminer->credentials(); if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) { @@ -223,7 +223,7 @@ if (isset($_GET["clickhouse"])) { } function get_databases($flush) { - global $connection; + $connection = connection(); $result = get_rows('SHOW DATABASES'); $return = array(); @@ -250,7 +250,7 @@ if (isset($_GET["clickhouse"])) { } function logged_user() { - global $adminer; + $adminer = adminer(); $credentials = $adminer->credentials(); return $credentials[1]; } @@ -270,7 +270,7 @@ if (isset($_GET["clickhouse"])) { } function table_status($name = "", $fast = false) { - global $connection; + $connection = connection(); $return = array(); $tables = get_rows("SELECT name, engine FROM system.tables WHERE database = " . q($connection->_db)); foreach ($tables as $table) { @@ -340,7 +340,7 @@ if (isset($_GET["clickhouse"])) { } function error() { - global $connection; + $connection = connection(); return h($connection->error); } diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index df6f92ef..68a37602 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -59,7 +59,7 @@ if (isset($_GET["elastic"])) { function query($path, array $content = null, $method = 'GET') { // Support for global search through all tables if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) { - global $driver; + $driver = get_driver(); $where = explode(" AND ", $matches[2]); diff --git a/plugins/drivers/elastic5.php b/plugins/drivers/elastic5.php index ec5ec5f6..a577e078 100644 --- a/plugins/drivers/elastic5.php +++ b/plugins/drivers/elastic5.php @@ -54,7 +54,7 @@ if (isset($_GET["elastic5"])) { function query($path, $content = array(), $method = 'GET') { // Support for global search through all tables if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) { - global $driver; + $driver = get_driver(); $where = explode(" AND ", $matches[2]); diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index fc46f3a7..8822d286 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -126,7 +126,7 @@ if (isset($_GET["firebird"])) { } function connect() { - global $adminer; + $adminer = adminer(); $connection = new Min_DB; $credentials = $adminer->credentials(); if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { @@ -158,13 +158,13 @@ if (isset($_GET["firebird"])) { } function logged_user() { - global $adminer; + $adminer = adminer(); $credentials = $adminer->credentials(); return $credentials[1]; } function tables_list() { - global $connection; + $connection = connection(); $query = 'SELECT RDB$RELATION_NAME FROM rdb$relations WHERE rdb$system_flag = 0'; $result = ibase_query($connection->_link, $query); $return = array(); @@ -180,7 +180,7 @@ if (isset($_GET["firebird"])) { } function table_status($name = "", $fast = false) { - global $connection; + $connection = connection(); $return = array(); $data = tables_list(); foreach ($data as $index => $val) { @@ -205,7 +205,7 @@ if (isset($_GET["firebird"])) { } function fields($table) { - global $connection; + $connection = connection(); $return = array(); $query = 'SELECT r.RDB$FIELD_NAME AS field_name, r.RDB$DESCRIPTION AS field_description, @@ -287,7 +287,7 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION'; } function error() { - global $connection; + $connection = connection(); return h($connection->error); } diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index 88f5efd9..b314e7e6 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -121,7 +121,7 @@ if (isset($_GET["simpledb"])) { public $primary = "itemName()"; function _chunkRequest($ids, $action, $params, $expand = array()) { - global $connection; + $connection = connection(); foreach (array_chunk($ids, 25) as $chunk) { $params2 = $params; foreach ($chunk as $i => $id) { @@ -151,7 +151,7 @@ if (isset($_GET["simpledb"])) { } function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { - global $connection; + $connection = connection(); $connection->next = $_GET["next"]; $return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print); $connection->next = 0; @@ -247,7 +247,7 @@ if (isset($_GET["simpledb"])) { function connect() { - global $adminer; + $adminer = adminer(); list($host, , $password) = $adminer->credentials(); if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) { return lang('Invalid server.'); @@ -263,7 +263,7 @@ if (isset($_GET["simpledb"])) { } function logged_user() { - global $adminer; + $adminer = adminer(); $credentials = $adminer->credentials(); return $credentials[1]; } @@ -280,7 +280,7 @@ if (isset($_GET["simpledb"])) { } function tables_list() { - global $connection; + $connection = connection(); $return = array(); foreach (sdb_request_all('ListDomains', 'DomainName') as $table) { $return[(string) $table] = 'table'; @@ -320,7 +320,7 @@ if (isset($_GET["simpledb"])) { } function error() { - global $connection; + $connection = connection(); return h($connection->error); } @@ -410,7 +410,8 @@ if (isset($_GET["simpledb"])) { } function sdb_request($action, $params = array()) { - global $adminer, $connection; + $adminer = adminer(); + $connection = connection(); list($host, $params['AWSAccessKeyId'], $secret) = $adminer->credentials(); $params['Action'] = $action; $params['Timestamp'] = gmdate('Y-m-d\TH:i:s+00:00');