ClassicPress / classic-commerce

A simple but powerful e-commerce platform built for ClassicPress. Forked from WooCommerce and compatible with many Woo extensions.
https://classiccommerce.cc/
GNU General Public License v3.0
54 stars 15 forks source link

Change version of WooCommerce reported by CC to 3.5.3 #143

Closed timbocode closed 4 years ago

timbocode commented 4 years ago

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:

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 commented 4 years ago

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 commented 4 years ago

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

timbocode commented 4 years ago

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

timbocode commented 4 years ago

Reopened pending new PR.

ghost commented 4 years ago

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 commented 4 years ago

Plugins still show as 0.1.0...

plugins

Status report shows 3.5.3...

status

timbocode commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

ghost commented 4 years ago

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

bahiirwa commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

cc_version

ghost commented 4 years ago

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

timbocode commented 4 years ago

New issue created #145

timbocode commented 4 years ago

PR #146

Still need thoughts on comment re redundant code above.

bahiirwa commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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