Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Marketplace_Theme_Installer
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 1
 install
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
72
1<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2/**
3 * Class that allows to install a marketplace theme.
4 *
5 * @since 5.5.0
6 * @package WPCOM_Marketplace
7 */
8
9/**
10 * Class that allows to install a marketplace theme by generating and running the installation commands.
11 */
12class Marketplace_Theme_Installer extends Marketplace_Product_Installer {
13
14    /**
15     * Install the theme.
16     *
17     * @return WP_Error|bool
18     */
19    public function install() {
20        if ( ! $this->product_software instanceof Marketplace_Theme_Software ) {
21            return new WP_Error( 'invalid_product_software', 'Invalid product software.' );
22        }
23
24        // 1. Install the theme dependencies.
25        $install_dependencies = $this->install_dependencies();
26        if ( is_wp_error( $install_dependencies ) ) {
27            return $install_dependencies;
28        }
29
30        // 2. Get the list of plugins to skip when installing the theme.
31        $skip_plugins = $this->get_skip_plugins();
32        if ( is_wp_error( $skip_plugins ) ) {
33            return $skip_plugins;
34        }
35
36        // 3. Get the list of themes to skip when installing the theme.
37        $skip_themes = $this->get_skip_themes();
38        if ( is_wp_error( $skip_themes ) ) {
39            return $skip_themes;
40        }
41
42        // 4. Generate and run the theme installation command.
43        $theme_install_command = $this->command_helper->generate_theme_install_command(
44            $this->product_software->get_theme_slug(),
45            $this->product_software->is_managed(),
46            $skip_plugins,
47            $skip_themes
48        );
49
50        $theme_install = $this->run_command( $theme_install_command );
51        if ( is_wp_error( $theme_install ) ) {
52            return $theme_install;
53        }
54
55        // 5. Verify the theme installation.
56        $verify_theme_installation_command = $this->command_helper->generate_verify_theme_installation_command( $this->product_software->get_theme_slug() );
57        $verify_theme_installation         = $this->run_command( $verify_theme_installation_command );
58        if ( is_wp_error( $verify_theme_installation ) ) {
59            return $verify_theme_installation;
60        }
61
62        if ( $verify_theme_installation->stdout !== 'active' ) {
63            return new WP_Error(
64                'theme_installation_failed',
65                'Theme installation failed.'
66            );
67        }
68
69        return true;
70    }
71}