Skip to content
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

Change version of WooCommerce reported by CC to 3.5.3 #143

Closed
timbocode opened this issue Dec 15, 2019 · 24 comments · Fixed by #146
Closed

Change version of WooCommerce reported by CC to 3.5.3 #143

timbocode opened this issue Dec 15, 2019 · 24 comments · Fixed by #146
Assignees

Comments

@timbocode
Copy link
Contributor

Describe the bug
See #131.

Plugins use a number of different methods to determine the version of WC that is active. Such plugins often require a minimum version of WC in order to a) activate and/or b) function correctly. At present, Classic Commerce reports version 1.0.0, the version of CC, rather than the version of WC it was forked from. Consequently, many plugins fail to activate.

This requires changes to the following as a minimum:

  • $woocommerce->version
  • WC_VERSION
  • WOOCOMMERCE_VERSION
  • woocommerce_db_version (options table)

To Reproduce
Try to activate a plugin the requires WC >= 3.0 (for example).

Screenshots
Example:
image

Expected behavior
Plugins checking for WC <= 3.5.3 should activate without error.

@timbocode timbocode added this to the Version 1.0.0 milestone Dec 15, 2019
@timbocode timbocode self-assigned this Dec 16, 2019
@timbocode timbocode added the Has PR Issue has a PR. label Dec 16, 2019
@timbocode timbocode removed the Has PR Issue has a PR. label Dec 16, 2019
@timbocode timbocode reopened this Dec 16, 2019
@timbocode
Copy link
Contributor Author

Can someone review?

The only change I've made, and all that seems necessary, is to set

public $version = '3.5.3'

in class-woocommerce.php.

@bahiirwa
Copy link
Collaborator

Change looks fine in includes\class-woocommerce.php. However, I could not find the PR though.

@timbocode
Copy link
Contributor Author

Yeah, my mistake. I'll explain on Slack. Do you want to go ahead and close this?

@timbocode
Copy link
Contributor Author

Reopened pending new PR.

@timbocode timbocode reopened this Dec 16, 2019
@ghost
Copy link

ghost commented Dec 16, 2019

When making this change on a test site I get a message in the dashboard:

update

If I click this I get a white screen. No errors logged.

@ghost
Copy link

ghost commented Dec 16, 2019

Plugins still show as 0.1.0...

plugins

Status report shows 3.5.3...

status

@timbocode
Copy link
Contributor Author

The database message will be because the db version has been bumped from 0.1.0 to 3.5.3. I don't know why it should white screen. It worked when I was testing it. I will check this tomorrow.

Re CC version. The CC version and the WC version can be independent of each other. We can start CC at 1.0.0 but ensure that it reports the WC version as 3.5.3. This is the same principle used in ClassicPress. CP is at 1.1.2 but reports version 4.9.x of WP.

@ghost
Copy link

ghost commented Dec 16, 2019

Turned on debugging and got this:
Fatal error: Uncaught Error: Call to a member function push_to_queue() on null in /home/robbiema/public_html/wp-content/plugins/classic-commerce/includes/class-wc-install.php:325 Stack trace: #0 /home/robbiema/public_html/wp-content/plugins/classic-commerce/includes/class-wc-install.php(164): WC_Install::update() #1 /home/robbiema/public_html/wp-includes/class-wp-hook.php(286): WC_Install::install_actions('') #2 /home/robbiema/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 /home/robbiema/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /home/robbiema/public_html/wp-admin/admin.php(156): do_action('admin_init') #5 {main} thrown in /home/robbiema/public_html/wp-content/plugins/classic-commerce/includes/class-wc-install.php on line 325

@ghost
Copy link

ghost commented Dec 16, 2019

I've just downloaded a fresh copy of CC and updated all the files on the site. Now when I change version to 3.5.3 it doesn't prompt me to update the database (and hence there is no error message).

I must have had an old version of some files in there. However, it is still confusing as the plugin page shows CC version 0.1.0, the status page shows CC version 3.5.3 and database version 0.1.0 (but the help message tells me these two should be the same).

@bahiirwa
Copy link
Collaborator

