Skip to content

Commit

Permalink
Handle upgrading from the PL plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed May 3, 2023
1 parent e2c7550 commit 6e5b9e8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 12 additions & 0 deletions activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ function sqlite_activation() {
return;
}
if ( isset( $_GET['confirm-install'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'sqlite-install' ) ) {

// Handle upgrading from the performance-lab plugin.
if ( isset( $_GET['upgrade-from-pl'] ) ) {
// Delete the previous db.php file.
unlink( WP_CONTENT_DIR . '/db.php' );

This comment has been minimized.

Copy link
@felixarntz

felixarntz May 8, 2023

Member

@aristath We need to use WP_Filesystem() and its underlying method for this, never modify files directly using low-level filesystem functions in WP.

This comment has been minimized.

Copy link
@aristath

aristath May 9, 2023

Author Member

Good catch. Done 👍

// Deactivate the performance-lab SQLite module.
$pl_option_name = defined( 'PERFLAB_MODULES_SETTING' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings';
$pl_option = get_option( $pl_option_name, array() );
unset( $pl_option['database/sqlite'] );
update_option( $pl_option_name, $pl_option );
remove_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); // Remove the PL-plugin admin notices.
}
sqlite_plugin_copy_db_file();
// WordPress will automatically redirect to the install screen here.
wp_redirect( admin_url() );
Expand Down
27 changes: 25 additions & 2 deletions admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,40 @@ function sqlite_integration_admin_screen() {
<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>
</div>
<?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<div class="notice notice-error">
<?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<div class="notice notice-warning">
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<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' ) ); ?>">
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'Update %s file', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</a>
<?php else : ?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<?php endif; ?>
<?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
<div class="notice notice-error">
<p>
Expand Down

0 comments on commit 6e5b9e8

Please sign in to comment.