Skip to content

Commit 7455141

Browse files
committed
Collaboration: Rename update_value column to data
Rename the `update_value` column to `data` in the collaboration table storage class and tests, and fix array arrow alignment to satisfy PHPCS. The shorter name is consistent with WordPress meta tables and avoids confusion with the `update_value()` method in `WP_REST_Meta_Fields`.
1 parent 09d0b86 commit 7455141

2 files changed

Lines changed: 51 additions & 51 deletions

File tree

src/wp-includes/collaboration/class-wp-collaboration-table-storage.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public function add_update( string $room, $update ): bool {
5959
$result = $wpdb->insert(
6060
$wpdb->collaboration,
6161
array(
62-
'room' => $room,
63-
'type' => $update['type'] ?? '',
64-
'client_id' => $update['client_id'] ?? '',
65-
'update_value' => wp_json_encode( $update ),
66-
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
62+
'room' => $room,
63+
'type' => $update['type'] ?? '',
64+
'client_id' => $update['client_id'] ?? '',
65+
'data' => wp_json_encode( $update ),
66+
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
6767
),
6868
array( '%s', '%s', '%s', '%s', '%s' )
6969
);
@@ -107,7 +107,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
107107

108108
$rows = $wpdb->get_results(
109109
$wpdb->prepare(
110-
"SELECT client_id, user_id, update_value FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s",
110+
"SELECT client_id, user_id, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s",
111111
$room,
112112
$cutoff
113113
)
@@ -119,7 +119,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
119119

120120
$entries = array();
121121
foreach ( $rows as $row ) {
122-
$decoded = json_decode( $row->update_value, true );
122+
$decoded = json_decode( $row->data, true );
123123
if ( is_array( $decoded ) ) {
124124
$entries[] = array(
125125
'client_id' => $row->client_id,
@@ -215,7 +215,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
215215
// Fetch updates after the cursor up to the snapshot boundary.
216216
$rows = $wpdb->get_results(
217217
$wpdb->prepare(
218-
"SELECT update_value FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
218+
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
219219
$room,
220220
$cursor,
221221
$max_id
@@ -228,7 +228,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
228228

229229
$updates = array();
230230
foreach ( $rows as $row ) {
231-
$decoded = json_decode( $row->update_value, true );
231+
$decoded = json_decode( $row->data, true );
232232
if ( is_array( $decoded ) ) {
233233
$updates[] = $decoded;
234234
}
@@ -293,16 +293,16 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
293293
public function set_awareness_state( string $room, string $client_id, array $state, int $user_id ): bool {
294294
global $wpdb;
295295

296-
$update_value = wp_json_encode( $state );
297-
$now = gmdate( 'Y-m-d H:i:s' );
296+
$data = wp_json_encode( $state );
297+
$now = gmdate( 'Y-m-d H:i:s' );
298298

299299
// Try UPDATE first.
300300
$updated = $wpdb->update(
301301
$wpdb->collaboration,
302302
array(
303-
'user_id' => $user_id,
304-
'update_value' => $update_value,
305-
'date_gmt' => $now,
303+
'user_id' => $user_id,
304+
'data' => $data,
305+
'date_gmt' => $now,
306306
),
307307
array(
308308
'room' => $room,
@@ -316,12 +316,12 @@ public function set_awareness_state( string $room, string $client_id, array $sta
316316
$result = $wpdb->insert(
317317
$wpdb->collaboration,
318318
array(
319-
'room' => $room,
320-
'type' => 'awareness',
321-
'client_id' => $client_id,
322-
'user_id' => $user_id,
323-
'update_value' => $update_value,
324-
'date_gmt' => $now,
319+
'room' => $room,
320+
'type' => 'awareness',
321+
'client_id' => $client_id,
322+
'user_id' => $user_id,
323+
'data' => $data,
324+
'date_gmt' => $now,
325325
)
326326
);
327327

@@ -339,7 +339,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
339339
$cached = wp_cache_get( $cache_key, 'collaboration' );
340340

341341
if ( false !== $cached ) {
342-
$normalized_state = json_decode( $update_value, true );
342+
$normalized_state = json_decode( $data, true );
343343
$found = false;
344344

345345
foreach ( $cached as $i => $entry ) {

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,24 +1157,24 @@ public function test_collaboration_compaction_reduces_total_updates(): void {
11571157
* Inserts a row directly into the collaboration table with a given age.
11581158
*
11591159
* @param positive-int $age_in_seconds How old the row should be.
1160-
* @param string $label A label stored in the update_value for identification.
1160+
* @param string $label A label stored in the data column for identification.
11611161
*/
11621162
private function insert_collaboration_row( int $age_in_seconds, string $label = 'test' ): void {
11631163
global $wpdb;
11641164

11651165
$wpdb->insert(
11661166
$wpdb->collaboration,
11671167
array(
1168-
'room' => $this->get_post_room(),
1169-
'type' => 'update',
1170-
'client_id' => '1',
1171-
'update_value' => wp_json_encode(
1168+
'room' => $this->get_post_room(),
1169+
'type' => 'update',
1170+
'client_id' => '1',
1171+
'data' => wp_json_encode(
11721172
array(
11731173
'type' => 'update',
11741174
'data' => $label,
11751175
)
11761176
),
1177-
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - $age_in_seconds ),
1177+
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - $age_in_seconds ),
11781178
),
11791179
array( '%s', '%s', '%s', '%s', '%s' )
11801180
);
@@ -1236,7 +1236,7 @@ public function test_cron_cleanup_boundary_at_exactly_seven_days(): void {
12361236
wp_delete_old_collaboration_data();
12371237

12381238
global $wpdb;
1239-
$remaining = $wpdb->get_col( "SELECT update_value FROM {$wpdb->collaboration}" );
1239+
$remaining = $wpdb->get_col( "SELECT data FROM {$wpdb->collaboration}" );
12401240

12411241
$this->assertCount( 1, $remaining, 'Only the row within the 7-day window should remain.' );
12421242
$this->assertStringContainsString( 'just-inside', $remaining[0], 'The surviving row should be the one inside the window.' );
@@ -1289,7 +1289,7 @@ public function test_collaboration_routes_not_registered_when_db_version_is_old(
12891289
$server = rest_get_server();
12901290
$routes = $server->get_routes();
12911291

1292-
$this->assertArrayNotHasKey( '/wp-collaboration/v1/updates', $routes, 'Collaboration routes should not be registered when db_version is below 61840.' );
1292+
$this->assertArrayNotHasKey( '/wp-collaboration/v1/updates', $routes, 'Collaboration routes should not be registered when db_version is below 61841.' );
12931293

12941294
// Reset again so subsequent tests get a server with the correct db_version.
12951295
$GLOBALS['wp_rest_server'] = null;
@@ -1441,12 +1441,12 @@ public function test_collaboration_expired_awareness_rows_cleaned_up(): void {
14411441
$wpdb->insert(
14421442
$wpdb->collaboration,
14431443
array(
1444-
'room' => $room,
1445-
'type' => 'awareness',
1446-
'client_id' => '99',
1447-
'user_id' => self::$editor_id,
1448-
'update_value' => wp_json_encode( array( 'cursor' => 'stale' ) ),
1449-
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
1444+
'room' => $room,
1445+
'type' => 'awareness',
1446+
'client_id' => '99',
1447+
'user_id' => self::$editor_id,
1448+
'data' => wp_json_encode( array( 'cursor' => 'stale' ) ),
1449+
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
14501450
),
14511451
array( '%s', '%s', '%s', '%d', '%s', '%s' )
14521452
);
@@ -1497,12 +1497,12 @@ public function test_cron_cleanup_deletes_expired_awareness_rows(): void {
14971497
$wpdb->insert(
14981498
$wpdb->collaboration,
14991499
array(
1500-
'room' => $this->get_post_room(),
1501-
'type' => 'awareness',
1502-
'client_id' => '42',
1503-
'user_id' => self::$editor_id,
1504-
'update_value' => wp_json_encode( array( 'cursor' => 'old' ) ),
1505-
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
1500+
'room' => $this->get_post_room(),
1501+
'type' => 'awareness',
1502+
'client_id' => '42',
1503+
'user_id' => self::$editor_id,
1504+
'data' => wp_json_encode( array( 'cursor' => 'old' ) ),
1505+
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
15061506
),
15071507
array( '%s', '%s', '%s', '%d', '%s', '%s' )
15081508
);
@@ -1521,7 +1521,7 @@ public function test_cron_cleanup_deletes_expired_awareness_rows(): void {
15211521

15221522
/**
15231523
* Verifies that user_id is stored as a dedicated column,
1524-
* not embedded inside the update_value JSON blob.
1524+
* not embedded inside the data JSON blob.
15251525
*
15261526
* @ticket 64696
15271527
*/
@@ -1539,20 +1539,20 @@ public function test_collaboration_awareness_user_id_round_trip() {
15391539
// Query the collaboration table directly for the awareness row.
15401540
$row = $wpdb->get_row(
15411541
$wpdb->prepare(
1542-
"SELECT user_id, update_value FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s",
1542+
"SELECT user_id, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s",
15431543
$room,
15441544
'1'
15451545
)
15461546
);
15471547

15481548
$this->assertNotNull( $row, 'Awareness row should exist.' );
15491549
$this->assertSame( self::$editor_id, (int) $row->user_id, 'user_id column should match the editor.' );
1550-
$this->assertStringNotContainsString( 'user_id', $row->update_value, 'update_value should not contain user_id.' );
1550+
$this->assertStringNotContainsString( 'user_id', $row->data, 'data column should not contain user_id.' );
15511551
}
15521552

15531553
/**
15541554
* Verifies that the is_array() guard in get_awareness_state() skips
1555-
* rows where update_value contains valid JSON that is not an array.
1555+
* rows where the data column contains valid JSON that is not an array.
15561556
*
15571557
* @ticket 64696
15581558
*/
@@ -1567,12 +1567,12 @@ public function test_collaboration_awareness_non_array_json_ignored() {
15671567
$wpdb->insert(
15681568
$wpdb->collaboration,
15691569
array(
1570-
'room' => $room,
1571-
'type' => 'awareness',
1572-
'client_id' => '99',
1573-
'user_id' => self::$editor_id,
1574-
'update_value' => '"hello"',
1575-
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
1570+
'room' => $room,
1571+
'type' => 'awareness',
1572+
'client_id' => '99',
1573+
'user_id' => self::$editor_id,
1574+
'data' => '"hello"',
1575+
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
15761576
),
15771577
array( '%s', '%s', '%s', '%d', '%s', '%s' )
15781578
);

0 commit comments

Comments
 (0)