Skip to content

Commit 25c571e

Browse files
peterwilsonccchriszarate
andcommitted
Restore things not related to direct DB calls
Co-Authored-By: chriszarate <czarate@git.wordpress.org>
1 parent f7e25c2 commit 25c571e

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WP_Sync_Post_Meta_Storage implements WP_Sync_Storage {
3838
* @since 7.0.0
3939
* @var string
4040
*/
41-
const SYNC_UPDATE_META_KEY = 'wp_sync_update';
41+
const SYNC_UPDATE_META_KEY = 'wp_sync_update_data';
4242

4343
/**
4444
* Cache of cursors by room.
@@ -171,6 +171,8 @@ private function get_storage_post_id( string $room ): ?int {
171171
'post_status' => 'publish',
172172
'name' => $room_hash,
173173
'fields' => 'ids',
174+
'orderby' => 'ID',
175+
'order' => 'ASC',
174176
)
175177
);
176178

tests/phpunit/tests/rest-api/rest-sync-server.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,57 @@ public function __set( $name, $value ) {
980980
);
981981
}
982982

983+
/*
984+
* Data integrity tests.
985+
*/
986+
987+
public function test_get_updates_after_cursor_drops_malformed_json() {
988+
$storage = new WP_Sync_Post_Meta_Storage();
989+
$room = $this->get_post_room();
990+
$storage_posts = get_posts(
991+
array(
992+
'post_type' => WP_Sync_Post_Meta_Storage::POST_TYPE,
993+
'posts_per_page' => 1,
994+
'post_status' => 'publish',
995+
'name' => md5( $room ),
996+
'fields' => 'ids',
997+
)
998+
);
999+
$storage_post_id = array_first( $storage_posts );
1000+
1001+
// Advance cursor past the seed update from create_storage_post().
1002+
$storage->get_updates_after_cursor( $room, 0 );
1003+
$cursor = $storage->get_cursor( $room );
1004+
1005+
// Insert a valid update.
1006+
$valid_update = array(
1007+
'type' => 'update',
1008+
'data' => 'dGVzdA==',
1009+
);
1010+
$this->assertTrue( $storage->add_update( $room, $valid_update ) );
1011+
1012+
// Insert a malformed JSON row directly into the meta data.
1013+
add_post_meta(
1014+
$storage_post_id,
1015+
WP_Sync_Post_Meta_Storage::SYNC_UPDATE_META_KEY,
1016+
'{invalid json'
1017+
);
1018+
1019+
// Insert another valid update after the malformed one.
1020+
$valid_update_2 = array(
1021+
'type' => 'sync_step1',
1022+
'data' => 'c3RlcDE=',
1023+
);
1024+
$this->assertTrue( $storage->add_update( $room, $valid_update_2 ) );
1025+
1026+
$updates = $storage->get_updates_after_cursor( $room, $cursor );
1027+
1028+
// The malformed row should be dropped; only the valid updates should appear.
1029+
$this->assertCount( 2, $updates );
1030+
$this->assertSame( $valid_update, $updates[0] );
1031+
$this->assertSame( $valid_update_2, $updates[1] );
1032+
}
1033+
9831034
/*
9841035
* Awareness tests.
9851036
*/

0 commit comments

Comments
 (0)