gde_db_tables

Create/update database table to store profile data.

Description

gde_db_tables( $gde_db_ver ); 

Parameters (1)

0. $gde_db_ver
The gde db ver.

Usage

  1. if ( !function_exists( 'gde_db_tables' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/libs/lib-setup.php'; 
  3.  
  4. // The gde db ver. 
  5. $gde_db_ver = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gde_db_tables($gde_db_ver); 
  9.  

Defined (1)

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

/libs/lib-setup.php  
  1. function gde_db_tables( $gde_db_ver ) { 
  2. global $wpdb; 
  3.  
  4. // attempt to trap table creation failures 
  5. $fails = 0; 
  6.  
  7. // check for missing required tables (clear db version) 
  8. $table = $wpdb->prefix . 'gde_profiles'; 
  9. if ($wpdb->get_var( "SHOW TABLES LIKE '$table'" ) !== $table) { 
  10. //gde_dx_log("profiles db failed health check"); 
  11. delete_site_option( 'gde_db_version' ); 
  12.  
  13. $table = $wpdb->prefix . 'gde_secure'; 
  14. if ($wpdb->get_var( "SHOW TABLES LIKE '$table'" ) !== $table) { 
  15. //gde_dx_log("securedoc db failed health check"); 
  16. delete_site_option( 'gde_db_version' ); 
  17.  
  18. if ( is_multisite() ) { 
  19. $db_ver_installed = get_site_option( 'gde_db_version', 0 ); 
  20. } else { 
  21. $db_ver_installed = get_option( 'gde_db_version', 0 ); 
  22.  
  23. gde_dx_log("Installed DB ver: $db_ver_installed; This DB ver: " . $gde_db_ver ); 
  24. if ( version_compare( $gde_db_ver, $db_ver_installed, ">" ) ) { 
  25. // install or upgrade profile table 
  26. $table = $wpdb->prefix . 'gde_profiles'; 
  27.  
  28. $sql = "CREATE TABLE " . $table . " ( 
  29. profile_id mediumint(9) UNSIGNED NOT NULL AUTO_INCREMENT,  
  30. profile_name varchar(64) NOT NULL,  
  31. profile_desc varchar(255) NULL,  
  32. profile_data longtext NOT NULL,  
  33. UNIQUE KEY (profile_id) 
  34. ) ENGINE=MyISAM DEFAULT CHARSET=utf8; "; 
  35.  
  36. if ( isset( $sql ) ) { 
  37. // write table or update to database 
  38. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  39. dbDelta($sql); 
  40.  
  41. if ($wpdb->get_var( "SHOW TABLES LIKE '$table'" ) == $table ) { 
  42. gde_dx_log("Profile table create/update successful"); 
  43. } else { 
  44. gde_dx_log("Profile table create/update failed"); 
  45. $fails++; 
  46.  
  47. // install or upgrade securedoc table 
  48. $table = $wpdb->prefix . 'gde_secure'; 
  49. $sql = "CREATE TABLE " . $table . " ( 
  50. code varchar(10) NOT NULL,  
  51. url varchar(255) NOT NULL,  
  52. murl varchar(100) NOT NULL,  
  53. stamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  
  54. autoexpire enum('Y', 'N') NOT NULL DEFAULT 'N',  
  55. UNIQUE KEY code (code) 
  56. ) ENGINE=MyISAM DEFAULT CHARSET=utf8; "; 
  57.  
  58. if ( isset( $sql ) ) { 
  59. // write table or update to database 
  60. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  61. dbDelta( $sql ); 
  62.  
  63. if ( $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) == $table ) { 
  64. gde_dx_log("Secure doc table create/update successful"); 
  65. } else { 
  66. gde_dx_log("Secure doc table create/update failed"); 
  67. $fails++; 
  68. } else { 
  69. gde_dx_log("Tables OK, nothing to do"); 
  70.  
  71. if ( $fails > 0 ) { 
  72. delete_site_option( 'gde_db_version' ); 
  73. return false; 
  74. } else { 
  75. update_site_option( 'gde_db_version', $gde_db_ver ); 
  76. return true;