/var/www/html_de/wp-content/plugins/woocommerce/packages/blueprint/src/Cli/ExportCli.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
53
54
55
56
57
58
59
60
<?php

namespace Automattic\WooCommerce\Blueprint\Cli;

use 
Automattic\WooCommerce\Blueprint\ExportSchema;
use 
Automattic\WooCommerce\Blueprint\UseWPFunctions;

/**
 * Class ExportCli
 *
 * This class handles the CLI commands for exporting schemas.
 *
 * @package Automattic\WooCommerce\Blueprint\Cli
 */
class ExportCli {
    use 
UseWPFunctions;

    
/**
     * The path where the exported schema will be saved.
     *
     * @var string The path where the exported schema will be saved.
     */
    
private string $save_to;

    
/**
     * ExportCli constructor.
     *
     * @param string $save_to The path where the exported schema will be saved.
     */
    
public function __construct$save_to ) {
        
$this->save_to $save_to;
    }

    
/**
     * Run the export process.
     *
     * @param array $args The arguments for the export process.
     */
    
public function run$args = array() ) {
        if ( ! isset( 
$args['steps'] ) ) {
            
$args['steps'] = array();
        }

        
$exporter = new ExportSchema();

        
$result $exporter->export$args['steps'] );
        if ( 
is_wp_error$result ) ) {
            
\WP_CLI::error$result->get_error_message() );
            return;
        }

        
$is_saved $this->wp_filesystem_put_contents$this->save_towp_json_encode$resultJSON_PRETTY_PRINT ) );

        if ( 
false === $is_saved ) {
            
\WP_CLI::error"Failed to save to {$this->save_to});
        } else {
            
\WP_CLI::success"Exported JSON to {$this->save_to});
        }
    }
}