NF_UpgradeHandler

Class NF_Upgrade_Handler.

Defined (1)

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

/deprecated/includes/admin/upgrades/class-upgrade-handler.php  
  1. class NF_UpgradeHandler 
  2. static $instance; 
  3.  
  4. public $upgrades; 
  5.  
  6. private $page; 
  7.  
  8. public static function instance() 
  9. if ( ! isset( self::$instance ) ) { 
  10. self::$instance = new NF_UpgradeHandler(); 
  11.  
  12. return self::$instance; 
  13.  
  14. public function __construct() 
  15.  
  16. if ( function_exists( 'ignore_user_abort' ) && ! nf_is_func_disabled( 'ignore_user_abort' ) ) { 
  17. ignore_user_abort( true ); 
  18.  
  19. $this->register_upgrades(); 
  20.  
  21. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { 
  22. add_action( 'wp_ajax_nf_upgrade_handler', array( $this, 'ajax_response' ) ); 
  23. return; 
  24. } else { 
  25. $this->page = new NF_UpgradeHandlerPage(); 
  26.  
  27.  
  28. public function register_upgrades() 
  29. $this->upgrades[] = new NF_Upgrade_Database_Migrations(); 
  30. $this->upgrades[] = new NF_Upgrade_Forms(); 
  31. $this->upgrades[] = new NF_Upgrade_Notifications(); 
  32. $this->upgrades[] = new NF_Upgrade_Submissions(); 
  33. $this->upgrades[] = new NF_Upgrade_Email_Settings(); 
  34.  
  35. $this->upgrades = apply_filters( 'nf_upgrade_handler_register', $this->upgrades ); 
  36.  
  37. usort( $this->upgrades, array( $this, 'compare_upgrade_priority' ) ) ; 
  38.  
  39. private function compare_upgrade_priority( $a, $b ) 
  40. return version_compare( $a->priority, $b->priority ); 
  41.  
  42. public function ajax_response() 
  43. $current_step = ( isset( $_REQUEST['step'] ) ) ? $_REQUEST['step'] : 0; 
  44.  
  45. $current_upgrade = $this->getUpgradeByName( $_REQUEST['upgrade'] ); 
  46.  
  47. $current_upgrade->total_steps = $_REQUEST['total_steps']; 
  48.  
  49. if( isset( $_REQUEST['args'] ) ) { 
  50. $current_upgrade->args = $_REQUEST['args']; 
  51.  
  52. if( 0 == $current_step ) { 
  53. $current_upgrade->loading(); 
  54.  
  55. $response = array( 
  56. 'upgrade' => $current_upgrade->name,  
  57. 'total_steps' => (int) $current_upgrade->total_steps,  
  58. 'args' => $current_upgrade->args,  
  59. ); 
  60.  
  61. if( 0 != $current_step ) { 
  62.  
  63. if (is_array($current_upgrade->errors) AND $current_upgrade->errors) { 
  64. $response['errors'] = $current_upgrade->errors; 
  65.  
  66. if ($current_upgrade->total_steps < $current_step ) { 
  67.  
  68. $current_upgrade->complete(); 
  69. $response['complete'] = TRUE; 
  70. $next_upgrade = $this->getNextUpgrade($current_upgrade); 
  71.  
  72. if ($next_upgrade) { 
  73. if( ! $next_upgrade->isComplete() ) { 
  74. $response['nextUpgrade'] = $next_upgrade->name; 
  75. } else { 
  76.  
  77. $current_upgrade->_step($current_step); 
  78.  
  79.  
  80.  
  81. $response['step'] = $current_step + 1; 
  82.  
  83. echo json_encode( $response ); 
  84. die(); 
  85.  
  86.  
  87.  
  88. /** 
  89. * UTILITY METHODS 
  90. */ 
  91.  
  92.  
  93.  
  94. public function getUpgradeByName( $name ) 
  95. foreach ( $this->upgrades as $index => $upgrade ) { 
  96. if ( $name == $upgrade->name ) { 
  97. return $upgrade; 
  98.  
  99. public function getNextUpgrade( $current_upgrade ) 
  100. foreach ( $this->upgrades as $index => $upgrade ) { 
  101. if ( $current_upgrade->name == $upgrade->name ) { 
  102.  
  103. if( isset( $this->upgrades[ $index + 1 ] ) ) { 
  104. return $this->upgrades[ $index + 1 ]; 
  105.  
  106. return FALSE;