mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 14:52:56 +00:00
2.0.19
This commit is contained in:
@@ -32,18 +32,6 @@ abstract class ActionScheduler {
|
||||
return ActionScheduler_AdminView::instance();
|
||||
}
|
||||
|
||||
public static function get_datetime_object( $when ) {
|
||||
$when = empty($when) ? time() : $when;
|
||||
if ( is_object($when) && $when instanceof DateTime ) {
|
||||
$date = $when;
|
||||
} elseif ( is_numeric( $when ) ) {
|
||||
$date = new DateTime( '@'.$when );
|
||||
} else {
|
||||
$date = new DateTime( $when );
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute system path to the plugin directory, or a file therein
|
||||
* @static
|
||||
@@ -121,5 +109,12 @@ abstract class ActionScheduler {
|
||||
}
|
||||
|
||||
final private function __construct() {}
|
||||
|
||||
/** Deprecated **/
|
||||
|
||||
public static function get_datetime_object( $when = null, $timezone = 'UTC' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' );
|
||||
return as_get_datetime_object( $when, $timezone );
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ class ActionScheduler_ActionFactory {
|
||||
* @return string The ID of the stored action
|
||||
*/
|
||||
public function single( $hook, $args = array(), $when = NULL, $group = '' ) {
|
||||
$date = ActionScheduler::get_datetime_object( $when );
|
||||
$date = as_get_datetime_object( $when );
|
||||
$schedule = new ActionScheduler_SimpleSchedule( $date );
|
||||
$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
|
||||
return $this->store( $action );
|
||||
@@ -32,7 +32,7 @@ class ActionScheduler_ActionFactory {
|
||||
if ( empty($interval) ) {
|
||||
return $this->single( $hook, $args, $first, $group );
|
||||
}
|
||||
$date = ActionScheduler::get_datetime_object( $first );
|
||||
$date = as_get_datetime_object( $first );
|
||||
$schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
|
||||
$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
|
||||
return $this->store( $action );
|
||||
@@ -52,7 +52,7 @@ class ActionScheduler_ActionFactory {
|
||||
if ( empty($schedule) ) {
|
||||
return $this->single( $hook, $args, $first, $group );
|
||||
}
|
||||
$date = ActionScheduler::get_datetime_object( $first );
|
||||
$date = as_get_datetime_object( $first );
|
||||
$cron = CronExpression::factory( $schedule );
|
||||
$schedule = new ActionScheduler_CronSchedule( $date, $cron );
|
||||
$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
|
||||
|
@@ -166,44 +166,12 @@ class ActionScheduler_AdminView {
|
||||
|
||||
$action_title = ( 'trash' == $post->post_status ) ? $post->post_title : $action->get_hook();
|
||||
$recurrence = ( 'trash' == $post->post_status ) ? 0 : $action->get_schedule();
|
||||
$next_timestamp = get_post_time( 'U', true, $post_id );
|
||||
$next_timestamp = as_get_datetime_object( $post->post_date_gmt )->format( 'U' );
|
||||
$status = get_post_status( $post_id );
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'hook':
|
||||
|
||||
echo $action_title;
|
||||
|
||||
$actions = array();
|
||||
|
||||
if ( current_user_can( 'edit_post', $post->ID ) && ! in_array( $post->post_status, array( 'publish', 'in-progress', 'trash' ) ) ) {
|
||||
$actions['process'] = "<a title='" . esc_attr( __( 'Process the action now as if it were run as part of a queue' ) ) . "' href='" . self::get_run_action_link( $post->ID, 'process' ) . "'>" . __( 'Run', 'action-scheduler' ) . "</a>";
|
||||
}
|
||||
|
||||
if ( current_user_can( 'delete_post', $post->ID ) ) {
|
||||
if ( 'trash' == $post->post_status ) {
|
||||
$post_type_object = get_post_type_object( $post->post_type );
|
||||
$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this action from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore', 'action-scheduler' ) . "</a>";
|
||||
} elseif ( EMPTY_TRASH_DAYS ) {
|
||||
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this action to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash', 'action-scheduler' ) . "</a>";
|
||||
}
|
||||
|
||||
if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) {
|
||||
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this action permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently', 'action-scheduler' ) . "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
$action_count = count( $actions );
|
||||
$i = 0;
|
||||
|
||||
echo '<div class="row-actions">';
|
||||
foreach ( $actions as $a => $link ) {
|
||||
++$i;
|
||||
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
||||
echo "<span class='$a'>$link$sep</span>";
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
break;
|
||||
case 'status':
|
||||
if ( 'publish' == $status ) {
|
||||
@@ -228,7 +196,7 @@ class ActionScheduler_AdminView {
|
||||
}
|
||||
break;
|
||||
case 'scheduled':
|
||||
echo get_date_from_gmt( date( 'Y-m-d H:i:s', $next_timestamp ), 'Y-m-d H:i:s' );
|
||||
echo get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $next_timestamp ), 'Y-m-d H:i:s' );
|
||||
if ( gmdate( 'U' ) > $next_timestamp ) {
|
||||
printf( __( ' (%s ago)', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_timestamp ) );
|
||||
} else {
|
||||
@@ -260,8 +228,21 @@ class ActionScheduler_AdminView {
|
||||
*/
|
||||
public static function row_actions( $actions, $post ) {
|
||||
|
||||
if ( ActionScheduler_wpPostStore::POST_TYPE == $post->post_type && isset( $actions['edit'] ) ) {
|
||||
unset( $actions['edit'] );
|
||||
if ( ActionScheduler_wpPostStore::POST_TYPE == $post->post_type ) {
|
||||
|
||||
if ( isset( $actions['edit'] ) ) {
|
||||
unset( $actions['edit'] );
|
||||
}
|
||||
|
||||
if ( isset( $actions['inline hide-if-no-js'] ) ) {
|
||||
unset( $actions['inline hide-if-no-js'] );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'edit_post', $post->ID ) && ! in_array( $post->post_status, array( 'publish', 'in-progress', 'trash' ) ) ) {
|
||||
$actions['process'] = "<a title='" . esc_attr( __( 'Process the action now as if it were run as part of a queue' ) ) . "' href='" . self::get_run_action_link( $post->ID, 'process' ) . "'>" . __( 'Run', 'action-scheduler' ) . "</a>";
|
||||
}
|
||||
|
||||
ksort( $actions );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
|
@@ -20,7 +20,7 @@ class ActionScheduler_CronSchedule implements ActionScheduler_Schedule {
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function next( DateTime $after = NULL ) {
|
||||
$after = empty($after) ? clone($this->start) : clone($after);
|
||||
$after = empty($after) ? clone $this->start : clone $after;
|
||||
return $this->cron->getNextRunDate($after, 0, TRUE);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class ActionScheduler_CronSchedule implements ActionScheduler_Schedule {
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
$this->start = new DateTime('@'.$this->start_timestamp);
|
||||
$this->start = as_get_datetime_object($this->start_timestamp);
|
||||
}
|
||||
}
|
||||
|
@@ -20,12 +20,12 @@ class ActionScheduler_IntervalSchedule implements ActionScheduler_Schedule {
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function next( DateTime $after = NULL ) {
|
||||
$after = empty($after) ? new DateTime('@0') : clone($after);
|
||||
$after = empty($after) ? as_get_datetime_object('@0') : clone $after;
|
||||
if ( $after > $this->start ) {
|
||||
$after->modify('+'.$this->interval_in_seconds.' seconds');
|
||||
return $after;
|
||||
}
|
||||
return clone( $this->start );
|
||||
return clone $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ class ActionScheduler_IntervalSchedule implements ActionScheduler_Schedule {
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
$this->start = new DateTime('@'.$this->start_timestamp);
|
||||
$this->start = as_get_datetime_object($this->start_timestamp);
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ class ActionScheduler_QueueCleaner {
|
||||
|
||||
public function delete_old_actions() {
|
||||
$lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds );
|
||||
$cutoff = new DateTime($lifespan.' seconds ago');
|
||||
$cutoff = as_get_datetime_object($lifespan.' seconds ago');
|
||||
|
||||
$actions_to_delete = $this->store->query_actions( array(
|
||||
'status' => ActionScheduler_Store::STATUS_COMPLETE,
|
||||
@@ -35,7 +35,7 @@ class ActionScheduler_QueueCleaner {
|
||||
if ( $timeout < 0 ) {
|
||||
return;
|
||||
}
|
||||
$cutoff = new DateTime($timeout.' seconds ago');
|
||||
$cutoff = as_get_datetime_object($timeout.' seconds ago');
|
||||
$actions_to_reset = $this->store->query_actions( array(
|
||||
'status' => ActionScheduler_Store::STATUS_PENDING,
|
||||
'modified' => $cutoff,
|
||||
@@ -55,7 +55,7 @@ class ActionScheduler_QueueCleaner {
|
||||
if ( $timeout < 0 ) {
|
||||
return;
|
||||
}
|
||||
$cutoff = new DateTime($timeout.' seconds ago');
|
||||
$cutoff = as_get_datetime_object($timeout.' seconds ago');
|
||||
$actions_to_reset = $this->store->query_actions( array(
|
||||
'status' => ActionScheduler_Store::STATUS_RUNNING,
|
||||
'modified' => $cutoff,
|
||||
|
@@ -56,7 +56,7 @@ class ActionScheduler_QueueRunner {
|
||||
if ( $this->store->get_claim_count() < apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 5 ) ) {
|
||||
$batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 );
|
||||
$this->monitor = new ActionScheduler_FatalErrorMonitor( $this->store );
|
||||
$actions_run = $this->do_batch( $batch_size );
|
||||
$count = $this->do_batch( $batch_size );
|
||||
unset( $this->monitor );
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class ActionScheduler_QueueRunner {
|
||||
}
|
||||
|
||||
protected function schedule_next_instance( ActionScheduler_Action $action ) {
|
||||
$next = $action->get_schedule()->next( new DateTime() );
|
||||
$next = $action->get_schedule()->next( as_get_datetime_object() );
|
||||
if ( $next ) {
|
||||
$this->store->save_action( $action, $next );
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ class ActionScheduler_SimpleSchedule implements ActionScheduler_Schedule {
|
||||
private $date = NULL;
|
||||
private $timestamp = 0;
|
||||
public function __construct( DateTime $date ) {
|
||||
$this->date = clone($date);
|
||||
$this->date = clone $date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -16,8 +16,8 @@ class ActionScheduler_SimpleSchedule implements ActionScheduler_Schedule {
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function next( DateTime $after = NULL ) {
|
||||
$after = empty($after) ? new DateTime('@0') : $after;
|
||||
return ( $after > $this->date ) ? NULL : clone( $this->date );
|
||||
$after = empty($after) ? as_get_datetime_object('@0') : $after;
|
||||
return ( $after > $this->date ) ? NULL : clone $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ class ActionScheduler_SimpleSchedule implements ActionScheduler_Schedule {
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
$this->date = new DateTime('@'.$this->timestamp);
|
||||
$this->date = as_get_datetime_object($this->timestamp);
|
||||
}
|
||||
}
|
||||
|
@@ -16,19 +16,21 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
|
||||
*/
|
||||
public function log( $action_id, $message, DateTime $date = NULL ) {
|
||||
if ( empty($date) ) {
|
||||
$date = new DateTime();
|
||||
$date = as_get_datetime_object();
|
||||
} else {
|
||||
$date = clone( $date );
|
||||
$date = clone $date;
|
||||
}
|
||||
$comment_id = $this->create_wp_comment( $action_id, $message, $date );
|
||||
return $comment_id;
|
||||
}
|
||||
|
||||
protected function create_wp_comment( $action_id, $message, DateTime $date ) {
|
||||
$comment_date_gmt = $date->format('Y-m-d H:i:s');
|
||||
$date->setTimezone( ActionScheduler_TimezoneHelper::get_local_timezone() );
|
||||
$comment_data = array(
|
||||
'comment_post_ID' => $action_id,
|
||||
'comment_date' => $date->format('Y-m-d H:i:s'),
|
||||
'comment_date_gmt' => $comment_date_gmt,
|
||||
'comment_author' => self::AGENT,
|
||||
'comment_content' => $message,
|
||||
'comment_agent' => self::AGENT,
|
||||
|
@@ -176,7 +176,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
$order = 'ASC';
|
||||
break;
|
||||
}
|
||||
$query .= " ORDER BY post_date $order LIMIT 1";
|
||||
$query .= " ORDER BY post_date_gmt $order LIMIT 1";
|
||||
|
||||
$query = $wpdb->prepare( $query, $args );
|
||||
|
||||
@@ -239,20 +239,20 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
}
|
||||
|
||||
if ( $query['date'] instanceof DateTime ) {
|
||||
$date = clone( $query['date'] );
|
||||
$date->setTimezone( $this->get_local_timezone() );
|
||||
$date = clone $query['date'];
|
||||
$date->setTimezone( new DateTimeZone('UTC') );
|
||||
$date_string = $date->format('Y-m-d H:i:s');
|
||||
$comparator = $this->validate_sql_comparator($query['date_compare']);
|
||||
$sql .= " AND p.post_date $comparator %s";
|
||||
$sql .= " AND p.post_date_gmt $comparator %s";
|
||||
$sql_params[] = $date_string;
|
||||
}
|
||||
|
||||
if ( $query['modified'] instanceof DateTime ) {
|
||||
$modified = clone( $query['modified'] );
|
||||
$modified->setTimezone( $this->get_local_timezone() );
|
||||
$modified = clone $query['modified'];
|
||||
$modified->setTimezone( new DateTimeZone('UTC') );
|
||||
$date_string = $modified->format('Y-m-d H:i:s');
|
||||
$comparator = $this->validate_sql_comparator($query['modified_compare']);
|
||||
$sql .= " AND p.post_modified $comparator %s";
|
||||
$sql .= " AND p.post_modified_gmt $comparator %s";
|
||||
$sql_params[] = $date_string;
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
break;
|
||||
case 'date':
|
||||
default:
|
||||
$orderby = 'p.post_date';
|
||||
$orderby = 'p.post_date_gmt';
|
||||
break;
|
||||
}
|
||||
if ( strtoupper($query['order']) == 'ASC' ) {
|
||||
@@ -336,18 +336,28 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
* @return DateTime The date the action is schedule to run, or the date that it ran.
|
||||
*/
|
||||
public function get_date( $action_id ) {
|
||||
$date = $this->get_date_gmt( $action_id );
|
||||
return $date->setTimezone( $this->get_local_timezone() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return DateTime The date the action is schedule to run, or the date that it ran.
|
||||
*/
|
||||
public function get_date_gmt( $action_id ) {
|
||||
$post = get_post($action_id);
|
||||
if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
|
||||
throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
|
||||
}
|
||||
if ( $post->post_status == 'publish' ) {
|
||||
return new DateTime($post->post_modified, ActionScheduler_TimezoneHelper::get_local_timezone());
|
||||
return as_get_datetime_object($post->post_modified_gmt);
|
||||
} else {
|
||||
return new DateTime($post->post_date, ActionScheduler_TimezoneHelper::get_local_timezone());
|
||||
return as_get_datetime_object($post->post_date_gmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $max_actions
|
||||
* @param DateTime $before_date Jobs must be schedule before this date. Defaults to now.
|
||||
@@ -381,17 +391,17 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
/**
|
||||
* @param string $claim_id
|
||||
* @param int $limit
|
||||
* @param DateTime $before_date
|
||||
* @param DateTime $before_date Should use UTC timezone.
|
||||
* @return int The number of actions that were claimed
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function claim_actions( $claim_id, $limit, DateTime $before_date = NULL ) {
|
||||
/** @var wpdb $wpdb */
|
||||
global $wpdb;
|
||||
$date = is_null($before_date) ? new DateTime() : clone( $before_date );
|
||||
$date->setTimezone( $this->get_local_timezone() ); // using post_modified to take advantage of indexes
|
||||
// can't use $wpdb->update() because of the <= condition
|
||||
$sql = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s WHERE post_type = %s AND post_status = %s AND post_password = '' AND post_date <= %s ORDER BY menu_order ASC, post_date ASC LIMIT %d";
|
||||
|
||||
$date = is_null($before_date) ? as_get_datetime_object() : clone $before_date;
|
||||
// can't use $wpdb->update() because of the <= condition, using post_modified to take advantage of indexes
|
||||
$sql = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s WHERE post_type = %s AND post_status = %s AND post_password = '' AND post_date_gmt <= %s ORDER BY menu_order ASC, post_date_gmt ASC LIMIT %d";
|
||||
$sql = $wpdb->prepare( $sql, array( $claim_id, current_time('mysql', true), current_time('mysql'), self::POST_TYPE, 'pending', $date->format('Y-m-d H:i:s'), $limit ) );
|
||||
$rows_affected = $wpdb->query($sql);
|
||||
if ( $rows_affected === false ) {
|
||||
|
Reference in New Issue
Block a user