Skip to content

Commit 31b05cb

Browse files
committed
refactor(Tests): get test alert id from test current_alert_id
1 parent 34dfa99 commit 31b05cb

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

includes/features/class-metaboxes.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ public function add_rest_actions() {
109109
*/
110110
public function render_metabox() {
111111
global $post;
112+
112113
$post_id = $post->ID ? $post->ID : 0;
113-
$run_tests_checked = ! empty( Test::get_item_id( $post_id ) );
114+
$test_id = Test::get_item_id( $post_id );
115+
$test = (object) Test::get_item( $test_id );
114116

115-
$alert_id = Test::get_alert_id( $post_id );
117+
$run_tests_checked = ! is_null( $test_id );
118+
$alert_id = $test->current_alert_id ?? null;
116119
$testing_status_instructions = '';
120+
117121
if ( $alert_id ) {
118122
$alert_link = Url_Helpers::get_alert_page( $alert_id );
119123
$testing_status_instructions .= sprintf(
@@ -124,9 +128,6 @@ public function render_metabox() {
124128
);
125129
}
126130

127-
$test_id = Test::get_item_id( $post_id );
128-
$test = (object) Test::get_item( $test_id );
129-
130131
vrts()->component('metabox-classic-editor', [
131132
'post_id' => $post_id,
132133
'nonce' => $this->nonce,
@@ -135,7 +136,7 @@ public function render_metabox() {
135136
'field_test_status_key' => self::$field_test_status_key,
136137
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
137138
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
138-
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ),
139+
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ?? null ),
139140
'testing_status_instructions' => $testing_status_instructions,
140141
'is_new_test' => self::is_new_test( $post_id ),
141142
'remaining_tests' => Subscription::get_remaining_tests(),

includes/models/class-test.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -368,28 +368,6 @@ public static function exists_for_post( $post_id = 0 ) {
368368
);
369369
}
370370

371-
/**
372-
* Get the id of the alert
373-
*
374-
* @param int $post_id the id of the post.
375-
*
376-
* @return int
377-
*/
378-
public static function get_alert_id( $post_id = 0 ) {
379-
global $wpdb;
380-
381-
$tests_table = Tests_Table::get_table_name();
382-
383-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
384-
return $wpdb->get_var(
385-
$wpdb->prepare(
386-
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
387-
"SELECT current_alert_id FROM $tests_table WHERE post_id = %d",
388-
$post_id
389-
)
390-
);
391-
}
392-
393371
/**
394372
* Get post id by test id
395373
*

0 commit comments

Comments
 (0)