Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Fix WC 8.6 `wc_get_log_file_path()` deprecation warnings #566

Closed james-allan closed 4 months ago

james-allan commented 4 months ago

Description

This PR fixes failing unit tests, updates the way we point users to the view a certain log file and deprecates cleaning up large log files as WC core now handles that functionality.

How to test this PR

Cron job

  1. Install a plugin like WP Crontrol to view cron jobs.
  2. Go to Tools > Cron events
  3. Search for wcs_cleanup_big_logs and notice that job is still queued.

image

  1. Checkout this branch and that should be updated to have no action attached to it.
  2. Go into your database and search the options table for woocommerce_subscriptions_active_version.
  3. Update that option to be 6.7.0 (minus 1 version).
    • This will just trigger the upgrade flow.
  4. Notice that wcs_cleanup_big_logs is no longer listed.

Scheduled action notice

  1. Install WooCommerce 8.6 beta from the zips here: https://github.com/woocommerce/woocommerce/tags
  2. Simulate a fatal error during a subscription scheduled action by deleting a subscription from the database and running it's payment action manually or update the scheduled action directly and alter the subscription ID arg so it isn't valid.
  3. You should see the following notice:
Screenshot 2024-02-08 at 2 17 24 pm
  1. On trunk clicking the WooCommerce logs screen link will send you to the logs screen but not to the files directly.
  2. On this branch the logs table will only include failed-scheduled-actions files.

wcs-upgrade

  1. I wasn't able to find a way to get this page to show easily so I verified that my changes in this PR correctly generated valid HTML using WP Console.
// Get the log file URL depending on the log handler (file or database).
$url = admin_url( sprintf( 'admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', WCS_Upgrade_Logger::$handle, sanitize_file_name( wp_hash( WCS_Upgrade_Logger::$handle ) ) ) );

// In WC 8.6 the URL format changed to include the source parameter.
if ( ! wcs_is_woocommerce_pre( '8.6.0' ) ) {
    $url = admin_url( sprintf( 'admin.php?page=wc-status&tab=logs&source=%s&paged=1', WCS_Upgrade_Logger::$handle ) );
}

// translators: $1: placeholder is number of weeks, 2$: path to the file
echo wp_kses_post( sprintf( __( 'To record the progress of the update a new log file was created. This file will be automatically deleted in %1$d weeks. If you would like to delete it sooner, you can find it in the %2$sWooCommerce logs screen%3$s.', 'woocommerce-subscriptions' ), esc_html( WCS_Upgrade_Logger::$weeks_until_cleanup ), '<a href="' . esc_url( $url ) . '">', '</a>' ) );

Product impact