/var/www/html_sp/wp-content/plugins/woocommerce/vendor/woocommerce/blueprint/src/Cli/ImportCli.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace Automattic\WooCommerce\Blueprint\Cli;

use 
Automattic\WooCommerce\Blueprint\CliResultFormatter;
use 
Automattic\WooCommerce\Blueprint\ImportSchema;

/**
 * Class ImportCli
 */
class ImportCli {
    
/**
     * Schema path
     *
     * @var string $schema_path The path to the schema file.
     */
    
private $schema_path;

    
/**
     * ImportCli constructor.
     *
     * @param string $schema_path The path to the schema file.
     */
    
public function __construct$schema_path ) {
        
$this->schema_path $schema_path;
    }

    
/**
     * Run the import process.
     *
     * @param array $optional_args Optional arguments.
     *
     * @return void
     */
    
public function run$optional_args ) {
        
$blueprint ImportSchema::create_from_file$this->schema_path );
        
$results   $blueprint->import();

        
$result_formatter = new CliResultFormatter$results );
        
$is_success       $result_formatter->is_success();

        if ( isset( 
$optional_args['show-messages'] ) ) {
            
$result_formatter->format$optional_args['show-messages'] );
        }

        if ( 
$is_success ) {
            
\WP_CLI::success"$this->schema_path imported successfully" );
        } else {
            
\WP_CLI::error"Failed to import $this->schema_path. Run with --show-messages=all to debug" );
        }
    }
}