Skip to content

Commit

Permalink
refactor(Tests): get test alert id from test current_alert_id
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Nov 28, 2024
1 parent 34dfa99 commit 31b05cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
13 changes: 7 additions & 6 deletions includes/features/class-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ public function add_rest_actions() {
*/
public function render_metabox() {
global $post;

$post_id = $post->ID ? $post->ID : 0;
$run_tests_checked = ! empty( Test::get_item_id( $post_id ) );
$test_id = Test::get_item_id( $post_id );
$test = (object) Test::get_item( $test_id );

$alert_id = Test::get_alert_id( $post_id );
$run_tests_checked = ! is_null( $test_id );
$alert_id = $test->current_alert_id ?? null;
$testing_status_instructions = '';

if ( $alert_id ) {
$alert_link = Url_Helpers::get_alert_page( $alert_id );
$testing_status_instructions .= sprintf(
Expand All @@ -124,9 +128,6 @@ public function render_metabox() {
);
}

$test_id = Test::get_item_id( $post_id );
$test = (object) Test::get_item( $test_id );

vrts()->component('metabox-classic-editor', [
'post_id' => $post_id,
'nonce' => $this->nonce,
Expand All @@ -135,7 +136,7 @@ public function render_metabox() {
'field_test_status_key' => self::$field_test_status_key,
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ),
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ?? null ),
'testing_status_instructions' => $testing_status_instructions,
'is_new_test' => self::is_new_test( $post_id ),
'remaining_tests' => Subscription::get_remaining_tests(),
Expand Down
22 changes: 0 additions & 22 deletions includes/models/class-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,28 +368,6 @@ public static function exists_for_post( $post_id = 0 ) {
);
}

/**
* Get the id of the alert
*
* @param int $post_id the id of the post.
*
* @return int
*/
public static function get_alert_id( $post_id = 0 ) {
global $wpdb;

$tests_table = Tests_Table::get_table_name();

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
return $wpdb->get_var(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
"SELECT current_alert_id FROM $tests_table WHERE post_id = %d",
$post_id
)
);
}

/**
* Get post id by test id
*
Expand Down

0 comments on commit 31b05cb

Please sign in to comment.