/deprecated/includes/admin/upgrades/database-migrations.php

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