| 1 |
<?php |
| 2 |
/** |
| 3 |
* Update to 1.9.0. |
| 4 |
* |
| 5 |
* Clean up bloated woocommerce-pos log files caused by i18n translation |
| 6 |
* download spam (thundering herd race condition on missing locales). |
| 7 |
* |
| 8 |
* @author Paul Kilmurray <paul@kilbot.com> |
| 9 |
* |
| 10 |
* @see http://wcpos.com |
| 11 |
* @package WCPOS\WooCommercePOS |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace WCPOS\WooCommercePOS; |
| 15 |
|
| 16 |
$wcpos_log_dir = trailingslashit( wp_upload_dir()['basedir'] ) . 'wc-logs/'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- update script file scope. |
| 17 |
|
| 18 |
if ( ! is_dir( $wcpos_log_dir ) ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$wcpos_log_files = glob( $wcpos_log_dir . 'woocommerce-pos-*.log' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- update script file scope. |
| 23 |
|
| 24 |
if ( empty( $wcpos_log_files ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
$wcpos_deleted_count = 0; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- update script file scope. |
| 29 |
foreach ( $wcpos_log_files as $wcpos_log_file ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- update script file scope. |
| 30 |
if ( wp_delete_file( $wcpos_log_file ) || ! file_exists( $wcpos_log_file ) ) { |
| 31 |
++$wcpos_deleted_count; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
if ( \function_exists( 'wc_get_logger' ) && $wcpos_deleted_count > 0 ) { |
| 36 |
$wcpos_update_logger = wc_get_logger(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- update script file scope. |
| 37 |
$wcpos_update_logger->info( |
| 38 |
sprintf( 'WCPOS 1.9.0 migration: cleaned up %d POS log file(s) from i18n spam.', $wcpos_deleted_count ), |
| 39 |
array( 'source' => 'woocommerce-pos' ) |
| 40 |
); |
| 41 |
} |
| 42 |
|