schemas
1 year ago
ActivatePlugin.php
1 year ago
ActivateTheme.php
1 year ago
InstallPlugin.php
1 year ago
InstallTheme.php
1 year ago
RunSql.php
1 year ago
SetSiteOptions.php
1 year ago
Step.php
1 year ago
RunSql.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint\Steps; |
| 4 | |
| 5 | /** |
| 6 | * Class RunSql |
| 7 | * |
| 8 | * @package Automattic\WooCommerce\Blueprint\Steps |
| 9 | */ |
| 10 | class RunSql extends Step { |
| 11 | /** |
| 12 | * Sql code to run. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected string $sql = ''; |
| 17 | |
| 18 | /** |
| 19 | * Name of the sql file. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected string $name = 'schema.sql'; |
| 24 | |
| 25 | /** |
| 26 | * Constructor. |
| 27 | * |
| 28 | * @param string $sql Sql code to run. |
| 29 | * @param string $name Name of the sql file. |
| 30 | */ |
| 31 | public function __construct( string $sql, $name = 'schema.sql' ) { |
| 32 | $this->sql = $sql; |
| 33 | $this->name = $name; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the name of this step. |
| 38 | * |
| 39 | * @return string The step name. |
| 40 | */ |
| 41 | public static function get_step_name(): string { |
| 42 | return 'runSql'; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the schema for the JSON representation of this step. |
| 47 | * |
| 48 | * @param int $version The version of the schema to return. |
| 49 | * @return array The schema array. |
| 50 | */ |
| 51 | public static function get_schema( int $version = 1 ): array { |
| 52 | return array( |
| 53 | 'type' => 'object', |
| 54 | 'properties' => array( |
| 55 | 'step' => array( |
| 56 | 'type' => 'string', |
| 57 | 'enum' => array( static::get_step_name() ), |
| 58 | ), |
| 59 | 'sql' => array( |
| 60 | 'type' => 'object', |
| 61 | 'required' => array( 'contents', 'resource', 'name' ), |
| 62 | 'properties' => array( |
| 63 | 'resource' => array( |
| 64 | 'type' => 'string', |
| 65 | 'enum' => array( 'literal' ), |
| 66 | ), |
| 67 | 'name' => array( |
| 68 | 'type' => 'string', |
| 69 | ), |
| 70 | 'contents' => array( |
| 71 | 'type' => 'string', |
| 72 | ), |
| 73 | ), |
| 74 | ), |
| 75 | ), |
| 76 | 'required' => array( 'step', 'sql' ), |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Prepares an associative array for JSON encoding. |
| 82 | * |
| 83 | * @return array Array of data to be encoded as JSON. |
| 84 | */ |
| 85 | public function prepare_json_array(): array { |
| 86 | return array( |
| 87 | 'step' => static::get_step_name(), |
| 88 | 'sql' => array( |
| 89 | 'resource' => 'literal', |
| 90 | 'name' => $this->name, |
| 91 | 'contents' => $this->sql, |
| 92 | ), |
| 93 | ); |
| 94 | } |
| 95 | } |
| 96 |