Skip to content

Commit c28eeed

Browse files
authored
Merge pull request #8 from omnisend/grouping2
Fix push
2 parents 7532ae0 + 52801eb commit c28eeed

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

includes/class-stl-synchronizer.php

+26-14
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,16 @@ public function sync_db( $tables ) {
198198
foreach ($group['changes'] as $section_table => $section_changes) {
199199
// If this is the table we're looking for
200200
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')) {
202203

203-
// For attachments and child_posts, treat them as posts table
204+
// For attachments, child_posts and attachment_meta, map to the actual table
204205
$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+
}
205211

206212
// Find the change in this section
207213
foreach ($section_changes as $section_change) {
@@ -267,14 +273,20 @@ public function sync_db( $tables ) {
267273
private function process_db_change($table, $id, $change, &$results) {
268274
global $wpdb;
269275

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;
272284

273285
// Get the primary key column for this table
274286
$primary_key = $this->get_primary_key($production_table);
275287

276288
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 );
278290
return false;
279291
}
280292

@@ -287,7 +299,7 @@ private function process_db_change($table, $id, $change, &$results) {
287299
$staging_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$staging_table} WHERE {$primary_key} = %s", $id ), ARRAY_A );
288300

289301
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 );
291303
return false;
292304
}
293305

@@ -309,10 +321,10 @@ private function process_db_change($table, $id, $change, &$results) {
309321
$result = $wpdb->query( $wpdb->prepare( $query, $query_values ) );
310322

311323
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 );
313325
return false;
314326
} 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 );
316328
return true;
317329
}
318330
break;
@@ -322,7 +334,7 @@ private function process_db_change($table, $id, $change, &$results) {
322334
$staging_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$staging_table} WHERE {$primary_key} = %s", $id ), ARRAY_A );
323335

324336
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 );
326338
return false;
327339
}
328340

@@ -345,10 +357,10 @@ private function process_db_change($table, $id, $change, &$results) {
345357
$result = $wpdb->query( $wpdb->prepare( $query, $query_values ) );
346358

347359
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 );
349361
return false;
350362
} 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 );
352364
return true;
353365
}
354366
break;
@@ -358,16 +370,16 @@ private function process_db_change($table, $id, $change, &$results) {
358370
$result = $wpdb->delete( $production_table, array( $primary_key => $id ), array( '%s' ) );
359371

360372
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 );
362374
return false;
363375
} 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 );
365377
return true;
366378
}
367379
break;
368380

369381
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 );
371383
return false;
372384
}
373385

0 commit comments

Comments
 (0)