Skip to content

Commit 74f45b2

Browse files
committed
feat(Deactivate): delete all not finished runs
1 parent 57f7b10 commit 74f45b2

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Vrts\Features;
4+
5+
use Vrts\Models\Test_Run;
6+
7+
class Deactivate {
8+
9+
/**
10+
* Constructor.
11+
*/
12+
public function __construct() {
13+
register_deactivation_hook( vrts()->get_plugin_file(), [ $this, 'deactivate' ] );
14+
}
15+
16+
/**
17+
* Deactivate plugin.
18+
*/
19+
public function deactivate() {
20+
Test_Run::delete_all_not_finished();
21+
}
22+
}

includes/models/class-test-run.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ public static function delete( $test_id = 0 ) {
409409
return $wpdb->delete( $test_runs_table, [ 'id' => $test_id ] );
410410
}
411411

412+
/**
413+
* Delete all not finished test runs from database.
414+
*
415+
* @return int
416+
*/
417+
public static function delete_all_not_finished() {
418+
global $wpdb;
419+
420+
$test_runs_table = Test_Runs_Table::get_table_name();
421+
422+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
423+
return $wpdb->query( "DELETE FROM $test_runs_table WHERE finished_at = NULL" );
424+
}
425+
412426
/**
413427
* Convert values to correct type.
414428
*

0 commit comments

Comments
 (0)