WC_QuickPay_Install

WC_QuickPay_Install class.

Defined (1)

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

/classes/woocommerce-quickpay-install.php  
  1. class WC_QuickPay_Install  
  2. /** 
  3. * Contains version numbers and the path to the update files. 
  4. */ 
  5. private static $updates = array( 
  6. '4.3' => 'updates/woocommerce-quickpay-update-4.3.php',  
  7. '4.6' => 'updates/woocommerce-quickpay-update-4.6.php' 
  8. ); 
  9.  
  10.  
  11. /** 
  12. * Updates the version.  
  13. *  
  14. * @param string $version = NULL - The version number to update to 
  15. */ 
  16. private static function update_db_version( $version = NULL ) 
  17. delete_option( 'woocommerce_quickpay_version' ); 
  18. add_option( 'woocommerce_quickpay_version', $version === NULL ? WCQP_VERSION : $version ); 
  19.  
  20.  
  21. /** 
  22. * Get the current DB version stored in the database. 
  23. *  
  24. * @return string - the stored version number. 
  25. */ 
  26. public static function get_db_version()  
  27. return get_option( 'woocommerce_quickpay_version', TRUE );  
  28.  
  29.  
  30. /** 
  31. * Checks if this is the first install. 
  32. *  
  33. * @return bool 
  34. */ 
  35. public static function is_first_install()  
  36. $settings = get_option( 'woocommerce_quickpay_settings', FALSE );  
  37. return $settings === FALSE; 
  38.  
  39.  
  40. /** 
  41. * Runs on first install 
  42. */ 
  43. public static function install() 
  44. // Install... 
  45.  
  46.  
  47. /** 
  48. * Loops through the updates and executes them. 
  49. */ 
  50. public static function update()  
  51. // Don't lock up other requests while processing 
  52. session_write_close(); 
  53.  
  54. self::start_maintenance_mode(); 
  55.  
  56. foreach ( self::$updates as $version => $updater ) { 
  57. if ( self::is_update_required($version) ) { 
  58. include( $updater ); 
  59. self::update_db_version( $version ); 
  60.  
  61. self::update_db_version( WCQP_VERSION ); 
  62.  
  63. self::stop_maintenance_mode(); 
  64.  
  65. /** 
  66. * Checks if the current database version is outdated 
  67. * @param null $version 
  68. * @return mixed 
  69. */ 
  70. public static function is_update_required( $version = NULL ) 
  71. $version = self::get_db_version(); 
  72.  
  73. foreach( self::$updates as $update_version => $update_file ) { 
  74. if (version_compare($version, $update_version, '<')) { 
  75. return TRUE; 
  76.  
  77. return FALSE; 
  78.  
  79. /** 
  80. * Checks if in maintenance mode 
  81. * @return bool 
  82. */ 
  83. public static function is_in_maintenance_mode() 
  84. return get_option( 'woocommerce_quickpay_maintenance', FALSE ); 
  85.  
  86. /** 
  87. * Enables maintenance mode 
  88. */ 
  89. public static function start_maintenance_mode() 
  90. add_option('woocommerce_quickpay_maintenance', TRUE, '', 'yes'); 
  91.  
  92. /** 
  93. * Disables maintenance mode 
  94. */ 
  95. public static function stop_maintenance_mode() 
  96. delete_option('woocommerce_quickpay_maintenance'); 
  97.  
  98. /** 
  99. * Shows an admin notice informing about required database migrations. 
  100. */ 
  101. public static function show_update_warning() 
  102. if (self::is_update_required()) { 
  103. if (!self::is_in_maintenance_mode()) { 
  104. WC_QuickPay_Views::get_view('html-notice-update.php'); 
  105. } else { 
  106. WC_QuickPay_Views::get_view('html-notice-upgrading.php'); 
  107.  
  108. /** 
  109. * Asynchronous data upgrader acction 
  110. */ 
  111. public static function ajax_run_upgrader() 
  112. $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : NULL; 
  113.  
  114. if (!wp_verify_nonce($nonce, 'woocommerce-quickpay-run-upgrader-nonce') && !current_user_can('administrator')) 
  115. echo json_encode(array('status' => 'error', 'message' => __('You are not authorized to perform this action', 'woo-quickpay') ) ); 
  116. exit; 
  117.  
  118. self::update(); 
  119.  
  120. echo json_encode(array('status' => 'success')); 
  121.  
  122. exit; 
  123.  
  124. /** 
  125. * Creates a nonce 
  126. * @return string - the nonce 
  127. */ 
  128. public static function create_run_upgrader_nonce() 
  129. return wp_create_nonce("woocommerce-quickpay-run-upgrader-nonce");