WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.63k stars 251 forks source link

UpdraftPlus plugins doesn't fully work in Playground #1272

Open wojtekn opened 6 months ago

wojtekn commented 6 months ago

UpdraftPlus plugin only works in Playground partially.

Steps to reproduce:

  1. Load Playground with the UpdraftPlus plugin installed: https://playground.wordpress.net/?plugin=updraftplus
  2. Navigate to WP Admin: /wp-admin/admin.php?page=updraftplus
  3. Open the browser console
  4. Notice SQL errors:
    [18-Apr-2024 08:21:20 UTC] WordPress database error <div style="clear:both">&nbsp;</div>
    <div class="queries" style="clear:both;margin-bottom:2px;border:red dotted thin;">
    <p>MySQL query:</p>
    <p>SELECT @@session.max_allowed_packet</p>
    <p>Queries made or created this session were:</p>
    <ol>
    <li>Executing: BEGIN | (no parameters)</li>
    <li>Executing: SELECT @@session.max_allowed_packet | (no parameters)</li>
    <li>Executing: ROLLBACK | (no parameters)</li>
    </ol>

There is also JS errors displayed Uncaught ReferenceError: updraftlion is not defined in the console. Clicking different buttons triggers more errors like Uncaught ReferenceError: updraft_backup_dialog_open is not defined, but I'm not sure if those are related to the Playground environment or the plugin itself.

adamziel commented 6 months ago

In the SQLite plugin we should either:

In v1 we could use a hardcoded mapping of variable -> value. In v2 we could create a SQLite database table and source the data from there, also supporting SET. Would you start a new issue / pr in that repo @brandonpayton? CC @aristath

brandonpayton commented 6 months ago

I created https://github.com/WordPress/sqlite-database-integration/issues/104 for this and added some notes over the weekend. Planning to work on this today.

brandonpayton commented 5 months ago

I ended up fixing the unit tests for sqlite-database-integration today before adding a test to prove these queries are failing.

After adding failing test(s), my general plan is:

After that, we can consider allowing SET to simply modify this mapping. This seems straightforward for @@SESSION variables because they are scoped to the current connection, but for @@GLOBAL and @@PERSIST variables, maybe it would make sense to actually consider some kind of persistence.

brandonpayton commented 5 months ago

NOTE: It turns out @@PERSIST vars are "not permitted in expressions", which I believe includes expressions within SELECT statements based on this doc: https://dev.mysql.com/doc/refman/8.0/en/set-variable.html#variable-references-in-expressions

brandonpayton commented 5 months ago

Started a PR with failing tests for this issue here: https://github.com/WordPress/sqlite-database-integration/pull/109

As a v1, let's start with support for the specific variables used by UpdraftPlus, with an eye to broaden support over time.

The set I found in a recent checkout of UpdraftPlus is:

@@character_set_client
@@character_set_results
@@collation_connection
@@GLOBAL.gtid_purged
@@GLOBAL.log_bin
@@GLOBAL.log_bin_trust_function_creators
@@GLOBAL.sql_mode
@@SESSION.max_allowed_packet
@@SESSION.sql_mode
brandonpayton commented 5 months ago

