@@ -52,7 +52,7 @@ class STL_DB_Comparer {
52
52
* @var array
53
53
*/
54
54
private $ excluded_tables = array (
55
- 'options ' , // Often contains transients and cache data
55
+ // 'options', // Often contains transients and cache data
56
56
'usermeta ' , // User session data changes frequently
57
57
'sessions ' , // Session data changes frequently
58
58
'term_taxonomy ' , // Term taxonomy data changes frequently
@@ -290,6 +290,22 @@ public function get_changes( $force = false ) {
290
290
291
291
return $ grouped_changes ;
292
292
}
293
+
294
+ private function is_excluded_name ($ name ): bool {
295
+ if (strpos ($ name , '_site_transient ' ) === 0 ) {
296
+ return true ;
297
+ }
298
+
299
+ if (strpos ($ name , '_transient ' ) === 0 ) {
300
+ return true ;
301
+ }
302
+
303
+ if ($ name === 'wp_staging_user_roles ' ) {
304
+ return true ;
305
+ }
306
+
307
+ return false ;
308
+ }
293
309
294
310
/**
295
311
* Compare a single table between production and staging
@@ -325,11 +341,15 @@ private function compare_table( $production_table, $staging_table, $table_name )
325
341
// Find new entries (in staging but not in production)
326
342
$ new_ids = array_diff ( $ staging_ids , $ production_ids );
327
343
foreach ( $ new_ids as $ id ) {
344
+ if ( $ table_name == 'options ' && ! empty ($ staging_row ['option_name ' ]) && $ this ->is_excluded_name ($ staging_row ['option_name ' ])){
345
+ continue ;
346
+ }
347
+
328
348
$ staging_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ staging_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
329
349
330
350
$ changes [] = array (
331
351
'id ' => $ id ,
332
- 'type ' => 'added ' ,
352
+ 'type ' => 'added ' . (! empty ( $ staging_row [ ' option_name ' ]) ? " > { $ staging_row [ ' option_name ' ]}" : '' ) ,
333
353
'summary ' => sprintf ( __ ( 'New entry with ID %s ' , 'staging2live ' ), $ id ),
334
354
'details ' => $ staging_row ,
335
355
);
@@ -338,11 +358,14 @@ private function compare_table( $production_table, $staging_table, $table_name )
338
358
// Find deleted entries (in production but not in staging)
339
359
$ deleted_ids = array_diff ( $ production_ids , $ staging_ids );
340
360
foreach ( $ deleted_ids as $ id ) {
361
+ if ( $ table_name == 'options ' && ! empty ($ staging_row ['option_name ' ]) && $ this ->is_excluded_name ($ staging_row ['option_name ' ]))
362
+ continue ;
363
+
341
364
$ production_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ production_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
342
365
343
366
$ changes [] = array (
344
367
'id ' => $ id ,
345
- 'type ' => 'deleted ' ,
368
+ 'type ' => 'deleted ' . (! empty ( $ staging_row [ ' option_name ' ]) ? " > { $ staging_row [ ' option_name ' ]}" : '' ) ,
346
369
'summary ' => sprintf ( __ ( 'Entry with ID %s deleted ' , 'staging2live ' ), $ id ),
347
370
'details ' => $ production_row ,
348
371
);
@@ -354,7 +377,13 @@ private function compare_table( $production_table, $staging_table, $table_name )
354
377
foreach ( $ common_ids as $ id ) {
355
378
$ production_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ production_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
356
379
$ staging_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ staging_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
357
-
380
+
381
+ $ option = '' ;
382
+ if (!empty ($ production_row ['option_name ' ]))
383
+ $ option = $ production_row ['option_name ' ];
384
+ if (!empty ($ staging_row ['option_name ' ]))
385
+ $ option = $ staging_row ['option_name ' ];
386
+
358
387
$ row_changes = array ();
359
388
360
389
foreach ( $ columns as $ column ) {
@@ -394,10 +423,13 @@ private function compare_table( $production_table, $staging_table, $table_name )
394
423
if ( ! empty ( $ row_changes ) ) {
395
424
// Get a human-readable name for this entry if possible
396
425
$ entry_name = $ this ->get_entry_name ( $ table_name , $ production_row );
397
-
426
+
427
+ if ( $ table_name == 'options ' && ! empty ($ option ) && $ this ->is_excluded_name ($ option ))
428
+ continue ;
429
+
398
430
$ changes [] = array (
399
431
'id ' => $ id ,
400
- 'type ' => 'modified ' ,
432
+ 'type ' => 'modified ' . ( $ option != '' ? " > $ option " : '' ) ,
401
433
'summary ' => $ entry_name
402
434
? sprintf ( __ ( 'Changes to "%s" ' , 'staging2live ' ), $ entry_name )
403
435
: sprintf ( __ ( 'Entry with ID %s modified ' , 'staging2live ' ), $ id ),
0 commit comments