The update issue is interesting. We can add an HTML text In file to show this is WC 3.5.3 to remove confusion. The plugin version needs to be traceable so 0.1.0 will be fine.

@ghost
Copy link

ghost commented Dec 17, 2019

Is there some way to change the status page so it gets the version from the same place as the plugin page?

@ghost
Copy link

ghost commented Dec 17, 2019

At the moment it is using this value echo esc_html( $environment['version'] );

@bahiirwa
Copy link
Collaborator

Is there some way to change the status page so it gets the version from the same place as the plugin page?

Plugin gets version from the comments /**/ on the first file while the status picks from the variable updated via PR. Making it dynamic means we use something like plugin_data(). Ref https://wordpress.stackexchange.com/questions/18268/i-want-to-get-a-plugin-version-number-dynamically

@ghost
Copy link

ghost commented Dec 17, 2019

OK - I'll leave that to you coding people. 😉
The other option would be to change the heading in that field to say that the 3.5.3 value is the "Corresponding WC version", or something like that.

@timbocode
Copy link
Contributor Author

The reason why the updater gives a white screen and the reason for the 'Call to a member function push_to_queue() on null' error is because the requisite code has been removed from 'class-wc-install.php'.

In function init(), the following needs to be added:

add_action( 'init', array( __CLASS__, 'init_background_updater' ), 5 );

and then the following function needs to be added:

public static function init_background_updater() {
  include_once dirname( __FILE__ ) . '/class-wc-background-updater.php';
  self::$background_updater = new WC_Background_Updater();
}

@timbocode
Copy link
Contributor Author

To update the database (woocommerce_db_version) to the proper version:

Add the following to includes/wc-update-functions.php:

function wc_update_353_db_version() {
  WC_Install::update_db_version( '3.5.3' );
}

Add the following to includes/class-wc-install.php:

'3.5.3' => array(
  'wc_update_353_db_version',
)

at the end of the private static $db_updates array.

@timbocode
Copy link
Contributor Author

Regarding includes/wc-update-functions.php and includes/class-wc-install.php, is there a lot of redundant code we can get rid of?

Could everything except the code added above (i.e. everything not related to WC 3.5.3) be removed from both of these files?

Can anyone see any adverse implications of doing this?

@timbocode
Copy link
Contributor Author

Regarding the status report, something like this is easy enough to do:

cc_version

@ghost
Copy link

ghost commented Dec 17, 2019

Yes, that's good! Let's do that. Both values will be useful to have in a report.

@timbocode
Copy link
Contributor Author

New issue created #145

@timbocode timbocode added the Has PR Issue has a PR. label Dec 17, 2019
@timbocode
Copy link
Contributor Author

PR #146

Still need thoughts on comment re redundant code above.

@timbocode timbocode removed the Has PR Issue has a PR. label Dec 18, 2019
@bahiirwa
Copy link
Collaborator

Regarding includes/wc-update-functions.php and includes/class-wc-install.php, is there a lot of redundant code we can get rid of?

Could everything except the code added above (i.e. everything not related to WC 3.5.3) be removed from both of these files?

Can anyone see any adverse implications of doing this?

This in itself brings a new issue. There is code for WC < 3.0. Do we want to maintain this? If we have an answer for this we can then sort out that issue of redundant code too.

@timbocode
Copy link
Contributor Author

timbocode commented Dec 18, 2019

I was just in the process of doing a PR for this.

I think there are two separate issues.

Maintaining compatibility for WC < 3.0 is one issue.

But the issue I referred to only affects updates.

The question I am asking is: does the update code in includes/wc-update-functions.php and includes/class-wc-install.php only affect existing WC installations where someone is updating WooCommerce to a later version?

If you installed a clean copy of WooCommerce 3.5.3, would this update code still be required?

EDIT: the code I'm referring to is basically everything in includes/wc-update-functions.php except for the newly added wc_update_353_db_version() function and everything in the $db_updates array in includes/class-wc-install.php except for the '3.5.3' element.

@timbocode
Copy link
Contributor Author

I'll move this to a new issue as #143 is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants