Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/Preload/Controller/Queue.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace WP_Rocket\Engine\Preload\Controller;
4 +
5 + use ActionScheduler_Store;
6 + use WP_Rocket\Engine\Common\Queue\AbstractASQueue;
7 +
8 + class Queue extends AbstractASQueue {
9 + /**
10 + * Group from the queue.
11 + *
12 + * @var string
13 + */
14 + protected $group = 'rocket-preload';
15 +
16 +
17 + /**
18 + * Add Async load initial sitemap job.
19 + *
20 + * @return int
21 + */
22 + public function add_job_preload_job_load_initial_sitemap_async() {
23 + return $this->add_async( 'rocket_preload_job_load_initial_sitemap' );
24 + }
25 +
26 + /**
27 + * Add Async parse sitemap job with url.
28 + *
29 + * @param string $sitemap_url sitemap url.
30 + *
31 + * @return int
32 + */
33 + public function add_job_preload_job_parse_sitemap_async( string $sitemap_url ) {
34 + return $this->add_async(
35 + 'rocket_preload_job_parse_sitemap',
36 + [
37 + $sitemap_url,
38 + ]
39 + );
40 + }
41 +
42 + /**
43 + * Add Async preload url job with url.
44 + *
45 + * @param string $url url to preload.
46 + *
47 + * @return int
48 + */
49 + public function add_job_preload_job_preload_url_async( string $url ) {
50 + return $this->add_async(
51 + 'rocket_preload_job_preload_url',
52 + [
53 + $url,
54 + ]
55 + );
56 + }
57 +
58 + /**
59 + * Add a job that check if the preload is finished.
60 + *
61 + * @return int
62 + */
63 + public function add_job_preload_job_check_finished_async() {
64 +
65 + if ( $this->job_preload_job_check_finished_async_exists() ) {
66 + return 0;
67 + }
68 +
69 + return $this->schedule_single( time() + MINUTE_IN_SECONDS, 'rocket_preload_job_check_finished', [ time() ] );
70 + }
71 +
72 + /**
73 + * Check if a task job_preload_job_check_finished_async_exists already exists.
74 + *
75 + * @return bool
76 + */
77 + public function job_preload_job_check_finished_async_exists() {
78 + if ( ! did_action( 'init' ) || doing_action( 'init' ) ) {
79 + return true;
80 + }
81 +
82 + $row_found = $this->search(
83 + [
84 + 'hook' => 'rocket_preload_job_check_finished',
85 + 'status' => ActionScheduler_Store::STATUS_PENDING,
86 + ],
87 + 'ids'
88 + );
89 +
90 + return count( $row_found ) > 0;
91 + }
92 +
93 + /**
94 + * Check if some task is remaining.
95 + *
96 + * @return bool
97 + */
98 + public function has_remaining_tasks() {
99 + $parse_sitemap = $this->search(
100 + [
101 + 'hook' => 'rocket_preload_job_parse_sitemap',
102 + 'status' => ActionScheduler_Store::STATUS_PENDING,
103 + ],
104 + 'ids'
105 + );
106 + $preload_url = $this->search(
107 + [
108 + 'hook' => 'rocket_preload_job_preload_url',
109 + 'status' => ActionScheduler_Store::STATUS_PENDING,
110 + ],
111 + 'ids'
112 + );
113 +
114 + return count( $parse_sitemap ) > 0 || count( $preload_url ) > 0;
115 + }
116 +
117 + /**
118 + * Cancel pending jobs.
119 + *
120 + * @return void
121 + */
122 + public function cancel_pending_jobs() {
123 + $this->cancel_all( '' );
124 + }
125 +
126 + /**
127 + * Return pending actions inside AS scheduler queue.
128 + *
129 + * @return array
130 + */
131 + public function get_pending_preload_actions(): array {
132 + return $this->search(
133 + [
134 + 'hook' => 'rocket_preload_job_preload_url',
135 + 'status' => ActionScheduler_Store::STATUS_PENDING,
136 + 'per_page' => -1,
137 + ]
138 + );
139 + }
140 + }
141 +