NF_Upgrade_Database_Migrations

The Ninja Forms NF Upgrade Database Migrations class.

Defined (1)

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

/deprecated/includes/admin/upgrades/database-migrations.php  
  1. final class NF_Upgrade_Database_Migrations extends NF_Upgrade 
  2. public $name = 'database_migrations'; 
  3.  
  4. public $priority = "0.0.1"; 
  5.  
  6. public $description = 'The database needs to be updated to support the new version.'; 
  7.  
  8. public $args = array(); 
  9.  
  10. public $errors = array(); 
  11.  
  12. public function loading() 
  13. $already_run = $this->isComplete(); 
  14.  
  15. $this->total_steps = ( $already_run ) ? 0 : 1; 
  16.  
  17. public function step( $step ) 
  18. $this->createObjectTable(); 
  19. $this->createObjectMetaTable(); 
  20. $this->createObjectRelationshipsTable(); 
  21.  
  22. public function complete() 
  23. update_option( 'nf_database_migrations', true); 
  24.  
  25. public function isComplete() 
  26. if( $this->existsObjectTable() || 
  27. $this->existsObjectMetaTable() || 
  28. $this->existsObjectRelationshipsTable() 
  29. ) { 
  30. return true; 
  31. return get_option( 'nf_database_migrations', false ); 
  32.  
  33. /** 
  34. * PRIVATE METHODS 
  35. */ 
  36.  
  37. private function createObjectTable() 
  38. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  39.  
  40. $sql = "CREATE TABLE IF NOT EXISTS " . NF_OBJECTS_TABLE_NAME . " ( 
  41. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  42. `type` varchar(255) NOT NULL,  
  43. PRIMARY KEY (`id`) 
  44. ) DEFAULT CHARSET=utf8;"; 
  45.  
  46. dbDelta( $sql ); 
  47.  
  48. private function existsObjectTable() 
  49. global $wpdb; 
  50. return $wpdb->query( "SHOW TABLES LIKE '" . NF_OBJECTS_TABLE_NAME . "'" ); 
  51.  
  52.  
  53. private function createObjectMetaTable() 
  54. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  55.  
  56. $sql = "CREATE TABLE IF NOT EXISTS ". NF_OBJECT_META_TABLE_NAME . " ( 
  57. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  58. `object_id` bigint(20) NOT NULL,  
  59. `meta_key` varchar(255) NOT NULL,  
  60. `meta_value` longtext NOT NULL,  
  61. PRIMARY KEY (`id`) 
  62. ) DEFAULT CHARSET=utf8;"; 
  63.  
  64. dbDelta( $sql ); 
  65.  
  66. private function existsObjectMetaTable() 
  67. global $wpdb; 
  68. return $wpdb->query( "SHOW TABLES LIKE '" . NF_OBJECT_META_TABLE_NAME . "'" ); 
  69.  
  70. private function createObjectRelationshipsTable() 
  71. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  72.  
  73. $sql = "CREATE TABLE IF NOT EXISTS " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " ( 
  74. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  75. `child_id` bigint(20) NOT NULL,  
  76. `parent_id` bigint(20) NOT NULL,  
  77. `child_type` varchar(255) NOT NULL,  
  78. `parent_type` varchar(255) NOT NULL,  
  79. PRIMARY KEY (`id`) 
  80. ) DEFAULT CHARSET=utf8;"; 
  81.  
  82. dbDelta( $sql ); 
  83.  
  84. private function existsObjectRelationshipsTable() 
  85. global $wpdb; 
  86. return $wpdb->query( "SHOW TABLES LIKE '" . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . "'" );