Skip to content

Commit 97b4e79

Browse files
committed
Unify the SQLite setup screen
Combine installation requirements, database location guidance, and the install action in one panel. Clarify that switching does not copy the existing content, while preserving installation guards and Query Monitor support.
1 parent aadda18 commit 97b4e79

3 files changed

Lines changed: 192 additions & 115 deletions

File tree

‎packages/plugin-sqlite-database-integration/admin-page.css‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
color: #008a20;
8181
}
8282

83+
.sqlite-integration .sqlite-error {
84+
color: #d63638;
85+
}
86+
8387
.sqlite-integration .sqlite-box,
8488
.sqlite-integration .sqlite-help {
8589
background: #fff;
@@ -123,6 +127,10 @@
123127
margin: 0;
124128
}
125129

130+
.sqlite-integration .sqlite-setup-header p {
131+
margin: 8px 0 0;
132+
}
133+
126134
.sqlite-integration .sqlite-data p {
127135
margin: 0 0 10px;
128136
}
@@ -248,8 +256,48 @@
248256
cursor: pointer;
249257
}
250258

251-
.sqlite-integration .sqlite-installation .notice {
252-
margin-inline: 0;
259+
.sqlite-integration .sqlite-setup-header {
260+
padding: 20px;
261+
border-bottom: 1px solid #c3c4c7;
262+
}
263+
264+
.sqlite-integration .sqlite-setup-heading {
265+
display: flex;
266+
flex-wrap: wrap;
267+
align-items: center;
268+
justify-content: space-between;
269+
gap: 12px;
270+
}
271+
272+
.sqlite-integration .sqlite-setup-heading h2 {
273+
margin: 0;
274+
font-size: 16px;
275+
line-height: 1.5;
276+
}
277+
278+
.sqlite-integration .sqlite-inactive {
279+
color: #50575e;
280+
}
281+
282+
.sqlite-integration .sqlite-inactive .sqlite-status-dot {
283+
background: #787c82;
284+
}
285+
286+
.sqlite-integration .sqlite-setup-next {
287+
padding: 20px;
288+
border-top: 1px solid #c3c4c7;
289+
}
290+
291+
.sqlite-integration .sqlite-setup-next h3 {
292+
margin-top: 0;
293+
}
294+
295+
.sqlite-integration .sqlite-setup-actions {
296+
display: flex;
297+
flex-wrap: wrap;
298+
align-items: center;
299+
gap: 12px;
300+
margin-top: 20px;
253301
}
254302

255303
@media (pointer: coarse) {

‎packages/plugin-sqlite-database-integration/admin-page.php‎

Lines changed: 121 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -71,58 +71,147 @@ function sqlite_integration_admin_screen() {
7171
<?php if ( 'protection' === $tab ) : ?>
7272
<?php sqlite_plugin_render_protection_status( $status ); ?>
7373
<?php sqlite_plugin_render_protection_instructions(); ?>
74+
<?php elseif ( ! $active ) : ?>
75+
<?php sqlite_plugin_render_installation( $status ); ?>
7476
<?php else : ?>
7577
<?php $location = sqlite_plugin_get_database_location_details( $status ); ?>
7678
<section class="sqlite-box" aria-labelledby="sqlite-status-heading">
7779
<h2 id="sqlite-status-heading"><?php esc_html_e( 'Database status', 'sqlite-database-integration' ); ?></h2>
7880
<dl class="sqlite-data">
7981
<div><dt><?php esc_html_e( 'Integration', 'sqlite-database-integration' ); ?></dt><dd class="sqlite-status">
80-
<?php if ( $active ) : ?>
81-
<span class="sqlite-status-dot" aria-hidden="true"></span><?php esc_html_e( 'SQLite is active', 'sqlite-database-integration' ); ?>
82-
<?php else : ?>
83-
<?php esc_html_e( 'SQLite is not active', 'sqlite-database-integration' ); ?>
84-
<?php endif; ?>
82+
<span class="sqlite-status-dot" aria-hidden="true"></span><?php esc_html_e( 'SQLite is active', 'sqlite-database-integration' ); ?>
8583
</dd></div>
86-
<?php if ( $active ) : ?>
87-
<?php sqlite_plugin_render_database_details( sqlite_plugin_get_database_path() ); ?>
88-
<?php endif; ?>
84+
<?php sqlite_plugin_render_database_details( sqlite_plugin_get_database_path() ); ?>
8985
<div><dt><?php esc_html_e( 'Protection', 'sqlite-database-integration' ); ?></dt><dd>
9086
<p class="sqlite-status"><span class="dashicons <?php echo esc_attr( $location['icon'] ); ?>" aria-hidden="true"></span><strong><?php echo esc_html( $location['label'] ); ?></strong></p>
9187
<p><?php echo esc_html( $location['summary'] ); ?></p>
9288
<p><a href="<?php echo esc_url( add_query_arg( 'tab', 'protection', $url ) ); ?>"><?php esc_html_e( 'View protection status', 'sqlite-database-integration' ); ?></a></p>
9389
</dd></div>
9490
</dl>
9591
</section>
96-
<?php if ( $active ) : ?>
97-
<section class="sqlite-manage">
98-
<h2><?php esc_html_e( 'Manage the integration', 'sqlite-database-integration' ); ?></h2>
99-
<p><?php esc_html_e( 'Switching to MySQL does not copy your SQLite content.', 'sqlite-database-integration' ); ?></p>
100-
<details class="sqlite-help"><summary><?php esc_html_e( 'How to switch to MySQL', 'sqlite-database-integration' ); ?></summary><div>
101-
<p><?php esc_html_e( 'Back up your database. Prepare your MySQL database and configuration, and migrate any content you want to keep before switching.', 'sqlite-database-integration' ); ?></p>
102-
<p>
103-
<?php
104-
printf(
105-
/* translators: 1: Plugins page URL, 2: Drop-in file path relative to the content directory. */
106-
wp_kses_post( __( 'When ready, <a href="%1$s">deactivate the plugin</a> to remove the SQLite drop-in, or manually remove %2$s. Verify that your content loads correctly from MySQL.', 'sqlite-database-integration' ) ),
107-
esc_url( self_admin_url( 'plugins.php' ) ),
108-
'<code>' . esc_html( basename( WP_CONTENT_DIR ) . '/db.php' ) . '</code>'
109-
);
110-
?>
111-
</p>
112-
<?php if ( is_multisite() ) : ?>
113-
<p><?php esc_html_e( 'This change affects every site in the network.', 'sqlite-database-integration' ); ?></p>
114-
<?php endif; ?>
115-
</div></details>
116-
</section>
117-
<?php else : ?>
118-
<?php sqlite_plugin_render_installation(); ?>
119-
<?php endif; ?>
92+
<section class="sqlite-manage">
93+
<h2><?php esc_html_e( 'Manage the integration', 'sqlite-database-integration' ); ?></h2>
94+
<p><?php esc_html_e( 'Switching to MySQL does not copy your SQLite content.', 'sqlite-database-integration' ); ?></p>
95+
<details class="sqlite-help"><summary><?php esc_html_e( 'How to switch to MySQL', 'sqlite-database-integration' ); ?></summary><div>
96+
<p><?php esc_html_e( 'Back up your database. Prepare your MySQL database and configuration, and migrate any content you want to keep before switching.', 'sqlite-database-integration' ); ?></p>
97+
<p>
98+
<?php
99+
printf(
100+
/* translators: 1: Plugins page URL, 2: Drop-in file path relative to the content directory. */
101+
wp_kses_post( __( 'When ready, <a href="%1$s">deactivate the plugin</a> to remove the SQLite drop-in, or manually remove %2$s. Verify that your content loads correctly from MySQL.', 'sqlite-database-integration' ) ),
102+
esc_url( self_admin_url( 'plugins.php' ) ),
103+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) . '/db.php' ) . '</code>'
104+
);
105+
?>
106+
</p>
107+
<?php if ( is_multisite() ) : ?>
108+
<p><?php esc_html_e( 'This change affects every site in the network.', 'sqlite-database-integration' ); ?></p>
109+
<?php endif; ?>
110+
</div></details>
111+
</section>
120112
<?php endif; ?>
121113
</div>
122114
</div>
123115
<?php
124116
}
125117

