Skip to content

Commit

Permalink
feat(Deactivate): delete all not finished runs
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Nov 25, 2024
1 parent 57f7b10 commit 74f45b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions includes/features/class-deactivate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Vrts\Features;

use Vrts\Models\Test_Run;

class Deactivate {

/**
* Constructor.
*/
public function __construct() {
register_deactivation_hook( vrts()->get_plugin_file(), [ $this, 'deactivate' ] );
}

/**
* Deactivate plugin.
*/
public function deactivate() {
Test_Run::delete_all_not_finished();
}
}
14 changes: 14 additions & 0 deletions includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,20 @@ public static function delete( $test_id = 0 ) {
return $wpdb->delete( $test_runs_table, [ 'id' => $test_id ] );
}

/**
* Delete all not finished test runs from database.
*
* @return int
*/
public static function delete_all_not_finished() {
global $wpdb;

$test_runs_table = Test_Runs_Table::get_table_name();

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
return $wpdb->query( "DELETE FROM $test_runs_table WHERE finished_at = NULL" );
}

/**
* Convert values to correct type.
*
Expand Down

0 comments on commit 74f45b2

Please sign in to comment.