示例#1
0
 function wpsc_st_clear_dataset($dataset)
 {
     global $wpdb;
     $upload_dir = wp_upload_dir();
     switch ($dataset) {
         case 'products':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_list`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_productmeta`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_order`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_rating`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_item_category_assoc`");
             break;
         case 'variations':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_variations`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_variation_assoc`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_variation_combinations`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_variation_properties`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_variation_values`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_variation_values_assoc`");
             break;
         case 'tags':
             $term_taxonomy = 'product_tag';
             $tags = get_terms($term_taxonomy, array('hide_empty' => false));
             if ($tags) {
                 foreach ($tags as $tag) {
                     wp_delete_term($tag->term_id, $term_taxonomy);
                     $wpdb->query("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = " . $tag->term_id);
                 }
             }
             break;
         case 'categories':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_categories`");
             break;
         case 'images':
             wpsc_st_empty_dir($upload_dir['basedir'] . '/wpsc/product_images');
             wpsc_st_empty_dir($upload_dir['basedir'] . '/wpsc/product_images/thumbnails');
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_images`");
             break;
         case 'files':
             wpsc_st_empty_dir($upload_dir['basedir'] . '/wpsc/downloadables');
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_product_files`");
             break;
         case 'orders':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_purchase_logs`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_cart_contents`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_submited_form_data`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_download_status`");
             break;
         case 'wishlist':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_wishlist`");
             break;
         case 'enquiries':
             $post_type = 'wpsc-enquiry';
             $enquiries = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($enquiries) {
                 foreach ($enquiries as $enquiry) {
                     if ($enquiry->ID) {
                         wp_delete_post($enquiry->ID);
                     }
                 }
             }
             break;
         case 'credit-cards':
             $post_type = 'offline_payment';
             $cards = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($cards) {
                 foreach ($cards as $card) {
                     if ($card->ID) {
                         wp_delete_post($card->ID);
                     }
                 }
             }
             break;
         case 'custom-fields':
             delete_option('wpsc_cf_data');
             break;
     }
 }
示例#2
0
 function wpsc_st_clear_dataset($dataset, $data = null)
 {
     global $wpdb;
     switch ($dataset) {
         // WP e-Commerce
         case 'products':
             $post_type = 'wpsc-product';
             $products = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($products) {
                 foreach ($products as $product) {
                     if ($product->ID) {
                         wp_delete_post($product->ID, true);
                     }
                 }
             }
             break;
         case 'variations':
             // Products
             $post_type = 'wpsc-product';
             $variations_sql = "SELECT `ID` FROM `" . $wpdb->posts . "` WHERE `post_type` = '" . $post_type . "' AND `post_parent` <> 0";
             $variations = $wpdb->get_results($variations_sql);
             if ($variations) {
                 foreach ($variations as $variation) {
                     if ($variation->ID) {
                         wp_delete_post($variation->ID, true);
                     }
                 }
             }
             // Terms
             $term_taxonomy = 'wpsc-variation';
             $variations = get_terms($term_taxonomy, array('hide_empty' => false));
             if ($variations) {
                 foreach ($variations as $variation) {
                     if ($variation->term_id) {
                         wp_delete_term($variation->term_id, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $variation->term_id));
                     }
                 }
             }
             delete_option('wpsc-variation_children');
             break;
         case 'categories':
             $term_taxonomy = 'wpsc_product_category';
             if ($data) {
                 foreach ($data as $single_category) {
                     $post_type = 'wpsc-product';
                     $args = array('post_type' => $post_type, 'tax_query' => array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $single_category)), 'numberposts' => -1);
                     $products = get_posts($args);
                     if ($products) {
                         foreach ($products as $product) {
                             if ($product->ID) {
                                 wp_delete_post($product->ID, true);
                             }
                         }
                     }
                 }
             } else {
                 $categories = get_terms($term_taxonomy, array('hide_empty' => false));
                 if ($categories) {
                     foreach ($categories as $category) {
                         if ($category->term_id) {
                             wp_delete_term($category->term_id, $term_taxonomy);
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $category->term_id));
                         }
                         if ($category->term_taxonomy_id) {
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = %d", $category->term_taxonomy_id));
                         }
                     }
                 }
                 $wpdb->query("DELETE FROM `" . $wpdb->prefix . "wpsc_meta` WHERE `object_type` = 'wpsc_category'");
                 $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '%s'", $term_taxonomy));
             }
             break;
         case 'tags':
             $term_taxonomy = 'product_tag';
             $tags = get_terms($term_taxonomy, array('hide_empty' => false));
             if ($tags) {
                 foreach ($tags as $tag) {
                     if ($tag->term_id) {
                         wp_delete_term($tag->term_id, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $tag->term_id));
                     }
                 }
             }
             break;
         case 'images':
             $post_type = 'wpsc-product';
             $products = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($products) {
                 $upload_dir = wp_upload_dir();
                 foreach ($products as $product) {
                     $args = array('post_type' => 'attachment', 'post_parent' => $product->ID, 'post_status' => 'inherit', 'post_mime_type' => 'image', 'numberposts' => -1);
                     $images = get_children($args);
                     if ($images) {
                         // $intermediate_sizes = wpsc_intermediate_image_sizes_advanced( $intermediate_sizes );
                         foreach ($images as $image) {
                             wp_delete_attachment($image->ID, true);
                             /*
                             								$image->filepath = dirname( $upload_dir['basedir'] . '/' . get_post_meta( $image->ID, '_wp_attached_file', true ) );
                             								chdir( $image->filepath );
                             								$image->filename = basename( get_post_meta( $image->ID, '_wp_attached_file', true ) );
                             								$image->extension = strrchr( $image->filename, '.' );
                             								$image->filebase = wpsc_st_remove_filename_extension( $image->filename );
                             								foreach( $intermediate_sizes as $intermediate_size ) {
                             									if( file_exists( $image->filebase . '-' . $intermediate_size['width'] . 'x' . $intermediate_size['height'] . $image->extension ) )
                             										@unlink( $image->filebase . '-' . $intermediate_size['width'] . 'x' . $intermediate_size['height'] . $image->extension );
                             								}
                             								if( file_exists( $image->filename ) )
                             									@unlink( basename( $image->filename ) );
                             								wp_delete_post( $image->ID );
                             */
                         }
                         unset($images, $image);
                     }
                 }
             }
             break;
         case 'files':
             $post_type = 'wpsc-product-file';
             $files = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($files) {
                 foreach ($files as $file) {
                     if ($file->ID) {
                         wp_delete_post($file->ID, true);
                     }
                 }
             }
             break;
         case 'orders':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_purchase_logs`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_cart_contents`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_submited_form_data`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_download_status`");
             $wpdb->query("DELETE FROM `" . $wpdb->prefix . "wpsc_meta` WHERE `object_type` = 'wpsc_cart_item'");
             break;
         case 'coupons':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "wpsc_coupon_codes`");
             break;
         case 'wpsc_pages':
             $wpsc_pages = array('[productspage]', '[shoppingcart]', '[transactionresults]', '[userlog]', '[download-manager]', '[order-tracking]');
             $size = count($wpsc_pages);
             for ($i = 0; $i < $sizes; $i++) {
                 if ($wpsc_pages[$i]) {
                     $post_id = wpsc_st_get_page_by_shortcode($wpsc_pages[$i]);
                     if ($post_id) {
                         wp_delete_post($wishlist->ID, true);
                     }
                 }
             }
             break;
         case 'wpsc_options':
             $options = array();
             $wpec_options_sql = "SELECT `option_name` FROM  `" . $wpdb->prefix . "options` WHERE  `option_name` LIKE  'wpec_%'";
             $wpec_options = $wpdb->get_results($wpec_options_sql);
             if ($wpec_options) {
                 foreach ($wpec_options as $wpec_option) {
                     $options[] = $wpec_option;
                 }
                 // $wpdb->query( "DELETE FROM `" . $wpdb->prefix . "options` WHERE `option_name` LIKE 'wpec_%'" );
             }
             $wpsc_options_sql = "SELECT `option_name` FROM  `" . $wpdb->prefix . "options` WHERE  `option_name` LIKE  'wpsc_%'";
             $wpsc_options = $wpdb->get_results($wpsc_options_sql);
             if ($wpsc_options) {
                 foreach ($wpsc_options as $wpsc_option) {
                     $options[] = $wpsc_option;
                 }
                 // $wpdb->query( "DELETE FROM `" . $wpdb->prefix . "options` WHERE `option_name` LIKE 'wpsc_%'" );
             }
             break;
             // 3rd Party
         // 3rd Party
         case 'wishlist':
             $post_type = 'wpsc-wishlist';
             $wishlists = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($wishlists) {
                 foreach ($wishlists as $wishlist) {
                     if (isset($wishlist->ID)) {
                         wp_delete_post($wishlist->ID, true);
                     }
                 }
             }
             break;
         case 'enquiries':
             $post_type = 'wpsc-enquiry';
             $enquiries = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($enquiries) {
                 foreach ($enquiries as $enquiry) {
                     if (isset($enquiry->ID)) {
                         wp_delete_post($enquiry->ID, true);
                     }
                 }
             }
             break;
         case 'credit-cards':
             $post_type = 'offline_payment';
             $credit_cards = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($credit_cards) {
                 foreach ($credit_cards as $credit_card) {
                     if (isset($credit_card->ID)) {
                         wp_delete_post($credit_card->ID, true);
                     }
                 }
             }
             break;
         case 'custom-fields':
             delete_option('wpsc_cf_data');
             break;
         case 'preview-files':
             $post_type = 'wpsc-preview-file';
             $preview_files = (array) get_posts(array('post_type' => $post_type, 'post_status' => 'inherit', 'numberposts' => -1));
             if ($preview_files) {
                 foreach ($preview_files as $preview_file) {
                     if (isset($preview_file->ID)) {
                         wp_delete_post($preview_file->ID, true);
                     }
                 }
             }
             break;
             // WordPress
         // WordPress
         case 'posts':
             $post_type = 'post';
             $posts = (array) get_posts(array('post_type' => $post_type, 'post_status' => wpsc_st_post_statuses(), 'numberposts' => -1));
             if ($posts) {
                 foreach ($posts as $post) {
                     if (isset($post->ID)) {
                         wp_delete_post($post->ID, true);
                     }
                 }
             }
             break;
         case 'post_categories':
             $term_taxonomy = 'category';
             $post_categories = get_terms($term_taxonomy, array('hide_empty' => false));
             if ($post_categories) {
                 foreach ($post_categories as $post_category) {
                     if ($post_category->term_id) {
                         wp_delete_term($post_category->term_id, $term_taxonomy);
                         $wpdb->query("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = " . $post_category->term_id);
                     }
                     if ($post_category->term_taxonomy_id) {
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = %d", $post_category->term_taxonomy_id));
                     }
                 }
             }
             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '%s'", $term_taxonomy));
             break;
         case 'post_tags':
             $term_taxonomy = 'post_tag';
             $post_tags = get_terms($term_taxonomy, array('hide_empty' => false));
             if ($post_tags) {
                 foreach ($post_tags as $post_tag) {
                     if ($post_tag->term_id) {
                         wp_delete_term($post_tag->term_id, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $post_tag->term_id));
                     }
                     if ($post_tag->term_taxonomy_id) {
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = %d", $post_tag->term_taxonomy_id));
                     }
                 }
             }
             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '%s'", $term_taxonomy));
             break;
         case 'links':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "links`");
             break;
         case 'comments':
             $comments = get_comments();
             if ($comments) {
                 foreach ($comments as $comment) {
                     if ($comment->comment_ID) {
                         wp_delete_comment($comment->comment_ID, true);
                     }
                 }
             }
             break;
     }
 }