| 1 |
<?php |
| 2 |
namespace FileBird; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Install { |
| 7 |
public static function create_tables() { |
| 8 |
global $wpdb; |
| 9 |
|
| 10 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 11 |
|
| 12 |
$charset_collate = $wpdb->get_charset_collate(); |
| 13 |
|
| 14 |
$table_fbv = $wpdb->prefix . 'fbv'; |
| 15 |
//type == 0: folder |
| 16 |
//type == 1: collection |
| 17 |
if ( $wpdb->get_var( "show tables like '{$wpdb->prefix}fbv'" ) != $table_fbv ) { |
| 18 |
$sql = 'CREATE TABLE ' . $table_fbv . ' ( |
| 19 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 20 |
`name` varchar(250) NOT NULL, |
| 21 |
`parent` int(11) NOT NULL DEFAULT 0, |
| 22 |
`type` int(2) NOT NULL DEFAULT 0, |
| 23 |
`ord` int(11) NULL DEFAULT 0, |
| 24 |
`created_by` int(11) NULL DEFAULT 0, |
| 25 |
PRIMARY KEY (id), |
| 26 |
UNIQUE KEY `id` (id)) ' . $charset_collate . ';'; |
| 27 |
dbDelta( $sql ); |
| 28 |
} |
| 29 |
|
| 30 |
$table = $wpdb->prefix . 'fbv_attachment_folder'; |
| 31 |
//type == 0: folder |
| 32 |
//type == 1: collection |
| 33 |
if ( $wpdb->get_var( "show tables like '{$wpdb->prefix}fbv_attachment_folder'" ) != $table ) { |
| 34 |
$sql = 'CREATE TABLE ' . $table . ' ( |
| 35 |
`folder_id` int(11) unsigned NOT NULL, |
| 36 |
`attachment_id` bigint(20) unsigned NOT NULL, |
| 37 |
PRIMARY KEY( `folder_id`, `attachment_id`) |
| 38 |
)' . $charset_collate . ';'; |
| 39 |
dbDelta( $sql ); |
| 40 |
} |
| 41 |
} |
| 42 |
} |