44
55class JobQueue {
66
7+ public static function getTableName () : string {
8+ return Controller::getTableName ( 'jobs ' );
9+ }
10+
711 public static function createTable () : void {
812 global $ wpdb ;
913
10- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
14+ $ table_name = self :: getTableName () ;
1115
1216 $ charset_collate = $ wpdb ->get_charset_collate ();
1317
@@ -47,7 +51,7 @@ public static function addJob( string $job_type, ?int $post_id = null ) : void {
4751
4852 global $ wpdb ;
4953
50- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
54+ $ table_name = self :: getTableName () ;
5155
5256 // Add triggering_post_id column if it doesn't exist already
5357 $ triggering_post_id_row = $ wpdb ->get_row (
@@ -76,7 +80,7 @@ public static function getJobs() : array {
7680 global $ wpdb ;
7781 $ urls = [];
7882
79- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
83+ $ table_name = self :: getTableName () ;
8084
8185 $ rows = $ wpdb ->get_results ( "SELECT * FROM $ table_name ORDER BY id DESC " );
8286
@@ -96,7 +100,7 @@ public static function jobsInProgress() : bool {
96100 global $ wpdb ;
97101 $ jobs = [];
98102
99- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
103+ $ table_name = self :: getTableName () ;
100104
101105 $ jobs_in_progress = $ wpdb ->get_var (
102106 "SELECT COUNT(*) FROM $ table_name
@@ -115,7 +119,7 @@ public static function getProcessableJobs() : array {
115119 global $ wpdb ;
116120 $ jobs = [];
117121
118- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
122+ $ table_name = self :: getTableName () ;
119123
120124 $ rows = $ wpdb ->get_results (
121125 "SELECT * FROM $ table_name
@@ -139,7 +143,7 @@ public static function getJobCountByType() : array {
139143 global $ wpdb ;
140144 $ jobs = [];
141145
142- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
146+ $ table_name = self :: getTableName () ;
143147 $ query = "SELECT job_type, count(*) FROM $ table_name GROUP BY job_type " ;
144148
145149 $ rows = $ wpdb ->get_results ( $ query , 'ARRAY_N ' );
@@ -157,7 +161,7 @@ public static function getJobCountByType() : array {
157161 public static function squashQueue () : void {
158162 global $ wpdb ;
159163
160- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
164+ $ table_name = self :: getTableName () ;
161165
162166 // TODO: loop for each job_type
163167 $ job_types = [
@@ -215,7 +219,7 @@ public static function squashQueue() : void {
215219 public static function setStatus ( int $ id , string $ status ) : void {
216220 global $ wpdb ;
217221
218- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
222+ $ table_name = self :: getTableName () ;
219223
220224 $ wpdb ->update (
221225 $ table_name ,
@@ -232,7 +236,7 @@ public static function setStatus( int $id, string $status ) : void {
232236 public static function getTotalJobs () : int {
233237 global $ wpdb ;
234238
235- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
239+ $ table_name = self :: getTableName () ;
236240
237241 $ total_jobs = $ wpdb ->get_var ( "SELECT COUNT(*) FROM $ table_name " );
238242
@@ -251,7 +255,7 @@ public static function getWaitingJobs() : int {
251255 public static function getWaitingJobsCount () : int {
252256 global $ wpdb ;
253257
254- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
258+ $ table_name = self :: getTableName () ;
255259
256260 $ total_jobs = $ wpdb ->get_var ( "SELECT COUNT(*) FROM $ table_name WHERE status = 'waiting' " );
257261
@@ -266,7 +270,7 @@ public static function truncate() : void {
266270
267271 global $ wpdb ;
268272
269- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
273+ $ table_name = self :: getTableName () ;
270274
271275 $ wpdb ->query ( "TRUNCATE TABLE $ table_name " );
272276
@@ -286,13 +290,13 @@ public static function markFailedJobs() : void {
286290 global $ wpdb ;
287291
288292 $ job_types = [ 'detect ' , 'crawl ' , 'post_process ' , 'deploy ' , 'direct_deploy ' ];
289- $ table_name = $ wpdb -> prefix . ' wp2static_jobs ' ;
293+ $ table_name = self :: getTableName () ;
290294
291295 $ wpdb ->query ( 'START TRANSACTION ' );
292296
293297 foreach ( $ job_types as $ type ) {
294298 try {
295- $ lock = "{ $ wpdb -> prefix } .wp2static_jobs. $ type" ;
299+ $ lock = self :: getTableName () . ' . ' . $ type ;
296300 $ query = "SELECT IS_FREE_LOCK(' $ lock') AS free " ;
297301 $ free = intval ( $ wpdb ->get_row ( $ query )->free );
298302
0 commit comments