Skip to content

PLANET-7686: Upgrade WP Stateless to version 4.1.3 #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 21, 2025

Conversation

mardelnet
Copy link
Contributor

@mardelnet mardelnet commented Mar 31, 2025

Ref: https://jira.greenpeace.org/browse/PLANET-7686
Related PR: greenpeace/planet4-master-theme#2598


Testing 1

  1. Set up a new development environment based out of a multilingual site (ie: GP Africa). For more details about running a WPML-enabled website locally, check this comment.
  2. Upgrade the plugin on your local environment using the command: npx wp-env run cli wp plugin update wp-stateless
  3. Confirm the upgrade from the plugins page.
  4. Go to the Stateless settings (/wp-admin/upload.php?page=stateless-settings) and change the mode to Stateless. You will need extra data to make it work (Bucket, Service Account JSON, and Domain). You can copy it from the Gutenberg instance.
  5. Run the data optimization by clicking on this button:
    image
  6. Wait for the process in the previous step to finish. You can check the status from here: Info > WP-Stateless > Data Optimization.
  7. Go to the Media Library. Add and remove some files. The changes should be reflected in the Google Cloud bucket.
  8. Replace some files using the Media Replacer (remember to flush the file cache after replacing it to see the new one). The changes should be reflected in the Google Cloud bucket, too.
  9. Go to the Greenpeace Media page. Add some files. The changes should be reflected in the Google Cloud bucket.
  10. Export a post or page with files in it. Import it in another P4 website. Check that everything looks all alright and that the changes were reflected in the Google Cloud bucket.
  11. Repeat the previous step, but now do the opposite: import a post or page in your local environment.

Testing 2

  1. Run the GP International site locally.
  2. Upgrade the plugin following the steps of "Testing 1".
  3. Check if this problem is fixed: https://jira.greenpeace.org/browse/PLANET-7558

Notes

Do we also want to try the Gravity Form add-on, @comzeradd?
Screenshot from 2025-03-31 11-13-16

- From version 3.4.1 to 4.1.3
@mardelnet mardelnet self-assigned this Mar 31, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mardelnet, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request upgrades the wp-stateless plugin dependency in composer.json from version 3.4.1 to 4.1.3. This update likely includes new features, bug fixes, and performance improvements provided by the newer version of the plugin.

Highlights

  • Dependency Upgrade: The wp-stateless plugin has been upgraded from version 3.4.1 to 4.1.3 in the composer.json file.

Changelog

  • composer.json
    • Upgraded wpackagist-plugin/wp-stateless from version 3.4.1 to 4.1.3.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is Composer, and what problem does it solve?

Click here for the answer
Composer is a dependency management tool for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request updates the wp-stateless plugin version in the composer.json file. This is a straightforward update, and the change appears correct.

Merge Readiness

The pull request updates a dependency version. Given the limited scope of the change, it seems appropriate for merging, assuming that the update has been tested and verified to be compatible with the project. I am unable to directly approve the pull request, and users should have others review and approve this code before merging.

@mardelnet mardelnet changed the title Upgrade WP Stateless to version 4.1.3 PLANET-7686: Upgrade WP Stateless to version 4.1.3 Mar 31, 2025
@sagarsdeshmukh
Copy link
Member

Regarding WP-Stateless - Gravity Forms Addon, IMO we should use it along with a WP_STATELESS_COMPATIBILITY_GF constant.

@mardelnet
Copy link
Contributor Author

Regarding WP-Stateless - Gravity Forms Addon, IMO we should use it along with a WP_STATELESS_COMPATIBILITY_GF constant.

Thanks, @sagarsdeshmukh
We could implement it in another PR if @comzeradd agrees.

@sagarsdeshmukh
Copy link
Member

Nice job @mardelnet 🎉

I have tested the new version of WP-Stateless on my local environment as well as the following test environments:

The new version of the WP-Stateless plugin is working as expected. No issues were encountered during testing.
Below are few suggestions/notes:

  • We can use the CLI command wp stateless migrate to perform data optimizations via the post-deploy script.

  • After running the data optimization, the notice banner keeps displaying:
    'WP-Stateless: Data Optimization Complete.'
    We can consider hiding this banner once the optimization is done, as it might be confusing for editors.

  • Since the 'data optimization' operation takes a few minutes(eg. The GP Africa dev site tooks 12 mins) to complete, we’ll need to plan its execution carefully. Additionally, the following points should be considered:

Create a backup copy of wp database.
Do not upload, edit, or delete media or files while the optimization process is underway.
Perform this update during a low period in your website traffic.

@mardelnet
Copy link
Contributor Author

Thank you so much, @sagarsdeshmukh

We can use the CLI command wp stateless migrate to perform data optimizations via the post-deploy script.

Can you please explain how to do this? I've no experience in adding or editing CLI commands.

After running the data optimization, the notice banner keeps displaying:
'WP-Stateless: Data Optimization Complete.'
We can consider hiding this banner once the optimization is done, as it might be confusing for editors.

How do you suggest doing this? PHP I suppose, right?

Since the 'data optimization' operation takes a few minutes(eg. The GP Africa dev site tooks 12 mins) to complete, we’ll need to plan its execution carefully. Additionally, the following points should be considered:

Create a backup copy of wp database.
Do not upload, edit, or delete media or files while the optimization process is underway.
Perform this update during a low period in your website traffic.

I'm adding @comzeradd to this conversation to discuss how to action in this last point.

