Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AppService | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| start | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| complete | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Onboarding\Services; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\Onboarding\Data\Events; |
| 6 | use NewfoldLabs\WP\Module\Onboarding\Data\Options; |
| 7 | use NewfoldLabs\WP\Module\Onboarding\Data\Services\PreviewsService; |
| 8 | use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService; |
| 9 | |
| 10 | |
| 11 | use function NewfoldLabs\WP\ModuleLoader\container; |
| 12 | |
| 13 | class AppService { |
| 14 | |
| 15 | /** |
| 16 | * App Service constructor. |
| 17 | * |
| 18 | * @return AppService |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | return $this; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Initialize the App Service. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function start(): void { |
| 30 | // Disable SSO redirect. |
| 31 | update_option( Options::get_option_name( 'redirect' ), '0' ); |
| 32 | // If Onboarding is running for the first time... |
| 33 | if ( StatusService::handle_started() ) { |
| 34 | // Trash sample page. |
| 35 | LegacySiteGenService::trash_sample_page(); |
| 36 | |
| 37 | // Initialize services. |
| 38 | SettingsService::initialize(); |
| 39 | PluginService::initialize(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Complete onboarding. |
| 45 | * |
| 46 | * @param string $selected_sitegen_homepage The selected sitegen homepage to publish. |
| 47 | * @return void |
| 48 | * @throws \Exception |
| 49 | */ |
| 50 | public function complete( string $selected_sitegen_homepage ): void { |
| 51 | // Publish selected homepage. |
| 52 | $result = ( new SiteGenService() )->publish_homepage( $selected_sitegen_homepage ); |
| 53 | if ( \is_wp_error( $result ) ) { |
| 54 | throw new \Exception( $result->get_error_message() ); |
| 55 | } |
| 56 | // Trash Preview pages. |
| 57 | PreviewsService::trash_preview_pages(); |
| 58 | |
| 59 | // Mark onboarding as completed. |
| 60 | StatusService::handle_completed(); |
| 61 | |
| 62 | // Purge all caches. |
| 63 | container()->get( 'cachePurger' )->purge_all(); |
| 64 | |
| 65 | // Create a survey to collect feedback. |
| 66 | container()->get( 'survey' )->create_toast_survey( |
| 67 | Events::get_category()[0] . '_sitegen_pulse', |
| 68 | 'customer_satisfaction_survey', |
| 69 | array( |
| 70 | 'label_key' => 'value', |
| 71 | ), |
| 72 | __( 'Help us improve', 'wp-module-onboarding-data' ), |
| 73 | __( 'How satisfied were you with the ease of creating your website?', 'wp-module-onboarding-data' ), |
| 74 | ); |
| 75 | } |
| 76 | } |