Plugin Directory

Changeset 2388816


Ignore:
Timestamp:
09/26/2020 11:20:41 AM (6 years ago)
Author:
webinnane
Message:

database upgradation

Location:
lifeline-donation/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lifeline-donation/trunk/lifeline-donation.php

    r2388812 r2388816  
    4949            require_once LIFELINE_DONATION_PATH . 'webinane-commerce/webinane-commerce.php';
    5050        }
    51         WebinaneCommerce\Admin\Install::init();
     51        \WebinaneCommerce\Admin\Install::init();
    5252    }
    5353);
     54
     55add_action( 'upgrader_process_complete', function( $upgrader_object, $options ) {
     56    $current_plugin_path_name = plugin_basename( __FILE__ );
     57
     58    if ($options['action'] == 'update' && $options['type'] == 'plugin' ){
     59       if( isset($options['plugins'])) {
     60           foreach($options['plugins'] as $each_plugin){
     61              if ( $each_plugin == $current_plugin_path_name){
     62                \WebinaneCommerce\Classes\Webinane::update_database();
     63              }
     64           }
     65       } elseif( isset($options['plugin']) ) {
     66            if ( $options['plugin'] == $current_plugin_path_name ) {
     67                \WebinaneCommerce\Classes\Webinane::update_database();
     68            }
     69       }
     70    }
     71},10, 2);
  • lifeline-donation/trunk/webinane-commerce/includes/Classes/Webinane.php

    r2388812 r2388816  
    243243           }
    244244        }
    245         $settings = get_option('_wpcommerce_settings');
     245       
     246    }
     247
     248    /**
     249     * Update database.
     250     * @return [type] [description]
     251     */
     252    static function update_database() {
     253        global $wpdb;
     254
     255        $result = $wpdb->get_results("SHOW COLUMNS FROM `{$wpdb->prefix}wpcommerce_order_items` LIKE 'base_price'");
     256
     257        if( ! $result ) {
     258            $wpdb->query("ALTER TABLE {$wpdb->prefix}wpcommerce_order_items ADD base_price float DEFAULT '0'");
     259            $wpdb->query("ALTER TABLE {$wpdb->prefix}wpcommerce_order_items ADD currency varchar(3) DEFAULT 'USD'");
     260        }
     261
     262        $settings = get_option('_wpcommerce_settings');
    246263        if(! isset($settings['gateways'])) {
    247264            $settings['base_country'] = ['country' => $settings['base_country'], 'state' => $settings['base_state']];
     
    271288    }
    272289
    273     /**
    274      * Update database.
    275      * @return [type] [description]
    276      */
    277     static function update_database() {
    278         global $wpdb;
    279 
    280         $result = $wpdb->get_results("SHOW COLUMNS FROM `{$wpdb->prefix}wpcommerce_order_items` LIKE 'base_price'");
    281 
    282         if( ! $result ) {
    283             $wpdb->query("ALTER TABLE {$wpdb->prefix}wpcommerce_order_items ADD base_price float DEFAULT '0'");
    284             $wpdb->query("ALTER TABLE {$wpdb->prefix}wpcommerce_order_items ADD currency varchar(3) DEFAULT 'USD'");
    285         }
    286     }
    287 
    288290
    289291}
Note: See TracChangeset for help on using the changeset viewer.