PluginProbe
Hostinger Tools / 3.0.76
Hostinger Tools v3.0.76
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / Admin / Jobs / AbstractJob.php

AbstractJob.php in Hostinger Tools 3.0.76, at includes/Admin/Jobs/AbstractJob.php

55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare( strict_types=1 );
3
4 namespace Hostinger\Admin\Jobs;
5
6 use Exception;
7
8 defined( 'ABSPATH' ) || exit;
9
10 abstract class AbstractJob implements JobInterface {
11
12 protected ActionScheduler $action_scheduler;
13
14 public function __construct( ActionScheduler $action_scheduler ) {
15 $this->action_scheduler = $action_scheduler;
16 }
17
18 public function init(): void {
19 add_action( $this->get_process_item_hook(), array( $this, 'handle_process_items_action' ) );
20 add_action(
21 $this->get_start_hook(),
22 function ( $args ) {
23 $this->schedule( $args );
24 }
25 );
26 }
27
28 public function can_schedule( $args = array() ): bool {
29 return ! $this->is_running( $args );
30 }
31
32 public function handle_process_items_action( array $args = array() ): void {
33 $this->process_items( $args );
34 }
35
36 public function get_process_item_hook(): string {
37 return "{$this->get_hook_base_name()}process_item";
38 }
39
40 public function get_start_hook(): string {
41 return $this->get_name();
42 }
43
44 protected function is_running( ?array $args = array() ): bool {
45 return $this->action_scheduler->has_scheduled_action( $this->get_process_item_hook(), array( $args ) );
46 }
47
48 protected function get_hook_base_name(): string {
49 return "{$this->action_scheduler->get_group()}/jobs/{$this->get_name()}/";
50 }
51
52 abstract public function get_name(): string;
53 abstract protected function process_items( array $args );
54 }
55