abstracts
9 years ago
admin
9 years ago
api
9 years ago
cli
9 years ago
data-stores
9 years ago
emails
9 years ago
gateways
9 years ago
interfaces
9 years ago
legacy
9 years ago
libraries
9 years ago
log-handlers
9 years ago
payment-tokens
9 years ago
shipping
9 years ago
shortcodes
9 years ago
theme-support
9 years ago
vendor
9 years ago
walkers
9 years ago
widgets
9 years ago
class-wc-ajax.php
9 years ago
class-wc-api.php
9 years ago
class-wc-auth.php
9 years ago
class-wc-autoloader.php
9 years ago
class-wc-background-emailer.php
9 years ago
class-wc-background-updater.php
9 years ago
class-wc-breadcrumb.php
9 years ago
class-wc-cache-helper.php
9 years ago
class-wc-cart.php
9 years ago
class-wc-checkout.php
9 years ago
class-wc-cli.php
9 years ago
class-wc-comments.php
9 years ago
class-wc-countries.php
9 years ago
class-wc-coupon.php
9 years ago
class-wc-customer-download.php
9 years ago
class-wc-customer.php
9 years ago
class-wc-data-exception.php
9 years ago
class-wc-data-store.php
9 years ago
class-wc-datetime.php
9 years ago
class-wc-deprecated-action-hooks.php
9 years ago
class-wc-deprecated-filter-hooks.php
9 years ago
class-wc-download-handler.php
9 years ago
class-wc-emails.php
9 years ago
class-wc-embed.php
9 years ago
class-wc-form-handler.php
9 years ago
class-wc-frontend-scripts.php
9 years ago
class-wc-geo-ip.php
9 years ago
class-wc-geolocation.php
9 years ago
class-wc-https.php
9 years ago
class-wc-install.php
9 years ago
class-wc-integrations.php
9 years ago
class-wc-legacy-api.php
9 years ago
class-wc-log-levels.php
9 years ago
class-wc-logger.php
9 years ago
class-wc-order-factory.php
9 years ago
class-wc-order-item-coupon.php
9 years ago
class-wc-order-item-fee.php
9 years ago
class-wc-order-item-meta.php
9 years ago
class-wc-order-item-product.php
9 years ago
class-wc-order-item-shipping.php
9 years ago
class-wc-order-item-tax.php
9 years ago
class-wc-order-item.php
9 years ago
class-wc-order-refund.php
9 years ago
class-wc-order.php
9 years ago
class-wc-payment-gateways.php
9 years ago
class-wc-payment-tokens.php
9 years ago
class-wc-post-data.php
9 years ago
class-wc-post-types.php
9 years ago
class-wc-product-attribute.php
9 years ago
class-wc-product-download.php
9 years ago
class-wc-product-external.php
9 years ago
class-wc-product-factory.php
9 years ago
class-wc-product-grouped.php
9 years ago
class-wc-product-simple.php
9 years ago
class-wc-product-variable.php
9 years ago
class-wc-product-variation.php
9 years ago
class-wc-query.php
9 years ago
class-wc-register-wp-admin-settings.php
9 years ago
class-wc-session-handler.php
9 years ago
class-wc-shipping-rate.php
9 years ago
class-wc-shipping-zone.php
9 years ago
class-wc-shipping-zones.php
9 years ago
class-wc-shipping.php
9 years ago
class-wc-shortcodes.php
9 years ago
class-wc-structured-data.php
9 years ago
class-wc-tax.php
9 years ago
class-wc-template-loader.php
9 years ago
class-wc-tracker.php
9 years ago
class-wc-validation.php
9 years ago
class-wc-webhook.php
9 years ago
wc-account-functions.php
9 years ago
wc-attribute-functions.php
9 years ago
wc-cart-functions.php
9 years ago
wc-conditional-functions.php
9 years ago
wc-core-functions.php
9 years ago
wc-coupon-functions.php
9 years ago
wc-deprecated-functions.php
9 years ago
wc-formatting-functions.php
9 years ago
wc-notice-functions.php
9 years ago
wc-order-functions.php
9 years ago
wc-order-item-functions.php
9 years ago
wc-page-functions.php
9 years ago
wc-product-functions.php
9 years ago
wc-rest-functions.php
9 years ago
wc-stock-functions.php
9 years ago
wc-template-functions.php
9 years ago
wc-template-hooks.php
9 years ago
wc-term-functions.php
9 years ago
wc-update-functions.php
9 years ago
wc-user-functions.php
9 years ago
wc-webhook-functions.php
9 years ago
wc-widget-functions.php
9 years ago
class-wc-background-updater.php
135 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Background Updater |
| 4 | * |
| 5 | * Uses https://github.com/A5hleyRich/wp-background-processing to handle DB |
| 6 | * updates in the background. |
| 7 | * |
| 8 | * @class WC_Background_Updater |
| 9 | * @version 2.6.0 |
| 10 | * @package WooCommerce/Classes |
| 11 | * @category Class |
| 12 | * @author WooThemes |
| 13 | */ |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | if ( ! class_exists( 'WP_Async_Request', false ) ) { |
| 19 | include_once( dirname( __FILE__ ) . '/libraries/wp-async-request.php' ); |
| 20 | } |
| 21 | |
| 22 | if ( ! class_exists( 'WP_Background_Process', false ) ) { |
| 23 | include_once( dirname( __FILE__ ) . '/libraries/wp-background-process.php' ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * WC_Background_Updater Class. |
| 28 | */ |
| 29 | class WC_Background_Updater extends WP_Background_Process { |
| 30 | |
| 31 | /** |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $action = 'wc_updater'; |
| 35 | |
| 36 | /** |
| 37 | * Dispatch updater. |
| 38 | * |
| 39 | * Updater will still run via cron job if this fails for any reason. |
| 40 | */ |
| 41 | public function dispatch() { |
| 42 | $dispatched = parent::dispatch(); |
| 43 | $logger = wc_get_logger(); |
| 44 | |
| 45 | if ( is_wp_error( $dispatched ) ) { |
| 46 | $logger->error( |
| 47 | sprintf( 'Unable to dispatch WooCommerce updater: %s', $dispatched->get_error_message() ), |
| 48 | array( 'source' => 'wc_db_updates' ) |
| 49 | ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Handle cron healthcheck |
| 55 | * |
| 56 | * Restart the background process if not already running |
| 57 | * and data exists in the queue. |
| 58 | */ |
| 59 | public function handle_cron_healthcheck() { |
| 60 | if ( $this->is_process_running() ) { |
| 61 | // Background process already running. |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | if ( $this->is_queue_empty() ) { |
| 66 | // No data to process. |
| 67 | $this->clear_scheduled_event(); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | $this->handle(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Schedule fallback event. |
| 76 | */ |
| 77 | protected function schedule_event() { |
| 78 | if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { |
| 79 | wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Is the updater running? |
| 85 | * @return boolean |
| 86 | */ |
| 87 | public function is_updating() { |
| 88 | return false === $this->is_queue_empty(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Task |
| 93 | * |
| 94 | * Override this method to perform any actions required on each |
| 95 | * queue item. Return the modified item for further processing |
| 96 | * in the next pass through. Or, return false to remove the |
| 97 | * item from the queue. |
| 98 | * |
| 99 | * @param string $callback Update callback function |
| 100 | * @return mixed |
| 101 | */ |
| 102 | protected function task( $callback ) { |
| 103 | if ( ! defined( 'WC_UPDATING' ) ) { |
| 104 | define( 'WC_UPDATING', true ); |
| 105 | } |
| 106 | |
| 107 | $logger = wc_get_logger(); |
| 108 | |
| 109 | include_once( dirname( __FILE__ ) . '/wc-update-functions.php' ); |
| 110 | |
| 111 | if ( is_callable( $callback ) ) { |
| 112 | $logger->info( sprintf( 'Running %s callback', $callback ), array( 'source' => 'wc_db_updates' ) ); |
| 113 | call_user_func( $callback ); |
| 114 | $logger->info( sprintf( 'Finished %s callback', $callback ), array( 'source' => 'wc_db_updates' ) ); |
| 115 | } else { |
| 116 | $logger->notice( sprintf( 'Could not find %s callback', $callback ), array( 'source' => 'wc_db_updates' ) ); |
| 117 | } |
| 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Complete |
| 124 | * |
| 125 | * Override if applicable, but ensure that the below actions are |
| 126 | * performed, or, call parent::complete(). |
| 127 | */ |
| 128 | protected function complete() { |
| 129 | $logger = wc_get_logger(); |
| 130 | $logger->info( 'Data update complete', array( 'source' => 'wc_db_updates' ) ); |
| 131 | WC_Install::update_db_version(); |
| 132 | parent::complete(); |
| 133 | } |
| 134 | } |
| 135 |