/var/www/html_de/wp-content/plugins/woocommerce/packages/blueprint/src/Steps/RunSql.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

namespace Automattic\WooCommerce\Blueprint\Steps;

/**
 * Class RunSql
 *
 * @package Automattic\WooCommerce\Blueprint\Steps
 */
class RunSql extends Step {
    
/**
     * Sql code to run.
     *
     * @var string
     */
    
protected string $sql '';

    
/**
     * Name of the sql file.
     *
     * @var string
     */
    
protected string $name 'schema.sql';

    
/**
     * Constructor.
     *
     * @param string $sql Sql code to run.
     * @param string $name Name of the sql file.
     */
    
public function __constructstring $sql$name 'schema.sql' ) {
        
$this->sql  $sql;
        
$this->name $name;
    }

    
/**
     * Returns the name of this step.
     *
     * @return string The step name.
     */
    
public static function get_step_name(): string {
        return 
'runSql';
    }

    
/**
     * Returns the schema for the JSON representation of this step.
     *
     * @param int $version The version of the schema to return.
     * @return array The schema array.
     */
    
public static function get_schemaint $version ): array {
        return array(
            
'type'       => 'object',
            
'properties' => array(
                
'step' => array(
                    
'type' => 'string',
                    
'enum' => array( static::get_step_name() ),
                ),
                
'sql'  => array(
                    
'type'       => 'object',
                    
'required'   => array( 'contents''resource''name' ),
                    
'properties' => array(
                        
'resource' => array(
                            
'type' => 'string',
                            
'enum' => array( 'literal' ),
                        ),
                        
'name'     => array(
                            
'type' => 'string',
                        ),
                        
'contents' => array(
                            
'type' => 'string',
                        ),
                    ),
                ),
            ),
            
'required'   => array( 'step''sql' ),
        );
    }

    
/**
     * Prepares an associative array for JSON encoding.
     *
     * @return array Array of data to be encoded as JSON.
     */
    
public function prepare_json_array(): array {
        return array(
            
'step' => static::get_step_name(),
            
'sql'  => array(
                
'resource' => 'literal',
                
'name'     => $this->name,
                
'contents' => $this->sql,
            ),
        );
    }
}