| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit; |
| 3 |
|
| 4 |
if(!class_exists('Vision_Activator')) : |
| 5 |
|
| 6 |
class Vision_Activator { |
| 7 |
public function activate() { |
| 8 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 9 |
|
| 10 |
global $wpdb; |
| 11 |
$charsetCollate = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : ''; |
| 12 |
|
| 13 |
$table = $wpdb->prefix . VISION_PLUGIN_NAME; |
| 14 |
$sql = "CREATE TABLE {$table} ( |
| 15 |
id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 16 |
title text DEFAULT NULL, |
| 17 |
slug varchar(200) DEFAULT NULL, |
| 18 |
active tinyint NOT NULL DEFAULT 1, |
| 19 |
data longtext DEFAULT NULL, |
| 20 |
config longtext DEFAULT NULL, |
| 21 |
author bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 22 |
editor bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 23 |
deleted tinyint NOT NULL DEFAULT 0, |
| 24 |
created datetime NOT NULL, |
| 25 |
modified datetime NOT NULL, |
| 26 |
UNIQUE KEY id (id) |
| 27 |
) {$charsetCollate};"; |
| 28 |
dbDelta($sql); |
| 29 |
|
| 30 |
update_option('vision_db_version', VISION_DB_VERSION, false); |
| 31 |
|
| 32 |
$this->update_data(); |
| 33 |
if(get_option('vision_activated') == false ) { |
| 34 |
$this->install_data(); |
| 35 |
} |
| 36 |
update_option('vision_activated', time(), false); |
| 37 |
} |
| 38 |
|
| 39 |
public function update_data() { |
| 40 |
global $wpdb; |
| 41 |
$table = $wpdb->prefix . VISION_PLUGIN_NAME; |
| 42 |
|
| 43 |
// Add the new column 'deleted' |
| 44 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 45 |
$row = $wpdb->get_results($wpdb->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name=%s AND column_name='deleted'", $table)); |
| 46 |
if(empty($row)) { |
| 47 |
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 48 |
$sql = "ALTER TABLE {$table} ADD deleted tinyint NOT NULL DEFAULT 0"; |
| 49 |
$wpdb->query($sql); |
| 50 |
// phpcs:enable |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public function install_data() { |
| 55 |
} |
| 56 |
|
| 57 |
public function check_db() { |
| 58 |
if(get_option('vision_db_version') != VISION_DB_VERSION ) { |
| 59 |
$this->activate(); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
endif; |