Skip to content

Commit

Permalink
Check notification status when scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
puntope committed Feb 12, 2024
1 parent 72f00f8 commit 34e1329
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
31 changes: 20 additions & 11 deletions src/Jobs/Notifications/ProductNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,7 @@ protected function process_items( array $args ): void {
* @param array $args
*/
public function schedule( array $args = [] ): void {
/**
* Allow users to disable the notification job schedule.
*
* @since x.x.x
*
* @param bool $value The current filter value. By default, it is the result of `$this->can_schedule` function.
* @param array $args The arguments for the schedule function with the item id and the topic.
*/
$can_schedule = apply_filters( 'woocommerce_gla_product_notification_job_can_schedule', $this->can_schedule( [ $args ] ), $args );

if ( $can_schedule ) {
if ( $this->can_schedule( $args ) ) {
$this->action_scheduler->schedule_immediate(
$this->get_process_item_hook(),
[ $args ]
Expand Down Expand Up @@ -150,4 +140,23 @@ protected function can_process( int $product_id, string $topic ): bool {
return $this->product_helper->should_trigger_update_notification( $product );
}
}

/**
* Can the job be scheduled.
*
* @param array|null $args
*
* @return bool Returns true if the job can be scheduled.
*/
public function can_schedule( $args = [] ): bool {
/**
* Allow users to disable the notification job schedule.
*
* @since x.x.x
*
* @param bool $value The current filter value. By default, it is the result of `$this->can_schedule` function.
* @param array $args The arguments for the schedule function with the item id and the topic.
*/
return apply_filters( 'woocommerce_gla_product_notification_job_can_schedule', $this->notifications_service->is_enabled() && parent::can_schedule( $args ), $args );
}
}
27 changes: 18 additions & 9 deletions src/Jobs/Notifications/ShippingNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,30 @@ protected function process_items( array $args ): void {
* @param array $args
*/
public function schedule( array $args = [] ): void {
if ( $this->can_schedule( $args ) ) {
$this->action_scheduler->schedule_immediate(
$this->get_process_item_hook(),
[ $args ]
);
}
}

/**
* Can the job be scheduled.
*
* @param array|null $args
*
* @return bool Returns true if the job can be scheduled.
*/
public function can_schedule( $args = [] ): bool {
/**
* Allow users to disable the notification job schedule.
*
* @since x.x.x
*
* @param bool $value The current filter value. By default, it is the result of `$this->can_schedule` function.
* @param array $args The arguments for the schedule function.
* @param array $args The arguments for the schedule function with the item id and the topic.
*/
$can_schedule = apply_filters( 'woocommerce_gla_shipping_notification_job_can_schedule', $this->can_schedule( [ $args ] ), $args );

if ( $can_schedule ) {
$this->action_scheduler->schedule_immediate(
$this->get_process_item_hook(),
[ $args ]
);
}
return apply_filters( 'woocommerce_gla_shipping_notification_job_can_schedule', $this->notifications_service->is_enabled() && parent::can_schedule( $args ), $args );
}
}

0 comments on commit 34e1329

Please sign in to comment.