@@ -114,28 +114,36 @@ public static function validate_artifact( array $input ) {
114114
115115 /** Prepare plugin dependencies in this request; callers resume validation in another request. */
116116 public static function prepare_artifact_dependencies ( array $ input ) {
117- $ input ['runtime_lifecycle_phase ' ] = 'prepare ' ;
117+ $ input ['runtime_lifecycle_phase ' ] = 'prepare ' ;
118118 $ input ['materialize_dependencies ' ] = true ;
119- $ artifact = isset ( $ input ['artifact ' ] ) && is_array ( $ input ['artifact ' ] ) ? $ input ['artifact ' ] : array ();
119+ $ artifact = isset ( $ input ['artifact ' ] ) && is_array ( $ input ['artifact ' ] ) ? $ input ['artifact ' ] : array ();
120120 if ( empty ( $ artifact ) ) {
121121 return new WP_Error ( 'static_site_importer_validation_artifact_missing ' , 'Dependency preparation requires an artifact JSON object. ' );
122122 }
123- $ slug = isset ( $ input ['slug ' ] ) ? sanitize_title ( (string ) $ input ['slug ' ] ) : 'static-site-importer-validation ' ;
124- $ input ['slug ' ] = '' === $ slug ? 'static-site-importer-validation ' : $ slug ;
125- $ input ['name ' ] = isset ( $ input ['name ' ] ) ? sanitize_text_field ( (string ) $ input ['name ' ] ) : $ input ['slug ' ];
126- $ import_args = Static_Site_Importer_Website_Artifact_Import_Input::normalize ( $ input , array ( 'activate ' => true , 'overwrite ' => true , 'materialize_dependencies ' => true ) );
123+ $ slug = isset ( $ input ['slug ' ] ) ? sanitize_title ( (string ) $ input ['slug ' ] ) : 'static-site-importer-validation ' ;
124+ $ input ['slug ' ] = '' === $ slug ? 'static-site-importer-validation ' : $ slug ;
125+ $ input ['name ' ] = isset ( $ input ['name ' ] ) ? sanitize_text_field ( (string ) $ input ['name ' ] ) : $ input ['slug ' ];
126+ $ import_args = Static_Site_Importer_Website_Artifact_Import_Input::normalize (
127+ $ input ,
128+ array (
129+ 'activate ' => true ,
130+ 'overwrite ' => true ,
131+ 'materialize_dependencies ' => true ,
132+ )
133+ );
127134 $ import_args ['runtime_lifecycle_phase ' ] = 'prepare ' ;
128- $ result = Static_Site_Importer_Theme_Generator::import_website_artifact ( $ artifact , $ import_args );
135+ $ result = Static_Site_Importer_Theme_Generator::import_website_artifact ( $ artifact , $ import_args );
129136 if ( is_wp_error ( $ result ) ) {
130137 return $ result ;
131138 }
139+ $ encoded_artifact = wp_json_encode ( $ artifact );
132140 return array (
133- 'schema ' => 'static-site-importer/runtime-lifecycle-receipt/v1 ' ,
134- 'status ' => (string ) ( $ result ['status ' ] ?? 'failed ' ),
135- 'artifact_sha256 ' => hash ( 'sha256 ' , wp_json_encode ( $ artifact ) ? : '' ),
136- 'slug ' => $ input ['slug ' ],
137- 'fresh_runtime ' => $ result ['fresh_runtime ' ] ?? array (),
138- 'dependencies ' => $ result ['dependencies ' ] ?? array (),
141+ 'schema ' => 'static-site-importer/runtime-lifecycle-receipt/v1 ' ,
142+ 'status ' => (string ) ( $ result ['status ' ] ?? 'failed ' ),
143+ 'artifact_sha256 ' => hash ( 'sha256 ' , false !== $ encoded_artifact ? $ encoded_artifact : '' ),
144+ 'slug ' => $ input ['slug ' ],
145+ 'fresh_runtime ' => $ result ['fresh_runtime ' ] ?? array (),
146+ 'dependencies ' => $ result ['dependencies ' ] ?? array (),
139147 'runtime_lifecycle ' => $ result ['runtime_lifecycle ' ] ?? array (),
140148 );
141149 }
@@ -146,12 +154,20 @@ public static function plan_artifact_dependencies( array $input ) {
146154 if ( empty ( $ artifact ) ) {
147155 return new WP_Error ( 'static_site_importer_validation_artifact_missing ' , 'Dependency planning requires an artifact JSON object. ' );
148156 }
149- $ input ['runtime_lifecycle_phase ' ] = 'plan ' ;
157+ $ input ['runtime_lifecycle_phase ' ] = 'plan ' ;
150158 $ input ['materialize_dependencies ' ] = false ;
151- $ input ['slug ' ] = sanitize_title ( (string ) ( $ input ['slug ' ] ?? 'static-site-importer-validation ' ) ) ?: 'static-site-importer-validation ' ;
152- $ input ['name ' ] = isset ( $ input ['name ' ] ) ? sanitize_text_field ( (string ) $ input ['name ' ] ) : $ input ['slug ' ];
153- $ args = Static_Site_Importer_Website_Artifact_Import_Input::normalize ( $ input , array ( 'activate ' => true , 'overwrite ' => true , 'materialize_dependencies ' => false ) );
154- $ args ['runtime_lifecycle_phase ' ] = 'plan ' ;
159+ $ slug = sanitize_title ( (string ) ( $ input ['slug ' ] ?? 'static-site-importer-validation ' ) );
160+ $ input ['slug ' ] = '' !== $ slug ? $ slug : 'static-site-importer-validation ' ;
161+ $ input ['name ' ] = isset ( $ input ['name ' ] ) ? sanitize_text_field ( (string ) $ input ['name ' ] ) : $ input ['slug ' ];
162+ $ args = Static_Site_Importer_Website_Artifact_Import_Input::normalize (
163+ $ input ,
164+ array (
165+ 'activate ' => true ,
166+ 'overwrite ' => true ,
167+ 'materialize_dependencies ' => false ,
168+ )
169+ );
170+ $ args ['runtime_lifecycle_phase ' ] = 'plan ' ;
155171 return Static_Site_Importer_Theme_Generator::import_website_artifact ( $ artifact , $ args );
156172 }
157173
0 commit comments