This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest exploring an alternative route here, as the assumption that
wc_blocks_db_schema_version
is empty on fresh installs is a bit fragile. This option is updated whenevermaybe_create_tables
is triggered and this method is hooked to'admin_init'
, which is fired whenever an admin screen or script is being initialized, so fresh installs will have the default 0 value updated to 260 whenever the table creation is complete.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that checking
wc_blocks_db_schema_version
isn't the best approach, but unfortunately, it seems that it is the only way to check if it is a new installation.This code will be executed before that
admin_init
is triggered. Empty returns true if you pass 0 or "".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option is not deleted from the DB when the plugin is removed, so if someone at some point in the past had Woo and/or Woo blocks up and running, removed them, and now enabled them again,
$this->wc_blocks_update_1030_blockified_product_grid_block();
will be triggered and cause the same problem.Just to clarify, is the goal here to run the migration to all users that already had Woo installed (keeping the classic template) while at the same time displaying the blockified template for brand-new users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is fine since it is an uncommon use case. The user has an old version of WC Core. Remove it. Install the new one. The user will have the classic templates.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. I think that one way to reliably ensure a store is new when WooCommerce Blocks is enabled, is by looking for the existence of products or orders: a store that is brand new won't have at least one of those. Here's a loose example:
This way we have something more robust to rely on instead of the value of a DB migration to determine if the blockified template should be displayed or not. Also, notice that there's no condition to change the option back to false at any point in execution: this ensures that if someone enabled the plugin on a brand new store and after that created products/received orders, they won't have the legacy template accidentally displayed again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This graphic is just a representation of the current logic & unfortunately, doesn't answer my question: nothing in it explains why the plugin version is being used to determine if a store is new or not. And to reinforce my comment over here: #10415 (comment) there's no proposal to change what is represented in this image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We started saving the version of WC Blocks in the database only with WooCommerce Blocks 10.3.0 release.
So, if this condition below is true, it means that it isn't a new installation because:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "fresh WooCommerce installation" tries to answer it. It may be the insufficient choice of words, but this diagram was supposed to represent this table from this PR:
which clearly differentiates "New installation" from "Upgrade" and that's what the first condition in the diagram was supposed to represent ("Fresh installation" meaning "New installation" and not "Upgrade"). And we'd like to preserve that logic. Does that help answer the concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kmanijak , it does represent what the current implementation is, but unfortunately, I couldn't find any explanation why this decision was made on that PR =/.
Either way, we still have all the aforementioned problems to clear out, as the solution provided here does not apply to all use-case scenarios, with very important limitations as flagged on #10415 (comment) , #10415 (comment) and #10415 (comment) .
Since the decision was to proceed with this work for the patch release, I'll propose circling back to solve these problems in our next cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I cannot provide more context, as this PR was made way before I joined the project. It's possible the PR only represents the outcome of other discussions but I can't justify that as I wasn't there 😅. What I was trying to say is that the table represents the logic present in the project for months now and this PR aims to fix a specific scenario preserving those rules.
Agree! 👍