File "class-wc-background-process.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/abstracts/class-wc-background-process.php
File
size: 4.14 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
defined('ABSPATH') || exit;
if (!class_exists('WP_Async_Request', false)) {
include_once dirname(WC_PLUGIN_FILE) . '/includes/libraries/wp-async-request.php';
}
if (!class_exists('WP_Background_Process', false)) {
include_once dirname(WC_PLUGIN_FILE) . '/includes/libraries/wp-background-process.php';
}
abstract class WC_Background_Process extends WP_Background_Process
{
protected function is_queue_empty()
{
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
if (is_multisite()) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
}
$key = $wpdb->esc_like($this->identifier . '_batch_') . '%';
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", $key));
return !($count > 0);
}
protected function get_batch()
{
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
$key_column = 'option_id';
$value_column = 'option_value';
if (is_multisite()) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
$key_column = 'meta_id';
$value_column = 'meta_value';
}
$key = $wpdb->esc_like($this->identifier . '_batch_') . '%';
$query = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", $key));
$batch = new stdClass();
$batch->key = $query->{$column};
$batch->data = array_filter((array) maybe_unserialize($query->{$value_column}));
return $batch;
}
protected function batch_limit_exceeded()
{
return $this->time_exceeded() || $this->memory_exceeded();
}
protected function handle()
{
$this->lock_process();
do {
$batch = $this->get_batch();
foreach ($batch->data as $key => $value) {
$task = $this->task($value);
if (false !== $task) {
$batch->data[$key] = $task;
} else {
unset($batch->data[$key]);
}
if ($this->batch_limit_exceeded()) {
break;
}
}
if (!empty($batch->data)) {
$this->update($batch->key, $batch->data);
} else {
$this->delete($batch->key);
}
} while (!$this->batch_limit_exceeded() && !$this->is_queue_empty());
$this->unlock_process();
if (!$this->is_queue_empty()) {
$this->dispatch();
} else {
$this->complete();
}
}
protected function get_memory_limit()
{
if (function_exists('ini_get')) {
$memory_limit = ini_get('memory_limit');
} else {
$memory_limit = '128M';
}
if (!$memory_limit || -1 === intval($memory_limit)) {
$memory_limit = '32G';
}
return wp_convert_hr_to_bytes($memory_limit);
}
public function schedule_cron_healthcheck($schedules)
{
$interval = apply_filters($this->identifier . '_cron_interval', 5);
if (property_exists($this, 'cron_interval')) {
$interval = apply_filters($this->identifier . '_cron_interval', $this->cron_interval);
}
$schedules[$this->identifier . '_cron_interval'] = array('interval' => MINUTE_IN_SECONDS * $interval, 'display' => sprintf(__('Every %d minutes', 'woocommerce'), $interval));
return $schedules;
}
public function delete_all_batches()
{
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
if (is_multisite()) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
}
$key = $wpdb->esc_like($this->identifier . '_batch_') . '%';
$wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE {$column} LIKE %s", $key));
return $this;
}
public function kill_process()
{
if (!$this->is_queue_empty()) {
$this->delete_all_batches();
wp_clear_scheduled_hook($this->cron_hook_identifier);
}
}
}