118+
/**
119+
* Render setup while preserving installation requirements and drop-in support.
120+
*
121+
* @access private
122+
* @param string $status Location status.
123+
*/
124+
function sqlite_plugin_render_installation( $status ) {
125+
$db_dropin_path = WP_CONTENT_DIR . '/db.php';
126+
$location = sqlite_plugin_get_database_location_details( $status );
127+
128+
/*
129+
* When an existing "db.php" drop-in is detected, let's check if it's a known
130+
* plugin that we can continue supporting even when we override the drop-in.
131+
*/
132+
$override_db_dropin = false;
133+
if ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
134+
// Check for the Query Monitor plugin.
135+
// When "QM_DB" exists, it must have been loaded via the "db.php" file.
136+
if ( class_exists( 'QM_DB', false ) ) {
137+
$override_db_dropin = true;
138+
}
139+
}
140+
141+
$requirements_error = '';
142+
if ( ! extension_loaded( 'pdo_sqlite' ) ) {
143+
$requirements_error = __( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' );
144+
} elseif ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! $override_db_dropin ) {
145+
$requirements_error = sprintf(
146+
/* translators: %s: db.php drop-in path. */
147+
__( 'SQLite cannot be set up because a different %s drop-in already exists.', 'sqlite-database-integration' ),
148+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
149+
);
150+
} elseif ( ! is_writable( WP_CONTENT_DIR ) ) {
151+
$requirements_error = sprintf(
152+
/* translators: %s: WordPress content directory. */
153+
__( 'SQLite cannot be set up because the %s directory is not writable.', 'sqlite-database-integration' ),
154+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
155+
);
156+
}
157+
?>
158+
<section class="sqlite-box" aria-labelledby="sqlite-setup-heading">
159+
<header class="sqlite-setup-header">
160+
<div class="sqlite-setup-heading">
161+
<h2 id="sqlite-setup-heading"><?php esc_html_e( 'Set up SQLite', 'sqlite-database-integration' ); ?></h2>
162+
<span class="sqlite-status sqlite-inactive"><span class="sqlite-status-dot" aria-hidden="true"></span><?php esc_html_e( 'Not active', 'sqlite-database-integration' ); ?></span>
163+
</div>
164+
<p><?php esc_html_e( 'Use SQLite for a new WordPress installation.', 'sqlite-database-integration' ); ?></p>
165+
</header>
166+
<dl class="sqlite-data">
167+
<div><dt><?php esc_html_e( 'Server requirements', 'sqlite-database-integration' ); ?></dt><dd>
168+
<?php if ( $requirements_error ) : ?>
169+
<p class="sqlite-status"><span class="dashicons dashicons-warning sqlite-error" aria-hidden="true"></span><strong><?php esc_html_e( 'Requirements not met', 'sqlite-database-integration' ); ?></strong></p>
170+
<p><?php echo wp_kses_post( $requirements_error ); ?></p>
171+
<?php else : ?>
172+
<p class="sqlite-status"><span class="dashicons dashicons-yes-alt sqlite-success" aria-hidden="true"></span><strong><?php esc_html_e( 'Requirements met', 'sqlite-database-integration' ); ?></strong></p>
173+
<p><?php esc_html_e( 'PHP supports SQLite and the WordPress content directory is writable.', 'sqlite-database-integration' ); ?></p>
174+
<?php endif; ?>
175+
</dd></div>
176+
<div><dt><?php esc_html_e( 'Database location', 'sqlite-database-integration' ); ?></dt><dd>
177+
<p class="sqlite-status"><span class="dashicons <?php echo esc_attr( $location['icon'] ); ?>" aria-hidden="true"></span><strong><?php echo esc_html( $location['label'] ); ?></strong></p>
178+
<p><?php echo 'public' === $status ? esc_html__( 'The planned database location may be publicly accessible.', 'sqlite-database-integration' ) : esc_html( $location['summary'] ); ?></p>
179+
<p><a href="<?php echo esc_url( add_query_arg( 'tab', 'protection', sqlite_plugin_get_admin_page_url() ) ); ?>"><?php esc_html_e( 'How to protect your database', 'sqlite-database-integration' ); ?></a></p>
180+
</dd></div>
181+
</dl>
182+
<?php if ( ! $requirements_error ) : ?>
183+
<div class="sqlite-setup-next">
184+
<h3><?php esc_html_e( 'This starts a fresh WordPress site', 'sqlite-database-integration' ); ?></h3>
185+
<p><?php esc_html_e( 'Your current content stays in your existing database and is not copied to SQLite. You can return to your previous site by deactivating the plugin. Back up your current site before proceeding.', 'sqlite-database-integration' ); ?></p>
186+
<?php if ( is_multisite() ) : ?>
187+
<p><?php esc_html_e( 'This change affects every site in the network.', 'sqlite-database-integration' ); ?></p>
188+
<?php endif; ?>
189+
190+
<?php if ( $override_db_dropin ) : ?>
191+
<p>
192+
<strong>NOTE:</strong>
193+
<?php
194+
printf(
195+
/* translators: %s: db.php drop-in path */
196+
esc_html__( 'We’ve detected an existing database drop-in file at %s, created by the Query Monitor plugin.', 'sqlite-database-integration' ),
197+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
198+
);
199+
?>
200+
<?php esc_html_e( 'To enable SQLite support, this file will need to be replaced.', 'sqlite-database-integration' ); ?>
201+
<?php esc_html_e( 'The Query Monitor plugin will continue to function correctly after the change. You can safely proceed with the installation.', 'sqlite-database-integration' ); ?>
202+
</p>
203+
<?php endif; ?>
204+
205+
<div class="sqlite-setup-actions">
206+
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'confirm-install', '1', sqlite_plugin_get_admin_page_url() ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>
207+
<span class="description"><?php esc_html_e( 'Next: WordPress setup', 'sqlite-database-integration' ); ?></span>
208+
</div>
209+
</div>
210+
<?php endif; ?>
211+
</section>
212+
<?php
213+
}
214+
126215
/**
127216
* Render the location-only protection result.
128217
*
@@ -274,87 +363,6 @@ function sqlite_plugin_render_protection_instructions() {
274363
<?php
275364
}
276365

277-
/**
278-
* Preserve the installation requirements and drop-in replacement flow.
279-
*
280-
* @access private
281-
*/
282-
function sqlite_plugin_render_installation() {
283-
$db_dropin_path = WP_CONTENT_DIR . '/db.php';
284-
285-
/*
286-
* When an existing "db.php" drop-in is detected, let's check if it's a known
287-
* plugin that we can continue supporting even when we override the drop-in.
288-
*/
289-
$override_db_dropin = false;
290-
if ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
291-
// Check for the Query Monitor plugin.
292-
// When "QM_DB" exists, it must have been loaded via the "db.php" file.
293-
if ( class_exists( 'QM_DB', false ) ) {
294-
$override_db_dropin = true;
295-
}
296-
}
297-
298-
?>
299-
<section class="sqlite-installation">
300-
<?php if ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
301-
<div class="notice notice-error inline">
302-
<p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
303-
</div>
304-
<?php elseif ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! $override_db_dropin ) : ?>
305-
<div class="notice notice-error inline">
306-
<p>
307-
<?php
308-
printf(
309-
/* translators: %s: db.php drop-in path */
310-
esc_html__( 'SQLite cannot be set up because a different %s drop-in already exists.', 'sqlite-database-integration' ),
311-
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
312-
);
313-
?>
314-
</p>
315-
</div>
316-
<?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
317-
<div class="notice notice-error inline">
318-
<p>
319-
<?php
320-
printf(
321-
/* translators: %s: db.php drop-in path */
322-
esc_html__( 'SQLite cannot be set up because the %s directory is not writable.', 'sqlite-database-integration' ),
323-
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
324-
);
325-
?>
326-
</p>
327-
</div>
328-
<?php else : ?>
329-
<div class="notice notice-success inline">
330-
<p><?php esc_html_e( 'The required PHP extension and file permissions are available. Before installing, choose a database location that your web server does not expose.', 'sqlite-database-integration' ); ?></p>
331-
</div>
332-
<h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
333-
<p><?php esc_html_e( 'This plugin will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the plugin you will get back to your previous MySQL database, with all your previous data intact.', 'sqlite-database-integration' ); ?></p>
334-
335-
<?php if ( $override_db_dropin ) : ?>
336-
<p>
337-
<strong>NOTE:</strong>
338-
<?php
339-
printf(
340-
/* translators: %s: db.php drop-in path */
341-
esc_html__( 'We’ve detected an existing database drop-in file at %s, created by the Query Monitor plugin.', 'sqlite-database-integration' ),
342-
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
343-
);
344-
?>
345-
<?php esc_html_e( 'To enable SQLite support, this file will need to be replaced.', 'sqlite-database-integration' ); ?>
346-
<?php esc_html_e( 'The Query Monitor plugin will continue to function correctly after the change. You can safely proceed with the installation.', 'sqlite-database-integration' ); ?>
347-
</p>
348-
<?php endif; ?>
349-
350-
<p><?php esc_html_e( 'By clicking the button below, you will be redirected to the WordPress installation screen to setup your new database', 'sqlite-database-integration' ); ?></p>
351-
352-
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'confirm-install', '1', sqlite_plugin_get_admin_page_url() ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>
353-
<?php endif; ?>
354-
</section>
355-
<?php
356-
}
357-
358366
/**
359367
* Adds a link to the admin bar.
360368
*

‎tests/phpunit/WP_SQLite_Storage_Health_Test.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,27 @@ public function test_overview_shows_database_details_and_links_to_protection() {
232232
$this->assertStringContainsString( 'Copy path', $html );
233233
$this->assertStringContainsString( 'View protection status', $html );
234234
$this->assertStringNotContainsString( 'id="sqlite-database-protection"', $html );
235+
$this->assertStringNotContainsString( 'Install SQLite database', $html );
236+
}
237+
238+
public function test_setup_warns_about_the_location_without_blocking_installation() {
239+
ob_start();
240+
sqlite_plugin_render_installation( 'public' );
241+
$html = ob_get_clean();
242+
243+
$this->assertStringContainsString( 'Requirements met', $html );
244+
$this->assertStringContainsString( 'The planned database location may be publicly accessible.', $html );
245+
$this->assertStringContainsString( 'is not copied to SQLite', $html );
246+
$this->assertStringContainsString(
247+
esc_url( add_query_arg( 'tab', 'protection', sqlite_plugin_get_admin_page_url() ) ),
248+
$html
249+
);
250+
$this->assertStringContainsString(
251+
esc_url( wp_nonce_url( add_query_arg( 'confirm-install', '1', sqlite_plugin_get_admin_page_url() ), 'sqlite-install' ) ),
252+
$html
253+
);
254+
$this->assertStringNotContainsString( esc_html( DB_PATH ), $html );
255+
$this->assertSame( is_multisite(), false !== strpos( $html, 'This change affects every site in the network.' ) );
235256
}
236257

237258
public function test_outside_location_has_a_limited_positive_result() {

0 commit comments

Comments
 (0)