Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ public static function save( $args = [], $row_id = null ) {
}
}

/**
* Delete duplicate test runs by service_test_run_id from database.
*
* @return void
*/
public static function delete_duplicates() {
global $wpdb;

$test_runs_table = Test_Runs_Table::get_table_name();

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
$wpdb->query(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
"DELETE t1 FROM $test_runs_table t1 INNER JOIN $test_runs_table t2 WHERE t1.id > t2.id AND t1.service_test_run_id = t2.service_test_run_id"
);
}

/**
* Insert multiple test data
*
Expand Down
4 changes: 3 additions & 1 deletion includes/services/class-test-run-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public function create_test_run( $service_test_run_id, $data, $update = false )
if ( $test_run && ! $update ) {
return false;
}
return Test_Run::save(array_merge( $data, [
$test_run_id = Test_Run::save(array_merge( $data, [
'service_test_run_id' => $service_test_run_id,
]), $test_run->id ?? null);
Test_Run::delete_duplicates();
return $test_run_id;
}

/**
Expand Down