WJECF_Admin_Auto_Upgrade

The WooCommerce Extended Coupon Features WJECF Admin Auto Upgrade class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/wjecf-admin-auto-upgrade.php  
  1. class WJECF_Admin_Auto_Upgrade extends Abstract_WJECF_Plugin { 
  2.  
  3. public function __construct() {  
  4. $this->set_plugin_data( array( 
  5. 'description' => __( 'Automatically upgrade data when a new version of this plugin is installed.', 'woocommerce-jos-autocoupon' ),  
  6. 'dependencies' => array(),  
  7. 'can_be_disabled' => true 
  8. ) );  
  9.  
  10. public function init_admin_hook() { 
  11. $this->auto_upgrade(); 
  12.  
  13. //Upgrade options on version change 
  14. public function auto_upgrade() { 
  15. if ( ! class_exists('WC_Coupon') ) { 
  16. return; 
  17.  
  18. //WJECF()->options['db_version'] = 1;update_option( 'wjecf_options' , WJECF()->options, false ); // Will force all upgrades 
  19. global $wpdb; 
  20. $prev_version = WJECF()->options['db_version']; 
  21.  
  22. //DB_VERSION 1: Since 2.1.0-b5 
  23. if ( WJECF()->options['db_version'] < 1 ) { 
  24. //RENAME meta_key _wjecf_matching_product_qty TO _wjecf_min_matching_product_qty 
  25. $where = array("meta_key" => "_wjecf_matching_product_qty"); 
  26. $set = array('meta_key' => "_wjecf_min_matching_product_qty"); 
  27. $wpdb->update( _get_meta_table('post'), $set, $where ); 
  28.  
  29. //RENAME meta_key woocommerce-jos-autocoupon TO _wjecf_is_auto_coupon 
  30. $where = array("meta_key" => "woocommerce-jos-autocoupon"); 
  31. $set = array('meta_key' => "_wjecf_is_auto_coupon"); 
  32. $wpdb->update( _get_meta_table('post'), $set, $where );  
  33. //Now we're version 1 
  34. WJECF()->options['db_version'] = 1; 
  35. } //DB VERSION 1 
  36.  
  37. //DB_VERSION 2: Since 2.3.3-b3 No changes; but used to omit message if 2.3.3-b3 has been installed before 
  38. if ( WJECF()->options['db_version'] < 2 ) { 
  39. WJECF()->options['db_version'] = 2; 
  40.  
  41. if ( WJECF()->options['db_version'] > 2 ) { 
  42. WJECF_ADMIN()->enqueue_notice( '<p>' . __( '<strong>WooCommerce Extended Coupon Features:</strong> Please note, you\'re using an older version of this plugin, while the data was upgraded to a newer version.' , 'woocommerce-jos-autocoupon' ) . '</p>', 'notice-warning'); 
  43.  
  44. //An upgrade took place? 
  45. if ( WJECF()->options['db_version'] != $prev_version ) {  
  46. // Set version and write options to database 
  47. update_option( 'wjecf_options' , WJECF()->options, false ); 
  48.  
  49. WJECF_ADMIN()->enqueue_notice( '<p>' . __( '<strong>WooCommerce Extended Coupon Features:</strong> Data succesfully upgraded to the newest version.', 'woocommerce-jos-autocoupon' ) . '</p>', 'notice-success'); 
  50. }  
  51.  
  52. // function admin_notice_allow_cart_excluded() { 
  53.  
  54. // if( ! empty( $this->admin_notice_allow_cart_excluded_couponcodes ) ) 
  55. // { 
  56. // $html = '<div class="notice notice-warning">'; 
  57. // $html .= '<p>'; 
  58. // $html .= __( '<strong>WooCommerce Extended Coupon Features:</strong> The following coupons use the deprecated option \'Allow discount on cart with excluded items\'. Please review and save them.', 'woocommerce-jos-autocoupon' ); 
  59. // $html .= '<ul>'; 
  60. // foreach( $this->admin_notice_allow_cart_excluded_couponcodes as $post_id => $coupon_code ) {  
  61. // $html .= '<li><a class="post-edit-link" href="' . esc_url( get_edit_post_link( $post_id ) ) . '">' . $coupon_code . '</a></li>'; 
  62. // } 
  63. // $html .= '</ul>';  
  64. // $html .= '</p>'; 
  65. // $html .= '</div>'; 
  66. // echo $html; 
  67. // } 
  68. // }