| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Llms_Txt\User_Interface; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 6 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 7 |
use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Remove_File_Command_Handler; |
| 8 |
use Yoast\WP\SEO\Llms_Txt\Application\File\Llms_Txt_Cron_Scheduler; |
| 9 |
|
| 10 |
/** |
| 11 |
* Trys to clean up the llms.txt file when the plugin is deactivated. |
| 12 |
*/ |
| 13 |
class Cleanup_Llms_Txt_On_Deactivation implements Integration_Interface { |
| 14 |
|
| 15 |
use No_Conditionals; |
| 16 |
|
| 17 |
/** |
| 18 |
* The command handler. |
| 19 |
* |
| 20 |
* @var Remove_File_Command_Handler |
| 21 |
*/ |
| 22 |
private $command_handler; |
| 23 |
|
| 24 |
/** |
| 25 |
* The cron scheduler. |
| 26 |
* |
| 27 |
* @var Llms_Txt_Cron_Scheduler |
| 28 |
*/ |
| 29 |
private $cron_scheduler; |
| 30 |
|
| 31 |
/** |
| 32 |
* Constructor. |
| 33 |
* |
| 34 |
* @param Remove_File_Command_Handler $command_handler The command handler. |
| 35 |
* @param Llms_Txt_Cron_Scheduler $cron_scheduler The scheduler. |
| 36 |
*/ |
| 37 |
public function __construct( |
| 38 |
Remove_File_Command_Handler $command_handler, |
| 39 |
Llms_Txt_Cron_Scheduler $cron_scheduler |
| 40 |
) { |
| 41 |
$this->command_handler = $command_handler; |
| 42 |
$this->cron_scheduler = $cron_scheduler; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Registers the unscheduling of the cron to the deactivation action. |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function register_hooks() { |
| 51 |
\add_action( 'wpseo_deactivate', [ $this, 'maybe_remove_llms_file' ] ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Call the command handler to remove the file. |
| 56 |
* |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function maybe_remove_llms_file(): void { |
| 60 |
$this->command_handler->handle(); |
| 61 |
$this->cron_scheduler->unschedule_llms_txt_population(); |
| 62 |
} |
| 63 |
} |
| 64 |
|