| @@ -1,20 +1,43 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Hostinger; |
| 4 | 4 | |
| 5 | +use Hostinger\Admin\PluginSettings; | |
| 6 | +use Hostinger\LlmsTxtGenerator\LlmsTxtFileHelper; | |
| 7 | +use Hostinger\LlmsTxtGenerator\LlmsTxtGenerator; | |
| 8 | +use Hostinger\LlmsTxtGenerator\LlmsTxtParser; | |
| 9 | +use Hostinger\LlmsTxtGenerator\LlmsTxtSummaryProvider; | |
| 10 | + | |
| 5 | 11 | defined( 'ABSPATH' ) || exit; |
| 6 | 12 | |
| 7 | 13 | class Activator { |
| 8 | 14 | public const INSTALLATION_OPTION_NAME = 'hts_new_installation'; |
| 9 | - /** | |
| 10 | - * @return void | |
| 11 | - */ | |
| 15 | + | |
| 12 | 16 | public static function activate(): void { |
| 13 | - $options = new DefaultOptions(); | |
| 17 | + $plugin_settings = new PluginSettings(); | |
| 18 | + | |
| 19 | + $options = new DefaultOptions( $plugin_settings ); | |
| 14 | 20 | $options->add_options(); |
| 15 | 21 | |
| 22 | + self::generate_llms_txt( $plugin_settings ); | |
| 16 | 23 | self::update_installation_state_on_activation(); |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * The generator's own self-heal on `init` only runs for a logged-in administrator, so a site | |
| 28 | + * provisioned headlessly would serve no llms.txt until someone opened wp-admin. | |
| 29 | + */ | |
| 30 | + private static function generate_llms_txt( PluginSettings $plugin_settings ): void { | |
| 31 | + $file_helper = new LlmsTxtFileHelper(); | |
| 32 | + | |
| 33 | + if ( $file_helper->llmstxt_file_exists() ) { | |
| 34 | + return; | |
| 35 | + } | |
| 36 | + | |
| 37 | + $llms_txt_parser = new LlmsTxtParser( new LlmsTxtSummaryProvider() ); | |
| 38 | + $generator = new LlmsTxtGenerator( $plugin_settings, $file_helper, $llms_txt_parser ); | |
| 39 | + $generator->generate(); | |
| 17 | 40 | } |
| 18 | 41 | |
| 19 | 42 | /** |
| 20 | 43 | * Saves installation state. |