Skip to content

Commit 6e5b9e8

Browse files
committed
Handle upgrading from the PL plugin
1 parent e2c7550 commit 6e5b9e8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

activate.php

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ function sqlite_activation() {
3636
return;
3737
}
3838
if ( isset( $_GET['confirm-install'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'sqlite-install' ) ) {
39+
40+
// Handle upgrading from the performance-lab plugin.
41+
if ( isset( $_GET['upgrade-from-pl'] ) ) {
42+
// Delete the previous db.php file.
43+
unlink( WP_CONTENT_DIR . '/db.php' );
44+
// Deactivate the performance-lab SQLite module.
45+
$pl_option_name = defined( 'PERFLAB_MODULES_SETTING' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings';
46+
$pl_option = get_option( $pl_option_name, array() );
47+
unset( $pl_option['database/sqlite'] );
48+
update_option( $pl_option_name, $pl_option );
49+
remove_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); // Remove the PL-plugin admin notices.
50+
}
3951
sqlite_plugin_copy_db_file();
4052
// WordPress will automatically redirect to the install screen here.
4153
wp_redirect( admin_url() );

admin-page.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,40 @@ function sqlite_integration_admin_screen() {
5252
<p><?php esc_html_e( 'We detected that the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
5353
</div>
5454
<?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
55-
<div class="notice notice-error">
55+
<?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
56+
<div class="notice notice-warning">
5657
<p>
5758
<?php
5859
printf(
5960
/* translators: %s: db.php drop-in path */
60-
esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
61+
esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
6162
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
6263
);
6364
?>
6465
</p>
6566
</div>
67+
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>">
68+
<?php
69+
printf(
70+
/* translators: %s: db.php drop-in path */
71+
esc_html__( 'Update %s file', 'sqlite-database-integration' ),
72+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
73+
);
74+
?>
75+
</a>
76+
<?php else : ?>
77+
<div class="notice notice-error">
78+
<p>
79+
<?php
80+
printf(
81+
/* translators: %s: db.php drop-in path */
82+
esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
83+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
84+
);
85+
?>
86+
</p>
87+
</div>
88+
<?php endif; ?>
6689
<?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
6790
<div class="notice notice-error">
6891
<p>

0 commit comments

Comments
 (0)