studio icon indicating copy to clipboard operation
studio copied to clipboard

Disable import/export for sites not using SQLite integration

Open fluiddot opened this issue 1 year ago • 8 comments

Related to https://github.com/Automattic/dotcom-forge/issues/8606#issuecomment-2288458361.

Proposed Changes

  • Add a function to determine if SQLite integration is installed on a site.
  • Add an IPC handler that determines if the Import/Export feature is supported for a site. For now, the condition we check is if SQLite integration is installed for that site as the import/export commands used only support SQLite databases. In the future, we could add more.
  • Render a warning notice in the Import/Export tab if the site doesn't have the SQLite integration.
Captura de pantalla 2024-09-26 a las 14 13 47

Testing Instructions

  • Create a site.
  • Navigate to the site folder.
  • Remove the file wp-content/db.php.
  • Navigate to the Import/Export tab.
  • Observe a warning notice is displayed and that the Import/Export functionality is disabled.
  • Select another site.
  • Observe the Import/Export functionality is enabled and working.

Pre-merge Checklist

  • [ ] Have you checked for TypeScript, React or other console errors?

fluiddot avatar Aug 14 '24 16:08 fluiddot

@matt-west let me know if you could take a look at the UI and share thoughts/feedback. I decided to use the WordPress Notice component as an initial iteration, but we could follow a better approach. Thanks 🙇 !

fluiddot avatar Aug 14 '24 16:08 fluiddot

@fluiddot Sorry for the slow response on this!

Using the Notice component here makes sense. We’ll have an updated version of this in the new design system, but we can use this one for now.

I think we could tweak the copy to something like:

Import / Export is not available for this site This feature is only available for sites using the default SQLite integration.

matt-west avatar Sep 20 '24 10:09 matt-west

@fluiddot Sorry for the slow response on this!

Using the Notice component here makes sense. We’ll have an updated version of this in the new design system, but we can use this one for now.

I think we could tweak the copy to something like:

Import / Export is not available for this site This feature is only available for sites using the default SQLite integration.

Great, thanks @matt-west for taking a look 🙇 ! I'll update the message and wrap up the PR with the current design 👍 .

fluiddot avatar Sep 23 '24 08:09 fluiddot

@jeroenpf @matt-west I've addressed the latest comments and updated the message in the notice. The PR is now ready to review. Thanks 🙇 !

fluiddot avatar Sep 26 '24 12:09 fluiddot

@fluiddot it works for most of my sites. However, it disables Import / Export for some older sites that had -main appended to the sqlite plugin name:

Screenshot 2024-09-26 at 14 41 44

Could we handle those, too?

wojtekn avatar Sep 26 '24 12:09 wojtekn

@fluiddot it works for most of my sites. However, it disables Import / Export for some older sites that had -main appended to the sqlite plugin name:

Screenshot 2024-09-26 at 14 41 44

Could we handle those, too?

Sure, I'll cover this case when we use -main for the folder's name. I feel this case can be easily overlooked when testing, so I'll consider adding some unit tests to cover it.

fluiddot avatar Sep 26 '24 13:09 fluiddot

@wojtekn, I wonder how is possible to have a site with the old integration 🤔 .

From what I can see the old/main SQLite folder gets renamed when the site starts.

https://github.com/Automattic/studio/blob/792b39ecd7b3ac100497d0251776c86c336f5fa0/src/lib/sqlite-versions.ts#L173

https://github.com/Automattic/studio/blob/792b39ecd7b3ac100497d0251776c86c336f5fa0/src/lib/sqlite-versions.ts#L139-L142

Could you share your zip? Maybe your site is using MySQL?

sejas avatar Oct 04 '24 13:10 sejas

@sejas I checked two sites, and one has a plugin in wp-content/mu-plugins/sqlite-database-integration-main and another in wp-content/plugins/sqlite-database-integration.

The sites that show the warning, have the plugin in wp-content/mu-plugins/sqlite-database-integration. Stopping and starting site doesn't change anything.

wojtekn avatar Oct 04 '24 15:10 wojtekn

@wojtekn , can you try again?

I tried using a different approach, by checking if the $wpdb uses the SQLite PHP class, but I had to go back to use the paths check because my approach only worked for started sites. Making it work for stopped sites is possible but we need a big refactor, and I think that is currently out of scope of this issue.

Here is the code for reference to check if SQLite is used in a WordPress site:

		const isSQLitePhp = `<?php
		require_once('${ this.server?.php?.documentRoot }/wp-load.php');
		global $wpdb;
		echo get_class($wpdb) === 'WP_SQLite_DB' ? 'true' : 'false';
		`;
		let isSQLiteString = null;
		try {
			isSQLiteString = await this.server?.runPhp( {
				code: isSQLitePhp,
			} );
		} catch ( error ) {
			Sentry.captureException( error );
		}
		return isSQLiteString === 'true';

So in the end I just added the alternative paths and added a new test. Let me know if it works for your old sites.

sejas avatar Nov 18 '24 18:11 sejas