Skip to content

Commit 9bd21ca

Browse files
committed
fix: treat already-disabled smilies as applied
1 parent 9fc9c8c commit 9bd21ca

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

includes/class-static-site-importer-wordpress-site-plan-materializer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ public static function materialize_prepared( array $prepared ): array {
262262
'theme_slug' => $state['theme']['slug'],
263263
);
264264
if ( ! isset( $args['disable_smilies'] ) || false !== (bool) $args['disable_smilies'] ) {
265-
if ( false === update_option( 'use_smilies', false ) ) {
266-
return self::failed_receipt( $state, 'disable_smilies_not_applied' );
265+
// update_option( 'use_smilies', false ) returns false both on failure and
266+
// when the stored value is already false, so the existing value is the oracle.
267+
if ( false !== get_option( 'use_smilies', false ) ) {
268+
if ( false === update_option( 'use_smilies', false ) ) {
269+
return self::failed_receipt( $state, 'disable_smilies_not_applied' );
270+
}
267271
}
268272
$state['applied']['runtime_policy']['disable_smilies'] = true;
269273
}

tests/smoke-wordpress-site-plan-materializer.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ function wp_safe_remote_get( string $url, array $args ) {
6464
}
6565
function wp_remote_retrieve_response_code( $response ): int { return (int) ( $response['response']['code'] ?? 0 ); }
6666
function wp_remote_retrieve_body( $response ): string { return (string) ( $response['body'] ?? '' ); }
67-
function update_option( string $key, $value ): bool { $GLOBALS['ssi_plan_options'][ $key ] = $value; return true; }
67+
function get_option( string $key, mixed $default = false ): mixed { return $GLOBALS['ssi_plan_options'][ $key ] ?? $default; }
68+
function update_option( string $key, $value ): bool {
69+
if ( array_key_exists( $key, $GLOBALS['ssi_plan_options'] ) && $GLOBALS['ssi_plan_options'][ $key ] === $value ) {
70+
return false; // Core semantics: unchanged value writes no row and returns false.
71+
}
72+
$GLOBALS['ssi_plan_options'][ $key ] = $value;
73+
return true;
74+
}
6875
function switch_theme( string $slug ): void { $GLOBALS['ssi_plan_options']['stylesheet'] = $slug; }
6976
function convert_smilies( string $content, string $which = 'content' ): string { return ( $GLOBALS['ssi_plan_options']['use_smilies'] ?? true ) ? 'smilied-' . $which : $content; }
7077
function sanitize_text_field( string $value ): string { return $value; }
@@ -438,6 +445,13 @@ function wp_insert_post( array $post, bool $wp_error ) {
438445
$assert( true === $GLOBALS['ssi_plan_options']['use_smilies'], 'activate-with-disable-smilies-false-keeps-smilies' );
439446
$assert( false === ( $activated_off['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ) && false === ( $activated_off['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'disable-smilies-false-not-applied-on-activate' );
440447

448+
// Repeated activating import: use_smilies already false, update_option returns false (unchanged value).
449+
$GLOBALS['ssi_plan_options']['use_smilies'] = false;
450+
$receipt_repeat_policy = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true, 'activate' => true, 'site_title' => 'Repeat Policy' ) );
451+
$assert( 'completed' === $receipt_repeat_policy['status'], 'repeated-activating-import-completes' );
452+
$assert( true === ( $receipt_repeat_policy['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ) && true === ( $receipt_repeat_policy['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'repeated-activating-import-records-requested-and-applied' );
453+
$assert( false === $GLOBALS['ssi_plan_options']['use_smilies'], 'repeated-activating-import-keeps-use-smilies-false' );
454+
441455
$repeat = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan' ) );
442456
$assert( 'completed' === $repeat['status'], 'reconciliation repeat completes' );
443457
$assert( count( $GLOBALS['ssi_plan_posts'] ) === count( $plan['pages'] ), 'reconciliation preserves source page identity' );

0 commit comments

Comments
 (0)