Skip to content

Commit 2f258c0

Browse files
committed
Fix Adminer setup and driver loading
1 parent ab3d257 commit 2f258c0

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

packages/playground/website/src/components/site-manager/site-database-panel/adminer-button.tsx

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,35 @@ const adminerUrl =
1717

1818
async function installAdminer(playground: PlaygroundClient) {
1919
const documentRoot = await playground.documentRoot;
20-
const adminerPath = `${documentRoot}/adminer.php`;
21-
const pluginsPath = `${documentRoot}/adminer-plugins`;
20+
const adminerPath = `${documentRoot}/adminer/`;
2221

2322
const steps: StepDefinition[] = [
23+
{ step: 'mkdir', path: adminerPath },
2424
{
2525
step: 'writeFile',
26-
path: adminerPath,
26+
path: `${adminerPath}/adminer.php`,
2727
data: {
2828
resource: 'url',
2929
url: adminerUrl,
3030
},
3131
},
32-
{ step: 'mkdir', path: pluginsPath },
32+
{
33+
step: 'writeFile',
34+
path: `${adminerPath}/adminer-mysql-on-sqlite-driver.php`,
35+
data: (
36+
await import(
37+
'./adminer-extensions/adminer-mysql-on-sqlite-driver.php?raw'
38+
)
39+
).default as string,
40+
},
41+
{
42+
step: 'writeFile',
43+
path: `${adminerPath}/index.php`,
44+
data: (await import('./adminer-extensions/index.php?raw'))
45+
.default as string,
46+
},
3347
];
3448

35-
const plugins = import.meta.glob<string>('./adminer-plugins/*', {
36-
eager: true,
37-
query: '?raw',
38-
import: 'default',
39-
});
40-
const files: Record<string, string> = {};
41-
for (const [srcPath, content] of Object.entries(plugins)) {
42-
const fileName = srcPath.split('/').pop()!;
43-
files[fileName] = content;
44-
}
45-
46-
if (Object.entries(files).length > 0) {
47-
steps.push({
48-
step: 'writeFiles',
49-
writeToPath: pluginsPath,
50-
filesTree: {
51-
resource: 'literal:directory',
52-
name: 'adminer-plugins',
53-
files: files,
54-
},
55-
});
56-
}
57-
5849
const blueprint = await compileBlueprintV1(
5950
{ steps },
6051
{ corsProxy: corsProxyUrl }
@@ -97,7 +88,7 @@ export function AdminerButton({
9788
const playgroundUrl = await playground.absoluteUrl;
9889
if (playgroundUrl) {
9990
window.open(
100-
`${playgroundUrl}/adminer.php`,
91+
`${playgroundUrl}/adminer/`,
10192
'_blank',
10293
'noopener,noreferrer'
10394
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* An Adminer driver plugin for the MySQL-on-SQLite driver.
4+
* An Adminer driver for MySQL-on-SQLite.
55
*
66
* This implementation is based on Adminer\SqlDb and Adminer\Db classes.
77
* It is modified to use the MySQL-on-SQLite driver instead of MySQLi.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* Adminer loader file.
5+
*
6+
* Setup the MySQL-on-SQLite driver and login automatically.
7+
*
8+
* @see https://www.adminer.org/en/extension/
9+
*/
10+
11+
/**
12+
* Automatically log in when the query string is empty (= login page).
13+
*/
14+
if (!count($_GET)) {
15+
$_POST['auth'] = [
16+
'driver' => 'server',
17+
'server' => '127.0.0.1',
18+
'username' => 'db_user',
19+
'password' => 'db_password',
20+
'db' => 'wordpress'
21+
];
22+
}
23+
24+
/**
25+
* Load Adminer with the SQLite driver plugin.
26+
*
27+
* We need to define a custom "adminer_object" function to ensure the custom
28+
* Adminer driver is loaded after Adminer classes are defined, but before the
29+
* built-in MySQL/MariaDB driver is loaded.
30+
*
31+
* @see https://www.adminer.org/en/extension/
32+
*/
33+
function adminer_object() {
34+
require_once __DIR__ . '/adminer-mysql-on-sqlite-driver.php';
35+
return new Adminer\Adminer();
36+
}
37+
require_once __DIR__ . '/adminer.php';

packages/playground/website/src/components/site-manager/site-database-panel/adminer-plugins/adminer-auto-login-plugin.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)