Skip to content

Commit c718eae

Browse files
committed
Preserve pending upload refresh during legacy state migration
1 parent 603aba0 commit c718eae

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎includes/class-spacefast-static-publisher.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function step(
3333
$state = get_option( self::OPTION, array() );
3434
$state = is_array( $state ) ? $state : array();
3535
if ( array_key_exists( 'upload', $state ) ) {
36-
self::save_upload( $state );
36+
self::save_upload( $state, ! empty( $state['resume_pending'] ) );
3737
} else {
3838
$state['upload'] = get_option( self::UPLOAD_OPTION, null );
3939
}
@@ -196,13 +196,13 @@ public static function reset(): void {
196196
delete_option( self::UPLOAD_OPTION );
197197
}
198198

199-
private static function save_upload( array &$state ): void {
199+
private static function save_upload( array &$state, bool $resume_pending = false ): void {
200200
// A crash between the receipt and cursor writes must refresh the page,
201201
// never apply the previous page's cursor to the replacement targets.
202202
$state['resume_pending'] = true;
203203
self::save_state( $state );
204204
self::save_option( self::UPLOAD_OPTION, $state['upload'] );
205-
$state['resume_pending'] = false;
205+
$state['resume_pending'] = $resume_pending;
206206
self::save_state( $state );
207207
}
208208

‎tests/behavior.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,12 @@ static function ( string $url ) use ( &$large_uploaded ): array {
10931093
$GLOBALS['spacefast_blocked_options'] = array();
10941094
Spacefast_Static_Publisher::reset();
10951095
check( null === get_option( Spacefast_Static_Publisher::UPLOAD_OPTION, null ), 'reset removes the separate upload page' );
1096+
$legacy_state['resume_pending'] = true;
1097+
update_option( Spacefast_Static_Publisher::OPTION, $legacy_state );
1098+
$uploads_before_migration = count( $large_uploaded );
1099+
$migrated_pending = Spacefast_Static_Publisher::step( $archive, $large_client );
1100+
check( $uploads_before_migration === count( $large_uploaded ) && 'finalizing' === $migrated_pending['status'], 'legacy migration preserves a pending refresh instead of sending expired targets' );
1101+
Spacefast_Static_Publisher::reset();
10961102
$GLOBALS['spacefast_blocked_options'][ Spacefast_Static_Publisher::UPLOAD_OPTION ] = true;
10971103
$uploads_before_block = count( $large_uploaded );
10981104
try {

0 commit comments

Comments
 (0)