Skip to content

Commit 34dfa99

Browse files
committed
refactor(Tests): check if alert exists directly from test current_alert_id
1 parent bbfc502 commit 34dfa99

File tree

3 files changed

+4
-27
lines changed

3 files changed

+4
-27
lines changed

includes/features/class-enqueue-scripts.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ public function enqueue_block_editor_assets() {
100100
wp_enqueue_script( 'vrts-editor' );
101101

102102
// Localize scripts.
103-
$test = (object) Test::get_item_by_post_id( $post->ID );
103+
$test_id = Test::get_item_id( $post->ID );
104+
$test = (object) Test::get_item( $test_id );
104105

105106
wp_localize_script(
106107
'vrts-editor',
107108
'vrts_editor_vars',
108109
[
109110
'plugin_name' => vrts()->get_plugin_info( 'name' ),
110111
'rest_url' => esc_url_raw( rest_url() ),
111-
'has_post_alert' => Test::has_post_alert( $post->ID ),
112+
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
112113
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
113114
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ?? null ),
114115
'remaining_tests' => Subscription::get_remaining_tests(),

includes/features/class-metaboxes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function render_metabox() {
133133
'plugin_url' => Url_Helpers::get_page_url( 'tests' ),
134134
'run_tests_checked' => $run_tests_checked,
135135
'field_test_status_key' => self::$field_test_status_key,
136-
'has_post_alert' => Test::has_post_alert( $post_id ),
136+
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
137137
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
138138
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ),
139139
'testing_status_instructions' => $testing_status_instructions,

includes/models/class-test.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -458,30 +458,6 @@ public static function get_service_test_id_by_post_id( $post_id = 0 ) {
458458
return $service_test_id;
459459
}
460460

461-
/**
462-
* Does an alert exits?
463-
*
464-
* @param int $post_id the id of the post.
465-
*
466-
* @return boolean
467-
*/
468-
public static function has_post_alert( $post_id = 0 ) {
469-
global $wpdb;
470-
471-
$tests_table = Tests_Table::get_table_name();
472-
473-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
474-
$current_alert_id = $wpdb->get_var(
475-
$wpdb->prepare(
476-
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
477-
"SELECT current_alert_id FROM $tests_table WHERE post_id = %d",
478-
$post_id
479-
)
480-
);
481-
482-
return null === $current_alert_id ? false : true;
483-
}
484-
485461
/**
486462
* Get total test items from database
487463
*

0 commit comments

Comments
 (0)