@@ -198,10 +198,16 @@ public function sync_db( $tables ) {
198
198
foreach ($ group ['changes ' ] as $ section_table => $ section_changes ) {
199
199
// If this is the table we're looking for
200
200
if ($ section_table === $ table ||
201
- ($ table === 'posts ' && ($ section_table === 'attachments ' || $ section_table === 'child_posts ' ))) {
201
+ ($ table === 'posts ' && ($ section_table === 'attachments ' || $ section_table === 'child_posts ' )) ||
202
+ ($ table === 'postmeta ' && $ section_table === 'attachment_meta ' )) {
202
203
203
- // For attachments and child_posts, treat them as posts table
204
+ // For attachments, child_posts and attachment_meta, map to the actual table
204
205
$ actual_table = $ table ;
206
+ if ($ section_table === 'attachments ' || $ section_table === 'child_posts ' ) {
207
+ $ actual_table = 'posts ' ;
208
+ } else if ($ section_table === 'attachment_meta ' ) {
209
+ $ actual_table = 'postmeta ' ;
210
+ }
205
211
206
212
// Find the change in this section
207
213
foreach ($ section_changes as $ section_change ) {
@@ -267,14 +273,20 @@ public function sync_db( $tables ) {
267
273
private function process_db_change ($ table , $ id , $ change , &$ results ) {
268
274
global $ wpdb ;
269
275
270
- $ production_table = $ this ->production_prefix . $ table ;
271
- $ staging_table = $ this ->staging_prefix . $ table ;
276
+ // Handle special case for attachment_meta - it's actually postmeta
277
+ $ actual_table = $ table ;
278
+ if ($ table === 'attachment_meta ' ) {
279
+ $ actual_table = 'postmeta ' ;
280
+ }
281
+
282
+ $ production_table = $ this ->production_prefix . $ actual_table ;
283
+ $ staging_table = $ this ->staging_prefix . $ actual_table ;
272
284
273
285
// Get the primary key column for this table
274
286
$ primary_key = $ this ->get_primary_key ($ production_table );
275
287
276
288
if (!$ primary_key ) {
277
- $ results ['error ' ][] = sprintf ( __ ( 'Could not find primary key for table %s. ' , 'staging2live ' ), $ table );
289
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not find primary key for table %s. ' , 'staging2live ' ), $ actual_table );
278
290
return false ;
279
291
}
280
292
@@ -287,7 +299,7 @@ private function process_db_change($table, $id, $change, &$results) {
287
299
$ staging_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ staging_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
288
300
289
301
if (!$ staging_row ) {
290
- $ results ['error ' ][] = sprintf ( __ ( 'Could not find entry with ID %s in staging table %s. ' , 'staging2live ' ), $ id , $ table );
302
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not find entry with ID %s in staging table %s. ' , 'staging2live ' ), $ id , $ actual_table );
291
303
return false ;
292
304
}
293
305
@@ -309,10 +321,10 @@ private function process_db_change($table, $id, $change, &$results) {
309
321
$ result = $ wpdb ->query ( $ wpdb ->prepare ( $ query , $ query_values ) );
310
322
311
323
if (false === $ result ) {
312
- $ results ['error ' ][] = sprintf ( __ ( 'Could not insert entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ table );
324
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not insert entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ actual_table );
313
325
return false ;
314
326
} else {
315
- $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s inserted successfully in table %s. ' , 'staging2live ' ), $ id , $ table );
327
+ $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s inserted successfully in table %s. ' , 'staging2live ' ), $ id , $ actual_table );
316
328
return true ;
317
329
}
318
330
break ;
@@ -322,7 +334,7 @@ private function process_db_change($table, $id, $change, &$results) {
322
334
$ staging_row = $ wpdb ->get_row ( $ wpdb ->prepare ( "SELECT * FROM {$ staging_table } WHERE {$ primary_key } = %s " , $ id ), ARRAY_A );
323
335
324
336
if (!$ staging_row ) {
325
- $ results ['error ' ][] = sprintf ( __ ( 'Could not find entry with ID %s in staging table %s. ' , 'staging2live ' ), $ id , $ table );
337
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not find entry with ID %s in staging table %s. ' , 'staging2live ' ), $ id , $ actual_table );
326
338
return false ;
327
339
}
328
340
@@ -345,10 +357,10 @@ private function process_db_change($table, $id, $change, &$results) {
345
357
$ result = $ wpdb ->query ( $ wpdb ->prepare ( $ query , $ query_values ) );
346
358
347
359
if (false === $ result ) {
348
- $ results ['error ' ][] = sprintf ( __ ( 'Could not update entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ table );
360
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not update entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ actual_table );
349
361
return false ;
350
362
} else {
351
- $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s updated successfully in table %s. ' , 'staging2live ' ), $ id , $ table );
363
+ $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s updated successfully in table %s. ' , 'staging2live ' ), $ id , $ actual_table );
352
364
return true ;
353
365
}
354
366
break ;
@@ -358,16 +370,16 @@ private function process_db_change($table, $id, $change, &$results) {
358
370
$ result = $ wpdb ->delete ( $ production_table , array ( $ primary_key => $ id ), array ( '%s ' ) );
359
371
360
372
if (false === $ result ) {
361
- $ results ['error ' ][] = sprintf ( __ ( 'Could not delete entry with ID %s from table %s. ' , 'staging2live ' ), $ id , $ table );
373
+ $ results ['error ' ][] = sprintf ( __ ( 'Could not delete entry with ID %s from table %s. ' , 'staging2live ' ), $ id , $ actual_table );
362
374
return false ;
363
375
} else {
364
- $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s deleted successfully from table %s. ' , 'staging2live ' ), $ id , $ table );
376
+ $ results ['success ' ][] = sprintf ( __ ( 'Entry with ID %s deleted successfully from table %s. ' , 'staging2live ' ), $ id , $ actual_table );
365
377
return true ;
366
378
}
367
379
break ;
368
380
369
381
default :
370
- $ results ['error ' ][] = sprintf ( __ ( 'Unknown change type for entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ table );
382
+ $ results ['error ' ][] = sprintf ( __ ( 'Unknown change type for entry with ID %s in table %s. ' , 'staging2live ' ), $ id , $ actual_table );
371
383
return false ;
372
384
}
373
385
0 commit comments