Skip to content

Commit

Permalink
Merge branch 'update/custom-logs-table-PSMEL-303' into beta/custom-lo…
Browse files Browse the repository at this point in the history
…gs-table
  • Loading branch information
smusmanobjects committed Mar 27, 2023
2 parents 5af4267 + 69b5e3f commit ef3271a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Postman/Postman-Email-Log/PostmanEmailLogMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ public function migrate_logs() {

//Migrating Logs
foreach( $old_logs as $ID => $log ) {

$log = $this->remove_extra_keys( $log );

$result = PostmanEmailLogs::get_instance()->save( $log );

Expand Down Expand Up @@ -344,6 +346,27 @@ public function get_old_logs( $limit = 500 ) {
$logs_meta = $wpdb->get_results(
"SELECT post_id as ID, meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id IN ({$log_ids});"
);

/**
* Filter to delete incomplete logs, force migration
*
* @param bool
* @since 2.5.0
* @version 1.0.0
*/
if( apply_filters( 'postman_delete_incomplete_logs', false ) && empty( $logs_meta ) ) {

$log_ids = explode( ',', $log_ids );

foreach( $log_ids as $ID ) {

wp_delete_post( $ID, true );

}

return true;

}

if( $logs_meta ) {

Expand Down Expand Up @@ -500,6 +523,46 @@ public function switch_to_new() {

}


/**
* Remove Extra Keys
*
* @param array $array
* @since 2.5.0
* @version 1.0.0
*/
public function remove_extra_keys( $array ) {

$allowedKeys = array(
'solution',
'success',
'from_header',
'to_header',
'cc_header',
'bcc_header',
'reply_to_header',
'transport_uri',
'original_to',
'original_subject',
'original_message',
'original_headers',
'session_transcript'
);

foreach ( $array as $key => $value ) {

if ( !in_array( $key, $allowedKeys ) ) {

unset( $array[$key] );

}

}

return $array;

}

}

new PostmanEmailLogsMigration;
Expand Down

0 comments on commit ef3271a

Please sign in to comment.