Skip to content

Commit

Permalink
feat(TestRuns): autodelete duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Nov 28, 2024
1 parent d317c5c commit 3aebb60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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 @@ -102,9 +102,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

0 comments on commit 3aebb60

Please sign in to comment.