It turns out that sqlite-database-integration already had a hack to avoid failures for queries for @@SESSION.sql_mode: https://github.com/WordPress/sqlite-database-integration/blob/23ed2215dd468a4d9d5f488ecefa66d0118efc50/wp-includes/sqlite/class-wp-sqlite-translator.php#L1455-L1466

                } elseif (
                        strpos( $updated_query, '@@SESSION.sql_mode' ) !== false
                        || strpos( $updated_query, 'CONVERT( ' ) !== false
                ) {
                        /*
                         * If the query contains a function that is not supported by SQLite,
                         * return a dummy select. This check must be done after the query
                         * has been rewritten to use parameters to avoid false positives
                         * on queries such as `SELECT * FROM table WHERE field='CONVERT('`.
                         */
                        $updated_query = 'SELECT 1=0';
                        $params        = array();

It would be great to have actual support for working with some of these vars, but as a v0, maybe we should just broaden the condition to match all @@GLOBAL.vars and @@SESSION.vars.

I don't yet know how to test dev version of sqlite-database-integration with Playground but plan to find out and test with this change: https://github.com/WordPress/sqlite-database-integration/pull/109/commits/21b0ad2066acf20d927009dbd55abe330fe085dd

brandonpayton commented 5 months ago

I tested with the above workaround, and there are no more query errors. Of course, faking the query is not the same as the real thing, but perhaps avoiding the errors in the meantime is a net gain.

There is also JS errors displayed Uncaught ReferenceError: updraftlion is not defined in the console. Clicking different buttons triggers more errors like Uncaught ReferenceError: updraft_backup_dialog_open is not defined, but I'm not sure if those are related to the Playground environment or the plugin itself.

@wojtekn I tested UpdraftPlus on a WordPress.com site, and am getting the same errors. There are no query errors, but the same JS errors remain so that it is not possible to trigger a backup from the admin page you linked to.

brandonpayton commented 5 months ago

The sqlite-database-integration plugin has been updated to at least tolerate selecting MySQL system vars, and Playground will pick up the changes when rebuilding WordPress. Will see if I can trigger that workflow rather than waiting on a schedule.

brandonpayton commented 5 months ago

@wojtekn with the latest changes to sqlite-database-integration, there are no more SQL var errors here (blueprint with updraft plus and the admin page).

Since the WordPress zips have been updated and deployed with the latest sqlite-database-integration, I believe this means that wp-now and Studio get the fix when doing new WP downloads. Is that correct?

adamziel commented 5 months ago

I believe this can be closed now, great work @brandonpayton! @wojtekn feel free to reopen if any other issues come up.

wojtekn commented 5 months ago

Thanks @brandonpayton !

Since the WordPress zips have been updated and deployed with the latest sqlite-database-integration, I believe this means that wp-now and Studio get the fix when doing new WP downloads. Is that correct?

Currently, we prepackage the SQLite plugin with Studio, so it won't be automatically updated for current installations. The new Studio release will include the new SQLite version. We are going to change it under https://github.com/Automattic/dotcom-forge/issues/6939

dcalhoun commented 5 months ago

I've noted that the ReferenceError: Can't find variable: updraftlion error remains presents in some circumstances. It appears a different SQL query error occurs during the backup and then leads to the aforementioned reference error in the browser.

0001.896 (0) PHP event: code E_WARNING: Undefined variable $entries (line 3373, wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php)
0001.897 (0) PHP Fatal error (TypeError) has occurred. Error Message: implode(): Argument #1 ($pieces) must be of type array, string given (Code: 0, line 3373 in /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php)
0001.897 (0) An error condition has occurred for the first time during this job
Full backup log ``` 0000.000 (0) Opened log file at time: Mon, 20 May 2024 16:34:37 +0000 on https://playground.wordpress.net/scope:0.5814657568889526 0000.001 (0) UpdraftPlus WordPress backup plugin (https://updraftplus.com): 1.24.3 WP: 6.5.3 PHP: 8.0.30-dev (cli, Emscripten emscripten 3.1.43 #1 wasm32) MySQL: 5.5 (max packet size=0) WPLANG: en_US Server: PHP.wasm safe_mode: 0 max_execution_time: 900 memory_limit: 256M (used: 28M | 30M) multisite: N openssl: OpenSSL 1.1.0h 27 Mar 2018 mcrypt: N LANG: en_US.UTF-8 ZipArchive::addFile: Y 0000.002 (0) Free space on disk containing Updraft's temporary directory: 1953.1 MB 0000.005 (0) Tasks: Backup files: 1 (schedule: unset) Backup DB: 1 (schedule: unset) 0000.006 (0) Semaphore (fd, wp_options) being initialised 0000.009 (0) Requesting semaphore lock (fd) (apparently not via scheduler) 0000.012 (0) Set semaphore last lock (fd) time to 2024-05-20 16:34:37 0000.013 (0) Semaphore lock (fd) complete 0000.017 (0) Backup run: resumption=0, nonce=fe9a2477e91b, file_nonce=fe9a2477e91b begun at=1716222877 (1s ago), job type=backup 0000.019 (0) Scheduling a resumption (1) after 300 seconds (1716223178) in case this run gets aborted 0000.025 (0) Checking if we have a zip executable available 0000.027 (0) Creation of backups of directories: beginning 0000.029 (0) Beginning creation of dump of plugins (split every: 400 MB) 0000.098 (0) Total entities for the zip file: 209 directories, 1221 files (0 skipped as non-modified), 24.7 MB 0000.106 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 100 files added (on-disk size: 0 KB) 0000.113 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 200 files added (on-disk size: 0 KB) 0000.120 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 300 files added (on-disk size: 0 KB) 0000.127 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 400 files added (on-disk size: 0 KB) 0000.134 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 500 files added (on-disk size: 0 KB) 0000.144 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 600 files added (on-disk size: 0 KB) 0000.154 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 700 files added (on-disk size: 0 KB) 0000.164 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 800 files added (on-disk size: 0 KB) 0000.172 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 900 files added (on-disk size: 0 KB) 0000.181 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 1000 files added (on-disk size: 0 KB) 0000.182 (0) Adding batch to zip file (UpdraftPlus_ZipArchive): over 1000 files added on this batch (23.7 MB, 1221 files batched, 1001 (1001) added so far); re-opening (prior size: 0 KB) 0001.447 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 1100 files added (on-disk size: 7139.9 KB) 0001.456 (0) Zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.tmp: 1200 files added (on-disk size: 7139.9 KB) 0001.631 (0) Creating zip file manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.list-temp.tmp) 0001.633 (0) Successfully created zip file manifest (size: 107132) 0001.701 (0) Created plugins zip (0) - 7482.5 KB in 1.7 s (4480.5 KB/s) (sha1: 5be77e7b191043e359a9fa5d77f9190dab1a65cd, sha256: 5cf01864ae392101033dba799a8f7c08fa7e89d7d756782b1dffd14e0fe1e823) 0001.704 (0) Cloud backup selection (1/1): none with instance (1/1) (last) 0001.705 (0) No remote despatch: user chose no remote backup service 0001.705 (0) Recording as successfully uploaded: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip 0001.707 (0) Deleting zip manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-plugins.zip.list.tmp) 0001.710 (0) Retain: beginning examination of existing backup sets; user setting: retain_files=2, retain_db=2 0001.711 (0) Number of backup sets in history: 0; groups (db): 1 0001.711 (0) Number of backup sets in history: 0; groups (files): 1 0001.712 (0) Retain: saving new backup history (sets now: 0) and finishing retain operation 0001.717 (0) Beginning creation of dump of themes (split every: 400 MB) 0001.722 (0) Total entities for the zip file: 8 directories, 91 files (0 skipped as non-modified), 1.3 MB 0001.758 (0) Creating zip file manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-themes.zip.list-temp.tmp) 0001.759 (0) Successfully created zip file manifest (size: 6055) 0001.772 (0) Created themes zip (0) - 1197 KB in 0.1 s (22584.8 KB/s) (sha1: 2f73ff1d85ddce8dee389877b6a3a484d67a4d38, sha256: 80e1bb6deca3d9f6ccb444a19c2171b09e1f3f14da2975e8d7e2734b33de247b) 0001.775 (0) Cloud backup selection (1/1): none with instance (1/1) (last) 0001.776 (0) No remote despatch: user chose no remote backup service 0001.777 (0) Recording as successfully uploaded: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-themes.zip 0001.778 (0) Deleting zip manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-themes.zip.list.tmp) 0001.780 (0) Retain: beginning examination of existing backup sets; user setting: retain_files=2, retain_db=2 0001.781 (0) Number of backup sets in history: 0; groups (db): 1 0001.781 (0) Number of backup sets in history: 0; groups (files): 1 0001.782 (0) Retain: saving new backup history (sets now: 0) and finishing retain operation 0001.786 (0) Exclusion option setting (uploads): backup*,*backups,backwpup*,wp-clone,snapshots 0001.787 (0) Looking for candidates to backup in: /wordpress/wp-content/uploads 0001.788 (0) finding files: 2024: adding to list (1) 0001.788 (0) Beginning creation of dump of uploads (split every: 400 MB) 0001.790 (0) Total entities for the zip file: 2 directories, 0 files (0 skipped as non-modified), 0 MB 0001.793 (0) Did not find any files in the zip: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-uploads.zip.tmp 0001.798 (0) Created uploads zip (0) - 0.2 KB in 0 s (28.3 KB/s) (sha1: 217a071f968a64530acc7bc3042fc9ad0c393b73, sha256: 60ba64e0f1fe49d178751caf8df738c3a1101561976ab7a5692fe22acc3859d9) 0001.800 (0) Beginning creation of dump of mu-plugins (split every: 400 MB) 0001.804 (0) Total entities for the zip file: 7 directories, 35 files (0 skipped as non-modified), 0.4 MB 0001.827 (0) Creating zip file manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-mu-plugins.zip.list-temp.tmp) 0001.828 (0) Successfully created zip file manifest (size: 2758) 0001.833 (0) Created mu-plugins zip (0) - 104.7 KB in 0 s (3377.8 KB/s) (sha1: cb674b1ac05edfa58b226180d8602e17e340147a, sha256: 339e0de6a5c8153727a6cd5f7aa617b2943e1dfe6693f230853f11eb108999f8) 0001.836 (0) Cloud backup selection (1/1): none with instance (1/1) (last) 0001.837 (0) No remote despatch: user chose no remote backup service 0001.837 (0) Recording as successfully uploaded: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-mu-plugins.zip 0001.839 (0) Deleting zip manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-mu-plugins.zip.list.tmp) 0001.840 (0) Retain: beginning examination of existing backup sets; user setting: retain_files=2, retain_db=2 0001.841 (0) Number of backup sets in history: 0; groups (db): 1 0001.842 (0) Number of backup sets in history: 0; groups (files): 1 0001.842 (0) Retain: saving new backup history (sets now: 0) and finishing retain operation 0001.848 (0) Beginning backup of other directories found in the content directory (index: 0) 0001.849 (0) Exclusion option setting (others): upgrade,cache,updraft,backup*,*backups,mysql.sql,debug.log 0001.849 (0) Looking for candidates to backup in: /wordpress/wp-content 0001.850 (0) finding files: database: adding to list (1) 0001.850 (0) finding files: mu-plugins: skipping: this is the mu-plugins directory 0001.851 (0) finding files: plugins: skipping: this is the plugins directory 0001.851 (0) finding files: themes: skipping: this is the themes directory 0001.852 (0) finding files: db.php: adding to list (2) 0001.852 (0) finding files: index.php: adding to list (3) 0001.853 (0) finding files: fonts: adding to list (4) 0001.853 (0) finding files: updraft: skipping: this is the updraft directory 0001.854 (0) finding files: uploads: skipping: this is the uploads directory 0001.856 (0) Total entities for the zip file: 2 directories, 5 files (0 skipped as non-modified), 0.2 MB 0001.863 (0) Creating zip file manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-others.zip.list-temp.tmp) 0001.864 (0) Successfully created zip file manifest (size: 145) 0001.868 (0) Created others zip (0) - 22.8 KB in 0 s (1896.3 KB/s) (sha1: 3a57edd87e1d56bd765eb3d966a031b2c5d38bf5, sha256: bd700f5aca344d339dc7cf78d4acea6304725d28c5329cae2b49af2855063a8f) 0001.871 (0) Cloud backup selection (1/1): none with instance (1/1) (last) 0001.872 (0) No remote despatch: user chose no remote backup service 0001.872 (0) Recording as successfully uploaded: backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-others.zip 0001.874 (0) Deleting zip manifest (backup_2024-05-20-1634_My_WordPress_Website_fe9a2477e91b-others.zip.list.tmp) 0001.876 (0) Retain: beginning examination of existing backup sets; user setting: retain_files=2, retain_db=2 0001.877 (0) Number of backup sets in history: 0; groups (db): 1 0001.878 (0) Number of backup sets in history: 0; groups (files): 1 0001.878 (0) Retain: saving new backup history (sets now: 0) and finishing retain operation 0001.886 (0) Saving backup status to database (elements: 10) 0001.888 (0) Beginning creation of database dump (WordPress DB) 0001.889 (0) SQL compatibility mode is: 0 0001.896 (0) PHP event: code E_WARNING: Undefined variable $entries (line 3373, wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php) 0001.897 (0) PHP Fatal error (TypeError) has occurred. Error Message: implode(): Argument #1 ($pieces) must be of type array, string given (Code: 0, line 3373 in /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php) 0001.897 (0) An error condition has occurred for the first time during this job ```

Steps to Reproduce

  1. Load Playground with the UpdraftPlus plugin installed: https://playground.wordpress.net/?plugin=updraftplus
  2. Navigate to the WP Admin.
  3. Navigate to Plugins.
  4. Important: Click "Press here to start!" in the UpdraftPlus tooltip[^1].
  5. Click the "Backup Now" button and then "Backup Now" in the modal.

@adamziel is it appropriate to reopen this issue based on this discovery?

[^1]: If you do not use the tooltip for navigating to the UpdraftPlus Backups page, then the browser immediately loads with the reference error, preventing you from starting a backup and uncovering the SQL error in the log.

adamziel commented 5 months ago

Thank you for reporting! And yes, it is appropriate. Cc @brandonpayton

brandonpayton commented 5 months ago

@dcalhoun thanks for reporting the SQLite-database-integration fatal. I added this to my list for investigation.

Regarding the JS error:

I've noted that the ReferenceError: Can't find variable: updraftlion error remains presents in some circumstances.

This is something I observed when running the plugin directly on a WP Cloud site, so I have not considered it a Playground-related issue. Please let me know if you disagree.

dcalhoun commented 5 months ago

This [updraftlion error] is something I observed when running the plugin directly on a WP Cloud site, so I have not considered it a Playground-related issue. Please let me know if you disagree.

Yes ā€” thank you for sharing this! I have experienced similar things on non-Playground sites sporadically but kept doubting myself. šŸ˜†

While the reproduction I shared in https://github.com/WordPress/wordpress-playground/issues/1272#issuecomment-2120820926 is definitely consistent and seemingly related to sqlite-database-integration, I agree there are likely circumstances where the updraftlion error occurs and is unrelated to Playground. I'm just not sure what those circumstances are currently. šŸ¤”

brandonpayton commented 5 months ago

, I agree there are likely circumstances where the updraftlion errors occurs and is unrelated to Playground. I'm just not sure what those circumstances are, currently. šŸ¤”

ah, OK. I'll keep my eye out in case SQLite-database-integration is contributing to the incidence of that JS error.