update
This commit is contained in:
@@ -377,134 +377,128 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
|
||||
$to_delete = true;
|
||||
|
||||
$to_change = apply_filters('wp_all_import_is_post_to_change_missing', true, $missingPostRecord['post_id'], $this);
|
||||
|
||||
if (empty($this->options['delete_missing_action']) || $this->options['delete_missing_action'] != 'remove') {
|
||||
// Instead of deletion, set Custom Field.
|
||||
if ($this->options['is_update_missing_cf']){
|
||||
$update_missing_cf_name = $this->options['update_missing_cf_name'];
|
||||
if (!is_array($update_missing_cf_name)) {
|
||||
$update_missing_cf_name = [$update_missing_cf_name];
|
||||
}
|
||||
$update_missing_cf_value = $this->options['update_missing_cf_value'];
|
||||
if (!is_array($update_missing_cf_value)) {
|
||||
$update_missing_cf_value = [$update_missing_cf_value];
|
||||
}
|
||||
foreach ($update_missing_cf_name as $cf_i => $cf_name) {
|
||||
if (empty($cf_name)) {
|
||||
continue;
|
||||
}
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion user with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'shop_customer':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion customer with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'taxonomies':
|
||||
update_term_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion taxonomy term with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'gf_entries':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
update_comment_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion comment with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
default:
|
||||
update_post_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
// Instead of deletion, send missing records to trash.
|
||||
if ($this->options['is_send_removed_to_trash']) {
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'trash' );
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
wp_trash_comment($missingPostRecord['post_id']);
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and 'trash' != get_post_status($missingPostRecord['post_id'])) {
|
||||
wp_trash_post($missingPostRecord['post_id']);
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to trash', 'wp_all_import_plugin'), $missingPostRecord['post_id']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
// Instead of deletion, change post status to Draft
|
||||
elseif ($this->options['is_change_post_status_of_removed']){
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
switch ($this->options['status_of_removed']) {
|
||||
case 'restore':
|
||||
case 'unspam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'active' );
|
||||
break;
|
||||
case 'spam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'spam' );
|
||||
break;
|
||||
case 'mark_read':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 1 );
|
||||
break;
|
||||
case 'mark_unread':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 0 );
|
||||
break;
|
||||
case 'add_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 1 );
|
||||
break;
|
||||
case 'remove_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 0 );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
wp_set_comment_status($missingPostRecord['post_id'], $this->options['status_of_removed']);
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and $this->options['status_of_removed'] != get_post_status($missingPostRecord['post_id'])) {
|
||||
$this->wpdb->update( $this->wpdb->posts, array('post_status' => $this->options['status_of_removed']), array('ID' => $missingPostRecord['post_id']) );
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to %s', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $this->options['status_of_removed']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
if (!empty($this->options['missing_records_stock_status']) && class_exists('PMWI_Plugin') && $this->options['custom_type'] == "product") {
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock_status', 'outofstock' );
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock', 0 );
|
||||
|
||||
$term_ids = wp_get_object_terms($missingPostRecord['post_id'], 'product_visibility', array('fields' => 'ids'));
|
||||
|
||||
if (!empty($outofstock_term) && !is_wp_error($outofstock_term) && !in_array($outofstock_term->term_taxonomy_id, $term_ids)){
|
||||
$term_ids[] = $outofstock_term->term_taxonomy_id;
|
||||
}
|
||||
$this->associate_terms( $missingPostRecord['post_id'], $term_ids, 'product_visibility', $logger );
|
||||
$to_delete = false;
|
||||
}
|
||||
if($to_change){
|
||||
// Instead of deletion, set Custom Field.
|
||||
if ($this->options['is_update_missing_cf']){
|
||||
$update_missing_cf_name = $this->options['update_missing_cf_name'];
|
||||
if (!is_array($update_missing_cf_name)) {
|
||||
$update_missing_cf_name = [$update_missing_cf_name];
|
||||
}
|
||||
$update_missing_cf_value = $this->options['update_missing_cf_value'];
|
||||
if (!is_array($update_missing_cf_value)) {
|
||||
$update_missing_cf_value = [$update_missing_cf_value];
|
||||
}
|
||||
foreach ($update_missing_cf_name as $cf_i => $cf_name) {
|
||||
if (empty($cf_name)) {
|
||||
continue;
|
||||
}
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion user with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'shop_customer':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion customer with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'taxonomies':
|
||||
update_term_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion taxonomy term with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'gf_entries':
|
||||
// No actions required.
|
||||
break;
|
||||
default:
|
||||
update_post_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
// Instead of deletion, send missing records to trash.
|
||||
if ($this->options['is_send_removed_to_trash']) {
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'trash' );
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and 'trash' != get_post_status($missingPostRecord['post_id'])) {
|
||||
wp_trash_post($missingPostRecord['post_id']);
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to trash', 'wp_all_import_plugin'), $missingPostRecord['post_id']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
// Instead of deletion, change post status to Draft
|
||||
elseif ($this->options['is_change_post_status_of_removed']){
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
switch ($this->options['status_of_removed']) {
|
||||
case 'restore':
|
||||
case 'unspam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'active' );
|
||||
break;
|
||||
case 'spam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'spam' );
|
||||
break;
|
||||
case 'mark_read':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 1 );
|
||||
break;
|
||||
case 'mark_unread':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 0 );
|
||||
break;
|
||||
case 'add_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 1 );
|
||||
break;
|
||||
case 'remove_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 0 );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and $this->options['status_of_removed'] != get_post_status($missingPostRecord['post_id'])) {
|
||||
$this->wpdb->update( $this->wpdb->posts, array('post_status' => $this->options['status_of_removed']), array('ID' => $missingPostRecord['post_id']) );
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to %s', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $this->options['status_of_removed']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
if (!empty($this->options['missing_records_stock_status']) && class_exists('PMWI_Plugin') && $this->options['custom_type'] == "product") {
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock_status', 'outofstock' );
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock', 0 );
|
||||
|
||||
$term_ids = wp_get_object_terms($missingPostRecord['post_id'], 'product_visibility', array('fields' => 'ids'));
|
||||
|
||||
if (!empty($outofstock_term) && !is_wp_error($outofstock_term) && !in_array($outofstock_term->term_taxonomy_id, $term_ids)){
|
||||
$term_ids[] = $outofstock_term->term_taxonomy_id;
|
||||
}
|
||||
$this->associate_terms( $missingPostRecord['post_id'], $term_ids, 'product_visibility', $logger );
|
||||
$to_delete = false;
|
||||
}
|
||||
}else{
|
||||
// If record has been forced to be unchanged then we shouldn't delete it either.
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
if (empty($this->options['is_update_missing_cf']) && empty($this->options['is_send_removed_to_trash']) && empty($this->options['is_change_post_status_of_removed']) && empty($this->options['missing_records_stock_status'])) {
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion: change %s with ID `%s` - no action selected, skipping', 'wp_all_import_plugin'), $custom_type->labels->name, $missingPostRecord['post_id']));
|
||||
@@ -520,8 +514,6 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'gf_entries':
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
// No action needed;
|
||||
break;
|
||||
case 'taxonomies':
|
||||
@@ -616,13 +608,6 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
wp_delete_term( $term_id, $this->options['taxonomy_type'] );
|
||||
}
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
do_action('pmxi_delete_comments', $ids);
|
||||
foreach ($ids as $comment_id){
|
||||
wp_delete_comment( $comment_id, TRUE );
|
||||
}
|
||||
break;
|
||||
case 'gf_entries':
|
||||
do_action('pmxi_delete_gf_entries', $ids, $this);
|
||||
foreach ($ids as $entry_id) {
|
||||
@@ -2389,10 +2374,6 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
case 'taxonomies':
|
||||
delete_term_meta( $pid, $image_custom_field );
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
delete_comment_meta( $pid, $image_custom_field );
|
||||
break;
|
||||
case 'gf_entries':
|
||||
// No actions required.
|
||||
break;
|
||||
@@ -3500,6 +3481,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
$term_args = sanitize_term($term_args, $tx_name, 'db');
|
||||
$term_name = wp_unslash( $term_args['name'] );
|
||||
$term_slug = sanitize_title( $term_name );
|
||||
$term_slug = pmxi_truncate_term_slug($term_slug);
|
||||
$term = (empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name])) ? is_exists_term($term_slug, $tx_name, (int)$parent_id) : is_exists_term($term_slug, $tx_name);
|
||||
if( empty($this->options['do_not_create_terms']) && empty($term) && !is_wp_error($term) ) {
|
||||
$term_attr = array('parent' => (!empty($parent_id)) ? $parent_id : 0);
|
||||
@@ -3664,7 +3646,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
$is_import_complete = ($records_count == $records_to_import);
|
||||
|
||||
// Set out of stock status for missing records [Woocommerce add-on option]
|
||||
if ( $is_import_complete && !empty($this->options['is_delete_missing']) && $this->options['delete_missing_action'] == 'keep' && $this->options['custom_type'] == "product" && class_exists('PMWI_Plugin') && !empty($this->options['missing_records_stock_status']) ) {
|
||||
if ( $is_import_complete && !empty($this->options['is_delete_missing']) && $this->options['delete_missing_action'] == 'keep' && $this->options['custom_type'] == "product" && class_exists('PMWI_Plugin') && !empty($this->options['missing_records_stock_status']) && apply_filters('wp_all_import_is_post_to_change_missing', true, $missingPostRecord['post_id'], $this) ) {
|
||||
|
||||
$logger and call_user_func($logger, __('Update stock status previously imported posts which are no longer actual...', 'wp_all_import_plugin'));
|
||||
|
||||
@@ -3706,10 +3688,6 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
case 'shop_customer':
|
||||
$title = $articleData['user_login'];
|
||||
break;
|
||||
case 'comments':
|
||||
case 'woo_reviews':
|
||||
$title = wp_trim_words($articleData['comment_content'], 10);
|
||||
break;
|
||||
default:
|
||||
$title = $articleData['post_title'];
|
||||
break;
|
||||
@@ -3739,6 +3717,9 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
if ( preg_match('%\W(svg)$%i', wp_all_import_basename($image_filepath)) or $file_info = apply_filters('pmxi_getimagesize', @getimagesize($image_filepath), $image_filepath) and in_array($file_info[2], wp_all_import_supported_image_types())) {
|
||||
$downloaded = true;
|
||||
if (preg_match('%\W(svg)$%i', wp_all_import_basename($image_filepath))){
|
||||
if ( (is_wp_error($request) or $request === false)) {
|
||||
wp_all_import_sanitize_svg( $image_filepath );
|
||||
}
|
||||
$file_info = true;
|
||||
}
|
||||
$logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
|
||||
@@ -3762,7 +3743,9 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
|
||||
$logger and call_user_func($logger, sprintf(__('- Creating an attachment for image `%s`', 'wp_all_import_plugin'), $handle_image['url']));
|
||||
|
||||
$attachment_title = explode(".", $image_name);
|
||||
empty($handle_image['type']) && $handle_image['type'] = preg_match('%\W(svg)$%i', wp_all_import_basename($handle_image['file'])) ? 'image/svg+xml' : '';
|
||||
|
||||
$attachment_title = explode(".", $image_name);
|
||||
if (is_array($attachment_title) and count($attachment_title) > 1) array_pop($attachment_title);
|
||||
|
||||
$attachment = array(
|
||||
@@ -3893,142 +3876,136 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
|
||||
$to_delete = true;
|
||||
|
||||
$to_change = apply_filters('wp_all_import_is_post_to_change_missing', true, $missingPostRecord['post_id'], $this);
|
||||
|
||||
if (empty($this->options['delete_missing_action']) || $this->options['delete_missing_action'] != 'remove') {
|
||||
// Instead of deletion, set Custom Field
|
||||
if ($this->options['is_update_missing_cf']){
|
||||
$update_missing_cf_name = $this->options['update_missing_cf_name'];
|
||||
if (!is_array($update_missing_cf_name)) {
|
||||
$update_missing_cf_name = [$update_missing_cf_name];
|
||||
}
|
||||
$update_missing_cf_value = $this->options['update_missing_cf_value'];
|
||||
if (!is_array($update_missing_cf_value)) {
|
||||
$update_missing_cf_value = [$update_missing_cf_value];
|
||||
}
|
||||
foreach ($update_missing_cf_name as $cf_i => $cf_name) {
|
||||
if (empty($cf_name)) {
|
||||
continue;
|
||||
}
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion user with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'shop_customer':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion customer with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'taxonomies':
|
||||
update_term_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion taxonomy term with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
update_comment_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion comment with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'gf_entries':
|
||||
// No actions required.
|
||||
break;
|
||||
default:
|
||||
update_post_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($to_change){
|
||||
// Instead of deletion, set Custom Field
|
||||
if ($this->options['is_update_missing_cf']){
|
||||
$update_missing_cf_name = $this->options['update_missing_cf_name'];
|
||||
if (!is_array($update_missing_cf_name)) {
|
||||
$update_missing_cf_name = [$update_missing_cf_name];
|
||||
}
|
||||
$update_missing_cf_value = $this->options['update_missing_cf_value'];
|
||||
if (!is_array($update_missing_cf_value)) {
|
||||
$update_missing_cf_value = [$update_missing_cf_value];
|
||||
}
|
||||
foreach ($update_missing_cf_name as $cf_i => $cf_name) {
|
||||
if (empty($cf_name)) {
|
||||
continue;
|
||||
}
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion user with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'shop_customer':
|
||||
update_user_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion customer with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'taxonomies':
|
||||
update_term_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion taxonomy term with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
case 'gf_entries':
|
||||
// No actions required.
|
||||
break;
|
||||
default:
|
||||
update_post_meta( $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i] );
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $cf_name, $update_missing_cf_value[$cf_i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$to_delete = false;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
// Instead of deletion, send missing records to trash.
|
||||
if ($this->options['is_send_removed_to_trash']) {
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'trash' );
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
wp_trash_comment($missingPostRecord['post_id']);
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and 'trash' != get_post_status($missingPostRecord['post_id'])) {
|
||||
wp_trash_post($missingPostRecord['post_id']);
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to trash', 'wp_all_import_plugin'), $missingPostRecord['post_id']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Instead of deletion, send missing records to trash.
|
||||
if ($this->options['is_send_removed_to_trash']) {
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'trash' );
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and 'trash' != get_post_status($missingPostRecord['post_id'])) {
|
||||
wp_trash_post($missingPostRecord['post_id']);
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to trash', 'wp_all_import_plugin'), $missingPostRecord['post_id']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$to_delete = false;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
// Instead of deletion, change post status to Draft
|
||||
elseif ($this->options['is_change_post_status_of_removed']){
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
switch ($this->options['status_of_removed']) {
|
||||
case 'restore':
|
||||
case 'unspam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'active' );
|
||||
break;
|
||||
case 'spam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'spam' );
|
||||
break;
|
||||
case 'mark_read':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 1 );
|
||||
break;
|
||||
case 'mark_unread':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 0 );
|
||||
break;
|
||||
case 'add_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 1 );
|
||||
break;
|
||||
case 'remove_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 0 );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
wp_set_comment_status($missingPostRecord['post_id'], $this->options['status_of_removed']);
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and $this->options['status_of_removed'] != get_post_status($missingPostRecord['post_id'])) {
|
||||
$this->wpdb->update( $this->wpdb->posts, array('post_status' => $this->options['status_of_removed']), array('ID' => $missingPostRecord['post_id']) );
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to %s', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $this->options['status_of_removed']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
// Instead of deletion, change post status to Draft
|
||||
elseif ($this->options['is_change_post_status_of_removed']){
|
||||
switch ($this->options['custom_type']){
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'taxonomies':
|
||||
// No actions required.
|
||||
break;
|
||||
case 'gf_entries':
|
||||
switch ($this->options['status_of_removed']) {
|
||||
case 'restore':
|
||||
case 'unspam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'active' );
|
||||
break;
|
||||
case 'spam':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'status', 'spam' );
|
||||
break;
|
||||
case 'mark_read':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 1 );
|
||||
break;
|
||||
case 'mark_unread':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_read', 0 );
|
||||
break;
|
||||
case 'add_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 1 );
|
||||
break;
|
||||
case 'remove_star':
|
||||
GFFormsModel::update_entry_property( $missingPostRecord['post_id'], 'is_starred', 0 );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($final_post_type = get_post_type($missingPostRecord['post_id']) and $this->options['status_of_removed'] != get_post_status($missingPostRecord['post_id'])) {
|
||||
$this->wpdb->update( $this->wpdb->posts, array('post_status' => $this->options['status_of_removed']), array('ID' => $missingPostRecord['post_id']) );
|
||||
$this->recount_terms($missingPostRecord['post_id'], $final_post_type);
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to %s', 'wp_all_import_plugin'), $missingPostRecord['post_id'], $this->options['status_of_removed']));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
if (!empty($this->options['missing_records_stock_status']) && class_exists('PMWI_Plugin') && $this->options['custom_type'] == "product") {
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock_status', 'outofstock' );
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock', 0 );
|
||||
if (!empty($this->options['missing_records_stock_status']) && class_exists('PMWI_Plugin') && $this->options['custom_type'] == "product") {
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock_status', 'outofstock' );
|
||||
update_post_meta( $missingPostRecord['post_id'], '_stock', 0 );
|
||||
|
||||
$term_ids = wp_get_object_terms($missingPostRecord['post_id'], 'product_visibility', array('fields' => 'ids'));
|
||||
$term_ids = wp_get_object_terms($missingPostRecord['post_id'], 'product_visibility', array('fields' => 'ids'));
|
||||
|
||||
if (!empty($outofstock_term) && !is_wp_error($outofstock_term) && !in_array($outofstock_term->term_taxonomy_id, $term_ids)){
|
||||
$term_ids[] = $outofstock_term->term_taxonomy_id;
|
||||
}
|
||||
$this->associate_terms( $missingPostRecord['post_id'], $term_ids, 'product_visibility', $logger );
|
||||
$to_delete = false;
|
||||
}
|
||||
if (!empty($outofstock_term) && !is_wp_error($outofstock_term) && !in_array($outofstock_term->term_taxonomy_id, $term_ids)){
|
||||
$term_ids[] = $outofstock_term->term_taxonomy_id;
|
||||
}
|
||||
$this->associate_terms( $missingPostRecord['post_id'], $term_ids, 'product_visibility', $logger );
|
||||
$to_delete = false;
|
||||
}
|
||||
|
||||
if (empty($this->options['is_update_missing_cf']) && empty($this->options['is_send_removed_to_trash']) && empty($this->options['is_change_post_status_of_removed']) && empty($this->options['missing_records_stock_status'])) {
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion: change %s with ID `%s` - no action selected, skipping', 'wp_all_import_plugin'), $custom_type->labels->name, $missingPostRecord['post_id']));
|
||||
$to_delete = false;
|
||||
}
|
||||
if (empty($this->options['is_update_missing_cf']) && empty($this->options['is_send_removed_to_trash']) && empty($this->options['is_change_post_status_of_removed']) && empty($this->options['missing_records_stock_status'])) {
|
||||
$logger and call_user_func($logger, sprintf(__('Instead of deletion: change %s with ID `%s` - no action selected, skipping', 'wp_all_import_plugin'), $custom_type->labels->name, $missingPostRecord['post_id']));
|
||||
$to_delete = false;
|
||||
}
|
||||
}else{
|
||||
// If record has been forced to be unchanged then we shouldn't delete it either.
|
||||
$to_delete = false;
|
||||
}
|
||||
}
|
||||
|
||||
$to_delete = apply_filters('wp_all_import_is_post_to_delete', $to_delete, $missingPostRecord['post_id'], $this);
|
||||
@@ -4037,8 +4014,6 @@ class PMXI_Import_Record extends PMXI_Model_Record {
|
||||
switch ($this->options['custom_type']) {
|
||||
case 'import_users':
|
||||
case 'shop_customer':
|
||||
case 'woo_reviews':
|
||||
case 'comments':
|
||||
case 'gf_entries':
|
||||
// No action needed.
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user