| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded |
| 4 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 5 |
namespace Yoast\WP\SEO\Llms_Txt\Application\File\Commands; |
| 6 |
|
| 7 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 8 |
use Yoast\WP\SEO\Llms_Txt\Infrastructure\File\WordPress_File_System_Adapter; |
| 9 |
use Yoast\WP\SEO\Llms_Txt\Infrastructure\File\WordPress_Llms_Txt_Permission_Gate; |
| 10 |
|
| 11 |
/** |
| 12 |
* Handles the removal of the llms.txt |
| 13 |
*/ |
| 14 |
class Remove_File_Command_Handler { |
| 15 |
|
| 16 |
/** |
| 17 |
* The options helper. |
| 18 |
* |
| 19 |
* @var Options_Helper |
| 20 |
*/ |
| 21 |
private $options_helper; |
| 22 |
|
| 23 |
/** |
| 24 |
* The file system adapter. |
| 25 |
* |
| 26 |
* @var WordPress_File_System_Adapter |
| 27 |
*/ |
| 28 |
private $file_system_adapter; |
| 29 |
|
| 30 |
/** |
| 31 |
* The permission gate. |
| 32 |
* |
| 33 |
* @var WordPress_Llms_Txt_Permission_Gate $permission_gate |
| 34 |
*/ |
| 35 |
private $permission_gate; |
| 36 |
|
| 37 |
/** |
| 38 |
* Constructor. |
| 39 |
* |
| 40 |
* @param Options_Helper $options_helper The options helper. |
| 41 |
* @param WordPress_File_System_Adapter $file_system_adapter The file system adapter. |
| 42 |
* @param WordPress_Llms_Txt_Permission_Gate $permission_gate The permission gate. |
| 43 |
*/ |
| 44 |
public function __construct( |
| 45 |
Options_Helper $options_helper, |
| 46 |
WordPress_File_System_Adapter $file_system_adapter, |
| 47 |
WordPress_Llms_Txt_Permission_Gate $permission_gate |
| 48 |
) { |
| 49 |
$this->options_helper = $options_helper; |
| 50 |
$this->file_system_adapter = $file_system_adapter; |
| 51 |
$this->permission_gate = $permission_gate; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Runs the command. |
| 56 |
* |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function handle() { |
| 60 |
if ( $this->permission_gate->is_managed_by_yoast_seo() ) { |
| 61 |
$file_removed = $this->file_system_adapter->remove_file(); |
| 62 |
|
| 63 |
if ( $file_removed ) { |
| 64 |
// Maybe move this to a class if we need to handle this option more often. |
| 65 |
\update_option( Populate_File_Command_Handler::CONTENT_HASH_OPTION, '' ); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|