@sagarsdeshmukh
Copy link
Member

Can you please explain how to do this? I've no experience in adding or editing CLI commands.

With every deployment, post-deploy scripts are executed—such as migration script or the 'Disable Attachment Pages' script.
We can include the data optimization CLI command as part of a new post-deploy script in the same way at here.

How do you suggest doing this? PHP I suppose, right?

Yes, that's right. The code below might be helpful -

add_action('admin_print_scripts', function () {
    echo '<style>
        #stateless-notice-migrations-finished { display: none !important; }
    </style>';
});

- From version 3.4.1 to 4.1.3
- Add post-deploy script
@mardelnet
Copy link
Contributor Author

Thanks @sagarsdeshmukh !

Can you please explain how to do this? I've no experience in adding or editing CLI commands.

With every deployment, post-deploy scripts are executed—such as migration script or the 'Disable Attachment Pages' script. We can include the data optimization CLI command as part of a new post-deploy script in the same way at here.

The post-deploy script was added. Can you please check it?

How do you suggest doing this? PHP I suppose, right?

Yes, that's right. The code below might be helpful -

I am not completely sure whether adding this would be a good idea for 2 reasons: editors can hide the message by simply clicking the close button (it doesn't re-appear on page reload) and the CSS code will hide any other future message related to migrations in WP Stateless. What do you think?

#!/bin/bash

echo "Perform WP-Stateless data optimization..."
wp stateless migrate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command lists a optimization id/records

$ npx wp-env run cli wp stateless migrate   
+----------------+------------------------------------+---------+--------------+
| id             | description                        | status  | message      |
+----------------+------------------------------------+---------+--------------+
| 20240423174109 | Optimize Compatibility Files       | Skipped | Not required |
| 20240219175240 | Update data for Google Cloud files | Pending | Ready to run |
+----------------+------------------------------------+---------+--------------+

We need to provide params with above command,
when we run npx wp-env run cli wp stateless -help on local -

usage: wp stateless migrate [<id|auto>] [--force] [--progress=<val>] [--email=<val>] [--yes] [--url=<val>]
   or: wp stateless reset_cache_control [--url=<val>]
   or: wp stateless sync <type> [--url=<val>] [--start=<val>] [--limit=<val>] [--end=<val>] [--batch=<val>] [--batches=<val>] [--b] [--log] [--o] [--order=<val>]
   or: wp stateless upgrade <type> [--url=<val>] [--start=<val>] [--limit=<val>] [--end=<val>] [--batch=<val>] [--batches=<val>] [--b] [--log] [--o]

I tried below command on local which works for me -
wp stateless migrate auto [email protected] --yes
here --yes skip confirmation(ref.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Should we use Nikos' email or is there a way to add the website admin's email?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess by default it will pick the website admin's email, but if we want to track the status during release process its good to add Nikos mail id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the command required for the upgrade? I deployed the branch on a test instance and the process times out because it takes a lot of time to finish.

We could upgrade the plugin and then I could manually trigger the migrate command outside of CircleCI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @comzeradd
In that case, manually triggering the migrate command will be better (I just removed it).
Perhaps we should let the NROs know of that beforehand so they don't do the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could hide the notices temporarily, just to make sure with a simple css rule. Right now I'm seeing this:

image

Something like that should work:

.stateless-admin-notice {
    display: none !important;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's something to be done in the master theme, right @comzeradd?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it makes more sense to be in the theme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Adjust post-deploy script
@mardelnet mardelnet requested a review from sagarsdeshmukh April 9, 2025 10:03
@mardelnet
Copy link
Contributor Author

@sagarsdeshmukh @comzeradd
Any additional comments regarding this PR?

@comzeradd
Copy link
Member

Any additional comments regarding this PR?

Testing the PR locally seems to work fine. But I'm getting a notice about the GF Add-on that may be confusing for NRO admins, thinking that the connection with GF is broken. So I think that may it's better to also install the add-on on this PR to have it in place on releasing this upgrade.

@mardelnet mardelnet force-pushed the PLANET-7686_upgrade-wp-stateless-to-4.1.x branch from 8162496 to 3154e4d Compare April 15, 2025 10:45
@mardelnet
Copy link
Contributor Author

Any additional comments regarding this PR?

Testing the PR locally seems to work fine. But I'm getting a notice about the GF Add-on that may be confusing for NRO admins, thinking that the connection with GF is broken. So I think that may it's better to also install the add-on on this PR to have it in place on releasing this upgrade.

Thanks @comzeradd
I've included the addon in the composer.json file and its installation in the post-deploy script.

wp plugin activate wp-stateless-gravity-forms-addon

echo "Perform WP-Stateless data optimization..."
wp stateless migrate auto [email protected] --yes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is not executable, failing to run. You can change that with:

chmod +x 09-wp-stateless.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@mardelnet mardelnet force-pushed the PLANET-7686_upgrade-wp-stateless-to-4.1.x branch from 3154e4d to 135461f Compare April 16, 2025 07:59
- Install and activate the GF addon
@sagarsdeshmukh
Copy link
Member

sagarsdeshmukh commented Apr 18, 2025

@sagarsdeshmukh @comzeradd Any additional comments regarding this PR?

Nothing to add from my side — looks good to me.

@mardelnet mardelnet merged commit f448e26 into main Apr 21, 2025
1 check passed
@mardelnet mardelnet deleted the PLANET-7686_upgrade-wp-stateless-to-4.1.x branch April 21, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants