Create object able to clear database.

This commit is contained in:
Narek Zakarian 2022-12-08 19:24:53 +04:00
parent 374ce5d5f9
commit f0798d7e88
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
2 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,34 @@
<?php
/**
* Clears the plugin related data from DB.
*
* @package WooCommerce\PayPalCommerce\Uninstall
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Uninstall;
/**
* Class ClearDatabase
*/
class ClearDatabase implements ClearDatabaseInterface {
/**
* {@inheritDoc}
*/
public function delete_options( array $option_names ):void {
foreach ( $option_names as $option_name ) {
delete_option( $option_name );
}
}
/**
* {@inheritDoc}
*/
public function clear_scheduled_actions( array $action_names ):void {
foreach ( $action_names as $action_name ) {
as_unschedule_action( $action_name );
}
}
}

View file

@ -0,0 +1,32 @@
<?php
/**
* Can delete the options and clear scheduled actions from database.
*
* @package WooCommerce\PayPalCommerce\Uninstall
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Uninstall;
use RuntimeException;
interface ClearDatabaseInterface {
/**
* Deletes the given options from database.
*
* @param string[] $option_names The list of option names.
* @throws RuntimeException If problem deleting.
*/
public function delete_options( array $option_names ): void;
/**
* Clears the given scheduled actions.
*
* @param string[] $action_names The list of scheduled action names.
* @throws RuntimeException If problem clearing.
*/
public function clear_scheduled_actions( array $action_names ): void;
}