Skip to content

Commit

Permalink
Fix for daylight savings and leap years when scheduling engagements (#…
Browse files Browse the repository at this point in the history
…2800)

* Use datetime vs. adding seconds to account for daylight savings and leap years.
  • Loading branch information
brianhogg authored Dec 16, 2024
1 parent 85976a0 commit b684f6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
significance: patch
type: fixed
links:
- "#2799"
entry: Fix for daylight savings and leap years when scheduling engagements.
13 changes: 1 addition & 12 deletions includes/class.llms.engagements.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ private function add_actions() {
}

add_action( 'deleted_post', array( $this, 'unschedule_delayed_engagements' ), 20, 2 );

}

/**
Expand Down Expand Up @@ -208,7 +207,6 @@ private function get_engagements( $trigger_type, $related_post_id = '' ) {
* @param int $related_post_id WP_Post ID of the related post.
*/
return apply_filters( 'lifterlms_get_engagements', $results, $trigger_type, $related_post_id );

}

/**
Expand Down Expand Up @@ -249,7 +247,6 @@ protected function get_trigger_hooks() {
* @param string[] $hooks List of hook names.
*/
return apply_filters( 'lifterlms_engagement_actions', $hooks );

}

/**
Expand Down Expand Up @@ -405,7 +402,6 @@ private function parse_hook( $action, $args ) {
$parsed['related_post_id'] = $related_post_id;

return $parsed;

}

/**
Expand Down Expand Up @@ -450,7 +446,6 @@ private function parse_hook_find_trigger_type( $action, $related_post_id ) {
}

return $trigger_type;

}

/**
Expand Down Expand Up @@ -485,7 +480,6 @@ public function maybe_trigger_engagement() {
$this->trigger_engagement( $handler, $engagement->delay );

}

}

/**
Expand Down Expand Up @@ -570,7 +564,6 @@ private function parse_engagement( $engagement, $trigger_data ) {
);

return $parsed;

}

/**
Expand All @@ -594,7 +587,7 @@ private function trigger_engagement( $data, $delay ) {
if ( $delay ) {

as_schedule_single_action(
time() + ( DAY_IN_SECONDS * $delay ),
current_datetime()->modify( "+{$delay} days" )->getTimestamp(),
$data['handler_action'],
array( $data['handler_args'] ),
! empty( $data['handler_args'][3] ) ? $this->get_delayed_group_id( $data['handler_args'][3] ) : null
Expand All @@ -616,7 +609,6 @@ private function trigger_engagement( $data, $delay ) {
remove_filter( 'llms_skip_engagement_processing_checks', '__return_true' );

}

}

/**
Expand All @@ -640,7 +632,6 @@ public function unschedule_delayed_engagements( $post_id, $post = null ) {
if ( 'llms_engagement' === $post_type ) {
as_unschedule_all_actions( '', array(), $this->get_delayed_group_id( $post_id ) );
}

}

/**
Expand All @@ -660,7 +651,5 @@ public function log( $log ) {
if ( $this->debug ) {
llms_log( $log, 'engagements' );
}

}

}

0 comments on commit b684f6b

Please sign in to comment.