Ejemplo n.º 1
0
 public static function do_upgrade($to_version)
 {
     global $wpdb;
     if ($to_version === '1.1.3') {
         $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD view_order INT COLLATE utf8_general_ci NULL DEFAULT 0;");
     } else {
         if ($to_version === '2.0.0') {
             $views = $wpdb->get_results("SELECT * FROM " . FPD_VIEWS_TABLE . " GROUP BY product_id");
             foreach ($views as $view) {
                 //check if product exists, otherwise delete it from views table
                 if (get_post_status($view->product_id) === false) {
                     $wpdb->query($wpdb->prepare("DELETE FROM " . FPD_VIEWS_TABLE . " WHERE product_id=%d", $view->product_id));
                 } else {
                     $check_title = get_the_title($view->product_id);
                     if (!empty($check_title)) {
                         $product_id = Fancy_Product::create($check_title);
                         //create product
                         $fancy_product_settings = new FPD_Product_Settings($view->product_id);
                         //get stage dimensions and add them in the product options
                         $product_options = array();
                         if ($fancy_product_settings->get_individual_option('stage_width')) {
                             $product_options['stage_width'] = $fancy_product_settings->get_individual_option('stage_width');
                         }
                         if ($fancy_product_settings->get_individual_option('stage_height')) {
                             $product_options['stage_height'] = $fancy_product_settings->get_individual_option('stage_height');
                         }
                         $fancy_product = new Fancy_Product($product_id);
                         if (sizeof($product_options) !== 0) {
                             $fancy_product->update(null, json_encode($product_options));
                         }
                         //assign product to wc product
                         update_post_meta($view->product_id, 'fpd_source_type', 'product');
                         $product_array = array($product_id);
                         update_post_meta($view->product_id, 'fpd_products', $product_array);
                         //update product id of views
                         $wpdb->update(FPD_VIEWS_TABLE, array('product_id' => $product_id), array('product_id' => $view->product_id), array('%d'), array('%d'));
                     }
                 }
             }
             //add options to views table
             $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD options TEXT COLLATE utf8_general_ci NULL DEFAULT '';");
         }
     }
 }