1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 22:56:46 +02:00

MongoDB: Move to plugin

This commit is contained in:
Jakub Vrana
2025-03-13 14:27:28 +01:00
parent 61f07867f9
commit 078957fe32
4 changed files with 18 additions and 29 deletions

View File

@@ -72,7 +72,6 @@ include "../adminer/drivers/sqlite.inc.php";
include "../adminer/drivers/pgsql.inc.php"; include "../adminer/drivers/pgsql.inc.php";
include "../adminer/drivers/oracle.inc.php"; include "../adminer/drivers/oracle.inc.php";
include "../adminer/drivers/mssql.inc.php"; include "../adminer/drivers/mssql.inc.php";
include "../adminer/drivers/mongo.inc.php";
include "./include/adminer.inc.php"; include "./include/adminer.inc.php";
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer); $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver include "../adminer/drivers/mysql.inc.php"; // must be included as last driver

View File

@@ -7,6 +7,7 @@ PostgreSQL PDO: Escape bytea values (bug #218)
CockroachDB: Display version CockroachDB: Display version
CockroachDB: Recognize unique_rowid() as auto_increment CockroachDB: Recognize unique_rowid() as auto_increment
MS SQL: Fix editing rows with datetime column in primary key MS SQL: Fix editing rows with datetime column in primary key
MongoDB: Move to plugin
CSS: Add dark theme CSS: Add dark theme
Adminer 5.0.4 (released 2025-03-11): Adminer 5.0.4 (released 2025-03-11):

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace Adminer; namespace Adminer;
$drivers["mongo"] = "MongoDB (alpha)"; add_driver("mongo", "MongoDB (alpha)");
if (isset($_GET["mongo"])) { if (isset($_GET["mongo"])) {
define('Adminer\DRIVER', "mongo"); define('Adminer\DRIVER', "mongo");
@@ -120,9 +120,8 @@ if (isset($_GET["mongo"])) {
function get_databases($flush) { function get_databases($flush) {
global $connection;
$return = array(); $return = array();
foreach ($connection->executeCommand(array('listDatabases' => 1)) as $dbs) { foreach (connection()->executeCommand(array('listDatabases' => 1)) as $dbs) {
foreach ($dbs->databases as $db) { foreach ($dbs->databases as $db) {
$return[] = $db->name; $return[] = $db->name;
} }
@@ -136,9 +135,8 @@ if (isset($_GET["mongo"])) {
} }
function tables_list() { function tables_list() {
global $connection;
$collections = array(); $collections = array();
foreach ($connection->executeCommand(array('listCollections' => 1)) as $result) { foreach (connection()->executeCommand(array('listCollections' => 1)) as $result) {
$collections[$result->name] = 'table'; $collections[$result->name] = 'table';
} }
return $collections; return $collections;
@@ -149,9 +147,8 @@ if (isset($_GET["mongo"])) {
} }
function indexes($table, $connection2 = null) { function indexes($table, $connection2 = null) {
global $connection;
$return = array(); $return = array();
foreach ($connection->executeCommand(array('listIndexes' => $table)) as $index) { foreach (connection()->executeCommand(array('listIndexes' => $table)) as $index) {
$descs = array(); $descs = array();
$columns = array(); $columns = array();
foreach (get_object_vars($index->key) as $column => $type) { foreach (get_object_vars($index->key) as $column => $type) {
@@ -169,7 +166,7 @@ if (isset($_GET["mongo"])) {
} }
function fields($table) { function fields($table) {
global $driver; $driver = get_driver();
$fields = fields_from_edit(); $fields = fields_from_edit();
if (!$fields) { if (!$fields) {
$result = $driver->select($table, array("*"), null, null, array(), 10); $result = $driver->select($table, array("*"), null, null, array(), 10);
@@ -198,9 +195,8 @@ if (isset($_GET["mongo"])) {
} }
function found_rows($table_status, $where) { function found_rows($table_status, $where) {
global $connection;
$where = where_to_query($where); $where = where_to_query($where);
$toArray = $connection->executeCommand(array('count' => $table_status['Name'], 'query' => $where))->toArray(); $toArray = connection()->executeCommand(array('count' => $table_status['Name'], 'query' => $where))->toArray();
return $toArray[0]->n; return $toArray[0]->n;
} }
@@ -225,7 +221,6 @@ if (isset($_GET["mongo"])) {
} }
function where_to_query($whereAnd = array(), $whereOr = array()) { function where_to_query($whereAnd = array(), $whereOr = array()) {
global $adminer;
$data = array(); $data = array();
foreach (array('and' => $whereAnd, 'or' => $whereOr) as $type => $where) { foreach (array('and' => $whereAnd, 'or' => $whereOr) as $type => $where) {
if (is_array($where)) { if (is_array($where)) {
@@ -235,7 +230,7 @@ if (isset($_GET["mongo"])) {
list(, $class, $val) = $match; list(, $class, $val) = $match;
$val = new $class($val); $val = new $class($val);
} }
if (!in_array($op, $adminer->operators)) { if (!in_array($op, adminer()->operators)) {
continue; continue;
} }
if (preg_match('~^\(f\)(.+)~', $op, $match)) { if (preg_match('~^\(f\)(.+)~', $op, $match)) {
@@ -409,13 +404,11 @@ if (isset($_GET["mongo"])) {
} }
function last_id() { function last_id() {
global $connection; return connection()->last_id;
return $connection->last_id;
} }
function error() { function error() {
global $connection; return h(connection()->error);
return h($connection->error);
} }
function collations() { function collations() {
@@ -423,13 +416,11 @@ if (isset($_GET["mongo"])) {
} }
function logged_user() { function logged_user() {
global $adminer; $credentials = adminer()->credentials();
$credentials = $adminer->credentials();
return $credentials[1]; return $credentials[1];
} }
function connect($credentials) { function connect($credentials) {
global $adminer;
$connection = new Db; $connection = new Db;
list($server, $username, $password) = $credentials; list($server, $username, $password) = $credentials;
@@ -442,7 +433,7 @@ if (isset($_GET["mongo"])) {
$options["username"] = $username; $options["username"] = $username;
$options["password"] = $password; $options["password"] = $password;
} }
$db = $adminer->database(); $db = adminer()->database();
if ($db != "") { if ($db != "") {
$options["db"] = $db; $options["db"] = $db;
} }
@@ -457,7 +448,7 @@ if (isset($_GET["mongo"])) {
} }
function alter_indexes($table, $alter) { function alter_indexes($table, $alter) {
global $connection; $connection = connection();
foreach ($alter as $val) { foreach ($alter as $val) {
list($type, $name, $set) = $val; list($type, $name, $set) = $val;
if ($set == "DROP") { if ($set == "DROP") {
@@ -514,17 +505,15 @@ if (isset($_GET["mongo"])) {
} }
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
global $connection;
if ($table == "") { if ($table == "") {
$connection->_db->createCollection($name); connection()->_db->createCollection($name);
return true; return true;
} }
} }
function drop_tables($tables) { function drop_tables($tables) {
global $connection;
foreach ($tables as $table) { foreach ($tables as $table) {
$response = $connection->_db->selectCollection($table)->drop(); $response = connection()->_db->selectCollection($table)->drop();
if (!$response['ok']) { if (!$response['ok']) {
return false; return false;
} }
@@ -533,9 +522,8 @@ if (isset($_GET["mongo"])) {
} }
function truncate_tables($tables) { function truncate_tables($tables) {
global $connection;
foreach ($tables as $table) { foreach ($tables as $table) {
$response = $connection->_db->selectCollection($table)->remove(); $response = connection()->_db->selectCollection($table)->remove();
if (!$response['ok']) { if (!$response['ok']) {
return false; return false;
} }

View File

@@ -3,7 +3,8 @@ Adminer Editor - Data manipulation for end-users
https://www.adminer.org/ https://www.adminer.org/
Supports: MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, MS SQL, Oracle, MongoDB, Elasticsearch (plugin), SimpleDB (plugin), Firebird (plugin), ClickHouse (plugin) Supports: MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, MS SQL, Oracle
Plugins for: Elasticsearch, SimpleDB, MongoDB, Firebird, ClickHouse
Requirements: PHP 5.3+ Requirements: PHP 5.3+
adminer/index.php - Run development version of Adminer adminer/index.php - Run development version of Adminer