/**
  * Perform any version-related changes. Changes to custom db tables should be handled by the migrate() method
  *
  * @since 3.0
  * @see SV_WC_Plugin::upgrade()
  * @param int $installed_version the currently installed version of the plugin
  */
 protected function upgrade($installed_version)
 {
     if (version_compare($installed_version, "3.0", '<')) {
         global $wpdb;
         require_once 'classes/class-wc-price-calculator-settings.php';
         // updating 3.0: From 2.0 to 3.0, the '_wc_price_calculator'
         // product post meta calculator settings structure changed: 'calculator'
         // was added to the 'pricing' option
         $rows = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key='_wc_price_calculator'");
         foreach ($rows as $row) {
             if ($row->meta_value) {
                 // calculator settings found
                 $settings = new WC_Price_Calculator_Settings();
                 $settings = $settings->set_raw_settings($row->meta_value);
                 // we want the updated underlying raw settings array
                 $updated = false;
                 foreach (WC_Price_Calculator_Settings::get_measurement_types() as $measurement_type) {
                     if (isset($settings[$measurement_type]['pricing']['enabled']) && 'yes' == $settings[$measurement_type]['pricing']['enabled']) {
                         // enable the pricing calculator in the new settings data structure
                         $settings[$measurement_type]['pricing']['calculator'] = array('enabled' => 'yes');
                         $updated = true;
                     }
                 }
                 if ($updated) {
                     update_post_meta($row->post_id, '_wc_price_calculator', $settings);
                 }
             }
         }
     }
 }