]> git.joonet.de Git - adminer.git/commitdiff
Avoid global variables in plugins drivers
authorJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 12:14:35 +0000 (13:14 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 13:36:07 +0000 (14:36 +0100)
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/elastic5.php
plugins/drivers/firebird.php
plugins/drivers/simpledb.php

index a96666454d586dd82495ab214d9d70c8d96ae524..48a2e68d3771657810960ef3cbae432d4a9196b3 100644 (file)
@@ -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);
        }
 
index df6f92efe62b9c973f884c9f09486202f9b5b6cb..68a376021b86df2d4de34fb410a770020ba4198a 100644 (file)
@@ -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]);
 
index ec5ec5f68592bd8ba25c83caff0a497bcb86499a..a577e078500dce668d5ec18f9a23cfe5dcb66e02 100644 (file)
@@ -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]);
 
index fc46f3a7f2d73f75d8357bc8f3d0b083481f6f6d..8822d2866964b455266c6a87253a94c6d83bd335 100644 (file)
@@ -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);
        }
 
index 88f5efd90d6b427a85ef6e70cff4be5219c25686..b314e7e680f198ecf00f2845746e4064e8470644 100644 (file)
@@ -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');