PluginProbe
Media Cloud Sync / 1.0.1
Media Cloud Sync v1.0.1
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / base / db.php

db.php in Media Cloud Sync 1.0.1, at includes/base/db.php

89 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Dudlewebs\WPMCS;
3
4 defined('ABSPATH') || exit;
5
6 class Db {
7 private static $instance = null;
8 private string $assets_url;
9 private string $version;
10 private string $token;
11
12
13 /**
14 * Admin constructor.
15 * @since 1.0.0
16 */
17 public function __construct() {
18 $this->assets_url = WPMCS_ASSETS_URL;
19 $this->version = WPMCS_VERSION;
20 $this->token = WPMCS_TOKEN;
21 }
22
23 /**
24 * Create Database Table
25 *
26 */
27 public function create_table() {
28 global $wpdb;
29
30 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
31
32 $table_name = WPMCS_ITEM_TABLE;
33 $queries = array();
34 $charset_collate = $wpdb->get_charset_collate();
35 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
36 $queries[] = "
37 CREATE TABLE {$table_name} (
38 id BIGINT(20) NOT NULL AUTO_INCREMENT,
39 provider varchar(18) NOT NULL,
40 region varchar(255) NOT NULL,
41 storage varchar(255) NOT NULL,
42 source_id bigint(20) NOT NULL,
43 source_path varchar(1024) NOT NULL,
44 source_type varchar(18) NOT NULL,
45 url varchar(1024) NOT NULL,
46 `key` varchar(1024) NOT NULL,
47 is_private tinyint(1) NOT NULL DEFAULT 0,
48 extra longtext DEFAULT NULL,
49 PRIMARY KEY (id),
50 UNIQUE KEY uidx_url (url(190), id),
51 UNIQUE KEY uidx_key (`key`(190), id),
52 UNIQUE KEY uidx_source_path (source_path(190), id)
53 ) $charset_collate;";
54 }
55 dbDelta( $queries );
56 }
57
58 /**
59 * Database Upgrade
60 * @since 1.0.0
61 */
62 public function do_database_upgrade() {
63 global $wpdb;
64 $table_name = WPMCS_ITEM_TABLE;
65 $current_version = get_option( $this->token.'_db_version' );
66
67 switch($current_version) {
68 case '1.0.0': null;
69 break;
70 default: null;
71 }
72
73 update_option( $this->token.'_db_version', WPMCS_DB_VERSION, true );
74 }
75
76 /**
77 * Ensures only one instance of Class is loaded or can be loaded.
78 *
79 * @return Db Class instance
80 * @since 1.0.0
81 * @static
82 */
83 public static function instance(){
84 if (is_null(self::$instance)) {
85 self::$instance = new self();
86 }
87 return self::$instance;
88 }
89 }