⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upgrade-functions.php

📁 是一个优秀的语义个人发布平台
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php
// Functions to be called in install and upgrade scripts

function upgrade_all() {
	upgrade_071();
	upgrade_072();
	upgrade_100();
	upgrade_101();
	upgrade_110();
}

// General
function maybe_create_table($table_name, $create_ddl) {
    global $wpdb;
    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
        if ($table == $table_name) {
            return true;
        }
    }
    //didn't find it try to create it.
    $q = $wpdb->query($create_ddl);
    // we cannot directly tell that whether this succeeded!
    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
        if ($table == $table_name) {
            return true;
        }
    }
    return false;
}

function drop_index($table, $index) {
	global $wpdb;
	$wpdb->hide_errors();
	$wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
	// Now we need to take out all the extra ones we may have created
	for ($i = 0; $i < 25; $i++) {
		$wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
	}
	$wpdb->show_errors();
	return true;
}

function add_clean_index($table, $index) {
	global $wpdb;
	drop_index($table, $index);
	$wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
	return true;
}

/**
 ** maybe_add_column()
 ** Add column to db table if it doesn't exist.
 ** Returns:  true if already exists or on successful completion
 **           false on error
 */
function maybe_add_column($table_name, $column_name, $create_ddl) {
    global $wpdb, $debug;
    foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
        if ($debug) echo("checking $column == $column_name<br />");
        if ($column == $column_name) {
            return true;
        }
    }
    //didn't find it try to create it.
    $q = $wpdb->query($create_ddl);
    // we cannot directly tell that whether this succeeded!
    foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
        if ($column == $column_name) {
            return true;
        }
    }
    return false;
}

// .71 stuff

function upgrade_071() {
	global $tableposts;
	maybe_add_column($tableposts, 'post_status', "ALTER TABLE $tableposts ADD `post_status` ENUM('publish','draft','private') NOT NULL");
	maybe_add_column($tableposts, 'comment_status', "ALTER TABLE $tableposts ADD `comment_status` ENUM('open','closed') NOT NULL");
	maybe_add_column($tableposts, 'ping_status', "ALTER TABLE $tableposts ADD `ping_status` ENUM('open','closed') NOT NULL");
	maybe_add_column($tableposts, 'post_password', "ALTER TABLE $tableposts ADD post_password varchar(20) NOT NULL");
}

function upgrade_072() {
	global $wpdb, $tableposts, $tablelinks, $tablelinkcategories, $tableoptions, $tableoptiontypes, $tableoptiongroups, $tableoptiongroup_options, $tableoptionvalues, $tablecategories;
	maybe_add_column($tablelinks, 'link_notes', "ALTER TABLE $tablelinks ADD COLUMN link_notes MEDIUMTEXT NOT NULL DEFAULT '' ");
	maybe_add_column($tablelinkcategories, 'show_images', "ALTER TABLE $tablelinkcategories ADD COLUMN show_images enum('Y','N') NOT NULL default 'Y'");
	maybe_add_column($tablelinkcategories, 'show_description', "ALTER TABLE $tablelinkcategories ADD COLUMN show_description enum('Y','N') NOT NULL default 'Y'");
	maybe_add_column($tablelinkcategories, 'show_rating', "ALTER TABLE $tablelinkcategories ADD COLUMN show_rating enum('Y','N') NOT NULL default 'Y'");
	maybe_add_column($tablelinkcategories, 'show_updated', "ALTER TABLE $tablelinkcategories ADD COLUMN show_updated enum('Y','N') NOT NULL default 'Y'");
	maybe_add_column($tablelinkcategories, 'sort_order', "ALTER TABLE $tablelinkcategories ADD COLUMN sort_order varchar(64) NOT NULL default 'name'");
	maybe_add_column($tablelinkcategories, 'sort_desc', "ALTER TABLE $tablelinkcategories ADD COLUMN sort_desc enum('Y','N') NOT NULL default 'N'");
	maybe_add_column($tablelinkcategories, 'text_before_link', "ALTER TABLE $tablelinkcategories ADD COLUMN text_before_link varchar(128) not null default '<li>'");
	maybe_add_column($tablelinkcategories, 'text_after_link', "ALTER TABLE $tablelinkcategories ADD COLUMN text_after_link  varchar(128) not null default '<br />'");
	maybe_add_column($tablelinkcategories, 'text_after_all', "ALTER TABLE $tablelinkcategories ADD COLUMN text_after_all  varchar(128) not null default '</li>'");
	maybe_add_column($tablelinkcategories, 'list_limit', "ALTER TABLE $tablelinkcategories ADD COLUMN list_limit int not null default -1");
	maybe_add_column($tableposts, 'post_lon', "ALTER TABLE $tableposts ADD COLUMN post_lon float");
	maybe_add_column($tableposts, 'post_lat', "ALTER TABLE $tableposts ADD COLUMN post_lat float ");
	maybe_create_table($tableoptions, "
	CREATE TABLE $tableoptions (
	  option_id int(11) NOT NULL auto_increment,
	  blog_id int(11) NOT NULL default 0,
	  option_name varchar(64) NOT NULL default '',
	  option_can_override enum('Y','N') NOT NULL default 'Y',
	  option_type int(11) NOT NULL default 1,
	  option_value varchar(255) NOT NULL default '',
	  option_width int NOT NULL default 20,
	  option_height int NOT NULL default 8,
	  option_description tinytext NOT NULL default '',
	  option_admin_level int NOT NULL DEFAULT '1',
	  PRIMARY KEY (option_id, blog_id, option_name)
	)
	");
	maybe_create_table($tableoptiontypes, "
	CREATE TABLE $tableoptiontypes (
	  optiontype_id int(11) NOT NULL auto_increment,
	  optiontype_name varchar(64) NOT NULL,
	  PRIMARY KEY (optiontype_id)
	)
	");
	maybe_create_table($tableoptiongroups, "
	CREATE TABLE $tableoptiongroups (
	  group_id int(11) NOT NULL auto_increment,
	  group_name varchar(64) not null,
	  group_desc varchar(255),
	  group_longdesc tinytext,
	  PRIMARY KEY (group_id)
	)
	");
	maybe_create_table($tableoptiongroup_options, "
	CREATE TABLE $tableoptiongroup_options (
	  group_id int(11) NOT NULL,
	  option_id int(11) NOT NULL,
	  seq int(11) NOT NULL,
	  PRIMARY KEY (group_id, option_id)
	)
	");
	maybe_create_table($tableoptionvalues, "
	CREATE TABLE $tableoptionvalues (
	  option_id int(11) NOT NULL,
	  optionvalue tinytext,
	  optionvalue_desc varchar(255),
	  optionvalue_max int(11),
	  optionvalue_min int(11),
	  optionvalue_seq int(11),
	  UNIQUE (option_id, optionvalue(255)),
	  INDEX (option_id, optionvalue_seq)
	)
	");
	
	// TODO: REWRITE THIS
	$option_types = array(
		"1" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('1', 'integer')",
		"2" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('2', 'boolean')",
		"3" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('3', 'string')",
		"4" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('4', 'date')",
		"5" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('5', 'select')",
		"6" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('6', 'range')",
		"7" => "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES ('7', 'sqlselect')");

	foreach ($option_types as $option_id => $query) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -