예제 #1
0
 /**
  * Create the table
  *
  * @access  public
  * @since   1.6
  */
 public function create_table()
 {
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     if (version_compare($this->installed_version(), $this->version, '!=')) {
         $sql = "CREATE TABLE {$this->get_table_name()} (\n\t\t\t\t  id int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t  account_id bigint(20) NOT NULL,\n\t\t\t\t  image_id varchar(256) NOT NULL,\n\t\t\t\t  image_timestamp bigint(20) NOT NULL,\n\t\t\t\t  status enum('pending','posted','ignore','posting', 'moderate') NOT NULL,\n\t\t\t\t  media_type varchar(50) NOT NULL,\n\t\t\t\t  image_url varchar(256) NOT NULL,\n\t\t\t\t  image_thumb_url varchar(256) NOT NULL,\n\t\t\t\t  video_url varchar(256) NOT NULL,\n\t\t\t\t  tags text NULL,\n\t\t\t\t  filter varchar(256) NULL,\n\t\t\t\t  link varchar(256) NULL,\n\t\t\t\t  caption text NULL,\n\t\t\t\t  caption_clean text NULL,\n\t\t\t\t  caption_clean_no_tags text NULL,\n\t\t\t\t  username text NULL,\n\t\t\t\t  user_id varchar(256) NULL,\n\t\t\t\t  user_image_url text NULL,\n\t\t\t\t  latitude varchar(256) NULL,\n\t\t\t\t  longitude varchar(256) NULL,\n\t\t\t\t  location_name text NULL,\n\t\t\t\t  location_id varchar(256) NULL,\n\t\t\t\t  comments_count bigint(20) NOT NULL,\n\t\t\t\t  comments longblob NOT NULL,\n\t\t\t\t  likes_count bigint(20) NOT NULL,\n\t\t\t\t  UNIQUE KEY (id)\n\t\t\t) DEFAULT CHARACTER SET utf8;";
         dbDelta($sql);
         global $wpdb;
         if ('utf8mb4' === $wpdb->charset && function_exists('maybe_convert_table_to_utf8mb4')) {
             maybe_convert_table_to_utf8mb4($this->get_table_name());
         }
         update_option($this->option_key, $this->version);
     }
 }
예제 #2
0
/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always.
    if (is_main_network()) {
        /*
         * Deletes all expired transients. The multi-table delete syntax is used
         * to delete the transient record from table a, and the corresponding
         * transient_timeout record from table b.
         */
        $time = time();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $time));
    }
    // 2.8.
    if ($wp_current_db_version < 11549) {
        $wpmu_sitewide_plugins = get_site_option('wpmu_sitewide_plugins');
        $active_sitewide_plugins = get_site_option('active_sitewide_plugins');
        if ($wpmu_sitewide_plugins) {
            if (!$active_sitewide_plugins) {
                $sitewide_plugins = (array) $wpmu_sitewide_plugins;
            } else {
                $sitewide_plugins = array_merge((array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins);
            }
            update_site_option('active_sitewide_plugins', $sitewide_plugins);
        }
        delete_site_option('wpmu_sitewide_plugins');
        delete_site_option('deactivated_sitewide_plugins');
        $start = 0;
        while ($rows = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT {$start}, 20")) {
            foreach ($rows as $row) {
                $value = $row->meta_value;
                if (!@unserialize($value)) {
                    $value = stripslashes($value);
                }
                if ($value !== $row->meta_value) {
                    update_site_option($row->meta_key, $value);
                }
            }
            $start += 20;
        }
    }
    // 3.0
    if ($wp_current_db_version < 13576) {
        update_site_option('global_terms_enabled', '1');
    }
    // 3.3
    if ($wp_current_db_version < 19390) {
        update_site_option('initial_db_version', $wp_current_db_version);
    }
    if ($wp_current_db_version < 19470) {
        if (false === get_site_option('active_sitewide_plugins')) {
            update_site_option('active_sitewide_plugins', array());
        }
    }
    // 3.4
    if ($wp_current_db_version < 20148) {
        // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
        $allowedthemes = get_site_option('allowedthemes');
        $allowed_themes = get_site_option('allowed_themes');
        if (false === $allowedthemes && is_array($allowed_themes) && $allowed_themes) {
            $converted = array();
            $themes = wp_get_themes();
            foreach ($themes as $stylesheet => $theme_data) {
                if (isset($allowed_themes[$theme_data->get('Name')])) {
                    $converted[$stylesheet] = true;
                }
            }
            update_site_option('allowedthemes', $converted);
            delete_site_option('allowed_themes');
        }
    }
    // 3.5
    if ($wp_current_db_version < 21823) {
        update_site_option('ms_files_rewriting', '1');
    }
    // 3.5.2
    if ($wp_current_db_version < 24448) {
        $illegal_names = get_site_option('illegal_names');
        if (is_array($illegal_names) && count($illegal_names) === 1) {
            $illegal_name = reset($illegal_names);
            $illegal_names = explode(' ', $illegal_name);
            update_site_option('illegal_names', $illegal_names);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (!(defined('DO_NOT_UPGRADE_GLOBAL_TABLES') && DO_NOT_UPGRADE_GLOBAL_TABLES)) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.2.2
    if ($wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset) {
        if (!(defined('DO_NOT_UPGRADE_GLOBAL_TABLES') && DO_NOT_UPGRADE_GLOBAL_TABLES)) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
        }
    }
}
예제 #3
0
 function upgrade()
 {
     global $wpdb, $charset_collate;
     parent::upgrade();
     $this->upgrade_query("create table if not exists " . NEWSLETTER_EMAILS_TABLE . " (id int auto_increment, primary key (id)) {$charset_collate}");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column message longtext");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column message_text longtext");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column subject varchar(255) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column type varchar(50) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column created timestamp not null default current_timestamp");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column status enum('new','sending','sent','paused') not null default 'new'");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column total int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column last_id int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column sent int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column send_on int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column track tinyint not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column editor tinyint not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column sex char(1) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " change column sex sex char(1) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column query text");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column preferences text");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column options longtext");
     // Cleans up old installations
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " drop column name");
     $this->upgrade_query("drop table if exists " . $wpdb->prefix . "newsletter_work");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " convert to character set utf8");
     if ($charset_collate != 'utf8mb4') {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         if (function_exists('maybe_convert_table_to_utf8mb4')) {
             maybe_convert_table_to_utf8mb4(NEWSLETTER_EMAILS_TABLE);
         }
     }
     // Some setting check to avoid the common support request for mis-configurations
     $options = $this->get_options();
     if (empty($options['sender_email'])) {
         // That code was taken from WordPress
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         // WordPress build an address in the same way using wordpress@...
         $options['sender_email'] = 'newsletter@' . $sitename;
         $this->save_options($options);
     }
     if (empty($options['scheduler_max']) || !is_numeric($options['scheduler_max'])) {
         $options['scheduler_max'] = 100;
         $this->save_options($options);
     }
     if (empty($options['api_key'])) {
         $options['api_key'] = self::get_token();
         $this->save_options($options);
     }
     if (empty($options['scheduler_max'])) {
         $options['scheduler_max'] = 100;
         $this->save_options($options);
     }
     wp_clear_scheduled_hook('newsletter');
     wp_schedule_event(time() + 30, 'newsletter', 'newsletter');
     wp_clear_scheduled_hook('newsletter_extension_versions');
     wp_schedule_event(time() + 30, 'newsletter_extension_versions', 'newsletter_weekly');
     add_option('newsletter_extension_versions', array(), null, 'no');
     wp_clear_scheduled_hook('newsletter_update');
     wp_clear_scheduled_hook('newsletter_check_versions');
     wp_mkdir_p(WP_CONTENT_DIR . '/extensions/newsletter');
     wp_mkdir_p(WP_CONTENT_DIR . '/cache/newsletter');
     //wp_clear_scheduled_hook('newsletter_updates_run');
     wp_clear_scheduled_hook('newsletter_statistics_version_check');
     wp_clear_scheduled_hook('newsletter_reports_version_check');
     wp_clear_scheduled_hook('newsletter_feed_version_check');
     wp_clear_scheduled_hook('newsletter_popup_version_check');
     return true;
 }
예제 #4
0
/**
 * Runs before the schema is upgraded.
 *
 * @since 2.9.0
 *
 * @global int  $wp_current_db_version
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function pre_schema_upgrade()
{
    global $wp_current_db_version, $wpdb;
    // Upgrade versions prior to 2.9
    if ($wp_current_db_version < 11557) {
        // Delete duplicate options. Keep the option with the highest option_id.
        $wpdb->query("DELETE o1 FROM {$wpdb->options} AS o1 JOIN {$wpdb->options} AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
        // Drop the old primary key and add the new.
        $wpdb->query("ALTER TABLE {$wpdb->options} DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
        // Drop the old option_name index. dbDelta() doesn't do the drop.
        $wpdb->query("ALTER TABLE {$wpdb->options} DROP INDEX option_name");
    }
    // Multisite schema upgrades.
    if ($wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables()) {
        // Upgrade verions prior to 3.7
        if ($wp_current_db_version < 25179) {
            // New primary key for signups.
            $wpdb->query("ALTER TABLE {$wpdb->signups} ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain");
        }
        if ($wp_current_db_version < 25448) {
            // Convert archived from enum to tinyint.
            $wpdb->query("ALTER TABLE {$wpdb->blogs} CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'");
            $wpdb->query("ALTER TABLE {$wpdb->blogs} CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0");
        }
    }
    // Upgrade versions prior to 4.2.
    if ($wp_current_db_version < 31351) {
        if (!is_multisite() && wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        }
        $wpdb->query("ALTER TABLE {$wpdb->terms} DROP INDEX slug, ADD INDEX slug(slug(191))");
        $wpdb->query("ALTER TABLE {$wpdb->terms} DROP INDEX name, ADD INDEX name(name(191))");
        $wpdb->query("ALTER TABLE {$wpdb->commentmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        $wpdb->query("ALTER TABLE {$wpdb->postmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        $wpdb->query("ALTER TABLE {$wpdb->posts} DROP INDEX post_name, ADD INDEX post_name(post_name(191))");
    }
    // Upgrade versions prior to 4.4.
    if ($wp_current_db_version < 34978) {
        // If compatible termmeta table is found, use it, but enforce a proper index and update collation.
        if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->termmeta}'") && $wpdb->get_results("SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'")) {
            $wpdb->query("ALTER TABLE {$wpdb->termmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            maybe_convert_table_to_utf8mb4($wpdb->termmeta);
        }
    }
}
 public static function upgradeUTF()
 {
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     if (!function_exists('maybe_convert_table_to_utf8mb4')) {
         return;
     }
     // Versions before 4.2.0
     $table_name = maxUtils::get_buttons_table_name();
     $collection_table_name = maxUtils::get_collection_table_name();
     maybe_convert_table_to_utf8mb4($table_name);
     maybe_convert_table_to_utf8mb4($collection_table_name);
 }
예제 #6
0
파일: upgrade.php 프로젝트: RainGrid/site
function gwolle_gb_upgrade()
{
    global $wpdb;
    $installed_ver = get_option('gwolle_gb_version');
    if (version_compare($installed_ver, '0.9', '<')) {
        /*
         * 0.8 -> 0.9
         * No changes to the database; just added a few options.
         */
        add_option('recaptcha-active', 'false');
        add_option('recaptcha-public-key', '');
        add_option('recaptcha-private-key', '');
    }
    if (version_compare($installed_ver, '0.9.1', '<')) {
        /*
         * 0.9 -> 0.9.1
         * Moved the email notification options to the WP options table.
         */
        $notifyUser = "******" . $wpdb->prefix . "gwolle_gb_settings\n\t\t\t\tWHERE\n\t\t\t\t\tsetting_name = 'notify_by_mail'\n\t\t\t\t\tAND\n\t\t\t\t\tsetting_value = '1'\n\t\t\t\t";
        $notifySettings = $wpdb->get_results($notifyUser, ARRAY_A);
        foreach ($notifySettings as $notifySetting) {
            //	Add an option for each notification subscriber.
            add_option('gwolle_gb-notifyByMail-' . $notifySetting['user_id'], 'true');
        }
        // Delete the old settings table.
        $wpdb->query("\n\t\t\t\tDROP TABLE\n\t\t\t\t\t" . $wpdb->prefix . "gwolle_gb_settings\n\t\t\t");
    }
    if (version_compare($installed_ver, '0.9.2', '<')) {
        /*
         **	0.9.1->0.9.2
         **	Renamed the option for toggling reCAPTCHA so that we can
         **	have different plugins using reCAPTCHA.
         */
        add_option('gwolle_gb-recaptcha-active', get_option('recaptcha-active'));
        delete_option('recaptcha-active');
    }
    if (version_compare($installed_ver, '0.9.3', '<')) {
        /*
         **	0.9.2->0.9.3
         **	Added Akismet integration
         **	Add an option row and a new column to the entry table
         **	to be able to mark entries as spam automatically.
         */
        add_option('gwolle_gb-akismet-active', 'false');
        $wpdb->query("\n\t\t\t\tALTER\n\t\t\t\tTABLE " . $wpdb->gwolle_gb_entries . "\n\t\t\t\tADD\n\t\t\t\t\tentry_isSpam\n\t\t\t\t\t\tVARCHAR( 1 )\n\t\t\t\t\t\tNOT NULL\n\t\t\t\t\t\tDEFAULT '0'\n\t\t\t\t\t\tAFTER entry_isDeleted\n\t\t\t");
    }
    if (version_compare($installed_ver, '0.9.4', '<')) {
        /*
         **	0.9.3->0.9.4
         **	added access-level, no-mail-on-spam, moderate on/off.
         */
        add_option('gwolle_gb-access-level', '10');
        add_option('gwolle_gb-moderate-entries', 'true');
        $emailNotification = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM\n\t\t\t\t\t" . $wpdb->prefix . "options\n\t\t\t\tWHERE\n\t\t\t\t\toption_name LIKE 'gwolle_gb-notifyByMail-%'\n\t\t\t\t";
        $notifications = $wpdb->get_results($emailNotification, ARRAY_A);
        foreach ($notifications as $notification) {
            add_option('gwolle_gb-notifyAll-' . str_replace('gwolle_gb-notifyByMail-', '', $notification['option_name']), 'true');
        }
    }
    if (version_compare($installed_ver, '0.9.4.1', '<')) {
        /*
         **	0.9.4->0.9.4.1
         **	Caching the Wordpress API key so that we don't need to
         **	validate it each time the user opens the settings panel.
         **	Also, add an option to show icons in the entry list.
         */
        add_option('gwolle_gb-wordpress-api-key', get_option('wordpress_api_key'));
        add_option('gwolle_gb-showEntryIcons', 'true');
    }
    if (version_compare($installed_ver, '0.9.4.2', '<')) {
        /*
         **	0.9.4.1->0.9.4.2
         **	Added the possibility to specify the content of the mail
         **	a subscriber of the mail notification gets.
         **	Also, added an option to turn the version-check on/off
         **	and the possibility to set the numbers of entries per page.
         */
        add_option('gwolle_gb-adminMailContent', '');
        if (function_exists('file') && get_cfg_var('allow_url_fopen')) {
            $default = 'true';
        } else {
            $default = 'false';
        }
        add_option('gwolle_gb-autoCheckVersion', $default);
        add_option('gwolle_gb-entriesPerPage', '20');
    }
    if (version_compare($installed_ver, '0.9.4.2.1', '<')) {
        /*
         **	0.9.4.2->0.9.4.2.1
         **	Removed the version check because of some problems.
         */
        delete_option('gwolle_gb-autoCheckVersion');
    }
    if (version_compare($installed_ver, '0.9.4.3', '<')) {
        /*
         **	0.9.4.2.1->0.9.4.3
         **	Added option to manually set link to the guestbook.
         */
        add_option('gwolle_gb-guestbookLink');
    }
    if (version_compare($installed_ver, '0.9.4.5', '<')) {
        /*
         **	0.9.4.2.3->0.9.4.5
         **	Support for Croation chars.
         **	Added option to toggle line breaks-visibility.
         */
        $wpdb->query("\n\t\t\t\tALTER\n\t\t\t\tTABLE " . $wpdb->gwolle_gb_entries . "\n\t\t\t\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci\n\t\t\t");
        $wpdb->query("\n\t\t\t\tALTER\n\t\t\t\tTABLE " . $wpdb->gwolle_gb_entries . "\n\t\t\t\t\tCHANGE `entry_id` `entry_id` INT(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tCHANGE `entry_author_name` `entry_author_name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_authorAdminId` `entry_authorAdminId` INT(5) NOT NULL DEFAULT '0',\n\t\t\t\t\tCHANGE `entry_author_email` `entry_author_email` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_author_origin` `entry_author_origin` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_author_website` `entry_author_website` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_author_ip` `entry_author_ip` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_author_host` `entry_author_host` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_content` `entry_content` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_date` `entry_date` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\tCHANGE `entry_isChecked` `entry_isChecked` TINYINT(1) NOT NULL,\n\t\t\t\t\tCHANGE `entry_checkedBy` `entry_checkedBy` INT(5) NOT NULL,\n\t\t\t\t\tCHANGE `entry_isDeleted` `entry_isDeleted` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0',\n\t\t\t\t\tCHANGE `entry_isSpam` `entry_isSpam` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0'\n\t\t\t");
        add_option('gwolle_gb-showLineBreaks', 'false');
    }
    if (version_compare($installed_ver, '0.9.4.6', '<')) {
        /*
         **  0.9.4.5->0.9.4.6
         **  Added option to show/hide text before/after [gwolle_gb] tag.
         */
        add_option('gwolle_gb-guestbookOnly', 'true');
    }
    if (version_compare($installed_ver, '0.9.5', '<')) {
        /*
         **  0.9.4.6->0.9.5
         **  Added option to toggle check for import data.
         */
        add_option('gwolle_gb-checkForImport', 'true');
    }
    if (version_compare($installed_ver, '0.9.6', '<')) {
        /**
         * 0.9.5->0.9.6
         * Added the following options:
         * - toggle replacing of smilies
         * - toggle link to author's website
         */
        add_option('gwolle_gb-showSmilies', 'true');
        add_option('gwolle_gb-linkAuthorWebsite', 'true');
    }
    if (version_compare($installed_ver, '0.9.9.1', '<')) {
        /*
         *  0.9.8.1->0.9.9.0
         *  Removed the access level option, use standard WordPress capabilities.
         *  Save Users that are subcribed to notification mails in an option with the array of user_id's
         */
        delete_option('gwolle_gb-access-level');
        // Get users from database who have subscribed to the notification service.
        $sql = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM\n\t\t\t\t\t" . $wpdb->prefix . "options\n\t\t\t\tWHERE\n\t\t\t\t\toption_name LIKE 'gwolle_gb-notifyByMail-%'\n\t\t\t\tORDER BY\n\t\t\t\t\toption_name\n\t\t\t";
        $notifyUser_result = $wpdb->get_results($sql, ARRAY_A);
        if (count($notifyUser_result) > 0) {
            $user_ids = array();
            foreach ($notifyUser_result as $option) {
                $user_id = (int) str_replace('gwolle_gb-notifyByMail-', '', $option['option_name']);
                $user_info = get_userdata($user_id);
                if ($user_info === FALSE) {
                    // Invalid $user_id
                    continue;
                }
                if ($user_id > 0) {
                    $user_ids[] = $user_id;
                }
            }
            $user_ids = implode(",", $user_ids);
            update_option('gwolle_gb-notifyByMail', $user_ids);
        }
    }
    if (version_compare($installed_ver, '0.9.9.2', '<')) {
        /*
         *  0.9.9.1->0.9.9.2
         *  Remove the options of Users that are subcribed to notification mails
         */
        $wpdb->query("\n\t\t\t\tDELETE\n\t\t\t\t\tFROM " . $wpdb->prefix . "options\n\t\t\t\tWHERE\n\t\t\t\t\toption_name LIKE 'gwolle_gb-notifyByMail-%'\n\t\t\t\tOR\n\t\t\t\t\toption_name LIKE 'gwolle_gb-notifyAll-%'\n\t\t\t");
    }
    if (version_compare($installed_ver, '1.0.5', '<')) {
        /*
         *  1.0.4->1.0.5
         *  Remove obsolete options
         */
        delete_option('gwolle_gb-access-level');
        delete_option('gwolle_gb-checkForImport');
        delete_option('gwolle_gb-post_ID');
        /* Alter table of logs */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_log}\n\t\t\t\tCHANGE log_id id int(8) NOT NULL auto_increment,\n\t\t\t\tCHANGE log_subject subject text NOT NULL,\n\t\t\t\tCHANGE log_subjectId entry_id int(5) NOT NULL,\n\t\t\t\tCHANGE log_authorId author_id int(5) NOT NULL,\n\t\t\t\tCHANGE log_date date varchar(12) NOT NULL\n\t\t\t");
    }
    if (version_compare($installed_ver, '1.0.6', '<')) {
        /*
         * 1.0.5->1.0.6
         * Alter table of entries
         */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries}\n\t\t\t\tCHANGE `entry_id` `id` INT(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\tCHANGE `entry_author_name` `author_name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_authorAdminId` `author_id` INT(5) NOT NULL DEFAULT '0',\n\t\t\t\tCHANGE `entry_author_email` `author_email` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_author_origin` `author_origin` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_author_website` `author_website` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_author_ip` `author_ip` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_author_host` `author_host` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_content` `content` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_date` `date` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n\t\t\t\tCHANGE `entry_isChecked` `ischecked` TINYINT(1) NOT NULL,\n\t\t\t\tCHANGE `entry_checkedBy` `checkedby` INT(5) NOT NULL,\n\t\t\t\tCHANGE `entry_isDeleted` `istrash` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0',\n\t\t\t\tCHANGE `entry_isSpam` `isspam` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0'\n\t\t\t");
    }
    if (version_compare($installed_ver, '1.1.3', '<')) {
        /*
         * 1.1.2->1.1.3
         */
        delete_option('gwolle_gb-guestbookOnly');
        delete_option('gwolle_gb-defaultMailText');
        if (get_option('gwolle_gb-recaptcha-active', 'false') == 'true') {
            $form_setting = array('form_recaptcha_enabled' => 'true');
            $form_setting = serialize($form_setting);
            update_option('gwolle_gb-form', $form_setting);
        }
        delete_option('gwolle_gb-recaptcha-active');
    }
    if (version_compare($installed_ver, '1.3.8', '<')) {
        /*
         * 1.3.7->1.3.8
         * Call flush_rules() as a method of the $wp_rewrite object for the RSS Feed.
         */
        global $wp_rewrite;
        $wp_rewrite->flush_rules(false);
    }
    if (version_compare($installed_ver, '1.4.2', '<')) {
        /*
         * 1.4.1->1.4.2
         * Add datetime field to database and fill it from the date column.
         */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries} ADD `datetime` BIGINT(8) UNSIGNED NOT NULL AFTER `date`;\n\t\t");
        $wpdb->query("\n\t\t\tUPDATE `{$wpdb->gwolle_gb_entries}` SET `datetime` = `date`;\n\t\t");
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_log} ADD `datetime` BIGINT(8) UNSIGNED NOT NULL AFTER `date`;\n\t\t");
        $wpdb->query("\n\t\t\tUPDATE `{$wpdb->gwolle_gb_log}` SET `datetime` = `date`;\n\t\t");
    }
    if (version_compare($installed_ver, '1.4.3', '<')) {
        /*
         * 1.4.2->1.4.3
         * Remove date field from database.
         */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries} DROP COLUMN `date`;\n\t\t");
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_log} DROP COLUMN `date`;\n\t\t");
    }
    if (version_compare($installed_ver, '1.4.8', '<')) {
        /*
         * 1.4.7->1.4.8
         * Add admin_reply and admin_reply_uid field to database.
         */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries} ADD `admin_reply` LONGTEXT NOT NULL AFTER `isspam`;\n\t\t");
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries} ADD `admin_reply_uid` INT(5) NOT NULL AFTER `admin_reply`;\n\t\t");
    }
    if (version_compare($installed_ver, '1.5.1', '<')) {
        /*
         * 1.5.0->1.5.1
         * Add book_id field to database and fill it with value '1'.
         */
        $wpdb->query("\n\t\t\tALTER TABLE {$wpdb->gwolle_gb_entries} ADD `book_id` INT(8) UNSIGNED NOT NULL default '1' AFTER `admin_reply_uid`;\n\t\t");
    }
    /* Upgrade to new shiny db collation. Since WP 4.2 */
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    if (function_exists('maybe_convert_table_to_utf8mb4')) {
        maybe_convert_table_to_utf8mb4($wpdb->gwolle_gb_entries);
        maybe_convert_table_to_utf8mb4($wpdb->gwolle_gb_log);
    }
    /* Update the plugin version option */
    update_option('gwolle_gb_version', GWOLLE_GB_VER);
}
예제 #7
0
 function upgrade()
 {
     global $wpdb, $charset_collate;
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     parent::upgrade();
     $this->upgrade_query("create table if not exists " . NEWSLETTER_EMAILS_TABLE . " (id int auto_increment, primary key (id)) {$charset_collate}");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column message longtext");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column message_text longtext");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column subject varchar(255) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column type varchar(50) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column created timestamp not null default current_timestamp");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column status enum('new','sending','sent','paused') not null default 'new'");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column total int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column last_id int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column sent int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column send_on int not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column track tinyint not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column editor tinyint not null default 0");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column sex char(1) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " change column sex sex char(1) not null default ''");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column query text");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column preferences text");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " add column options longtext");
     // Cleans up old installations
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " drop column name");
     $this->upgrade_query("drop table if exists " . $wpdb->prefix . "newsletter_work");
     $this->upgrade_query("alter table " . NEWSLETTER_EMAILS_TABLE . " convert to character set utf8");
     // WP does not manage composite primary key when it tries to upgrade a table...
     $suppress_errors = $wpdb->suppress_errors(true);
     dbDelta("CREATE TABLE " . $wpdb->prefix . "newsletter_sent (\n            email_id int(10) unsigned NOT NULL DEFAULT '0',\n            user_id int(10) unsigned NOT NULL DEFAULT '0',\n            status tinyint(1) unsigned NOT NULL DEFAULT '0',\n            open tinyint(1) unsigned NOT NULL DEFAULT '0',\n            time int(10) unsigned NOT NULL DEFAULT '0',\n            error varchar(100) NOT NULL DEFAULT '',\n\t    ip varchar(100) NOT NULL DEFAULT '',\n            PRIMARY KEY (email_id,user_id),\n            KEY user_id (user_id),\n            KEY email_id (email_id)\n          ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
     $wpdb->suppress_errors($suppress_errors);
     if ('utf8mb4' === $wpdb->charset) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         if (function_exists('maybe_convert_table_to_utf8mb4')) {
             maybe_convert_table_to_utf8mb4(NEWSLETTER_EMAILS_TABLE);
         }
     }
     // Some setting check to avoid the common support request for mis-configurations
     $options = $this->get_options();
     if (empty($options['sender_email'])) {
         // That code was taken from WordPress
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         // WordPress build an address in the same way using wordpress@...
         $options['sender_email'] = 'newsletter@' . $sitename;
         $this->save_options($options);
     }
     if (empty($options['scheduler_max']) || !is_numeric($options['scheduler_max'])) {
         $options['scheduler_max'] = 100;
         $this->save_options($options);
     }
     if (empty($options['api_key'])) {
         $options['api_key'] = self::get_token();
         $this->save_options($options);
     }
     if (empty($options['scheduler_max'])) {
         $options['scheduler_max'] = 100;
         $this->save_options($options);
     }
     wp_clear_scheduled_hook('newsletter');
     wp_schedule_event(time() + 30, 'newsletter', 'newsletter');
     wp_clear_scheduled_hook('newsletter_extension_versions');
     wp_schedule_event(time() + 30, 'newsletter_extension_versions', 'newsletter_weekly');
     add_option('newsletter_extension_versions', array(), null, 'no');
     wp_clear_scheduled_hook('newsletter_update');
     wp_clear_scheduled_hook('newsletter_check_versions');
     //wp_mkdir_p(WP_CONTENT_DIR . '/extensions/newsletter');
     //wp_mkdir_p(WP_CONTENT_DIR . '/cache/newsletter');
     //wp_clear_scheduled_hook('newsletter_updates_run');
     wp_clear_scheduled_hook('newsletter_statistics_version_check');
     wp_clear_scheduled_hook('newsletter_reports_version_check');
     wp_clear_scheduled_hook('newsletter_feed_version_check');
     wp_clear_scheduled_hook('newsletter_popup_version_check');
     // If the original options has already saved once
     if (isset($options['smtp_host'])) {
         $smtp_options['enabled'] = $options['smtp_enabled'];
         $smtp_options['test_email'] = $options['smtp_test_email'];
         $smtp_options['host'] = $options['smtp_host'];
         $smtp_options['pass'] = $options['smtp_pass'];
         $smtp_options['port'] = $options['smtp_port'];
         $smtp_options['user'] = $options['smtp_user'];
         $smtp_options['secure'] = $options['smtp_secure'];
         $this->save_options($smtp_options, 'smtp');
         unset($options['smtp_enabled']);
         unset($options['smtp_test_email']);
         unset($options['smtp_pass']);
         unset($options['smtp_port']);
         unset($options['smtp_user']);
         unset($options['smtp_secure']);
         unset($options['smtp_host']);
         $this->save_options($options);
     }
     $this->init_options('smtp');
     return true;
 }
예제 #8
0
 function finalize_migration()
 {
     $this->set_post_data();
     $tables = explode(',', $this->post_data['tables']);
     $temp_prefix = $this->post_data['temp_prefix'];
     $temp_tables = array();
     foreach ($tables as $table) {
         $temp_tables[] = $temp_prefix . $table;
     }
     // Update tables to utf8mb4 if MySQL version > 5.5.3
     global $wpdb;
     if (version_compare($wpdb->db_version(), '5.5.3', '>=')) {
         require_once ABSPATH . '/wp-admin/includes/upgrade.php';
         // WordPress versions 4.2 or greater
         if (function_exists('maybe_convert_table_to_utf8mb4')) {
             foreach ($temp_tables as $table) {
                 maybe_convert_table_to_utf8mb4($table);
             }
         }
     }
     $sql = "SET FOREIGN_KEY_CHECKS=0;\n";
     $sql .= $this->get_preserved_options_queries($temp_tables);
     foreach ($temp_tables as $table) {
         $sql .= 'DROP TABLE IF EXISTS ' . $this->backquote(substr($table, strlen($temp_prefix))) . ';';
         $sql .= "\n";
         $sql .= 'RENAME TABLE ' . $this->backquote($table) . ' TO ' . $this->backquote(substr($table, strlen($temp_prefix))) . ';';
         $sql .= "\n";
     }
     $alter_table_name = $this->get_alter_table_name();
     $sql .= $this->get_alter_queries();
     $sql .= 'DROP TABLE IF EXISTS ' . $this->backquote($alter_table_name) . ";\n";
     $process_chunk_result = $this->process_chunk($sql);
     if (true !== $process_chunk_result) {
         $result = $this->end_ajax($process_chunk_result);
         return $result;
     }
     $type = isset($this->post_data['type']) ? 'push' : 'pull';
     $location = isset($this->post_data['location']) ? $this->post_data['location'] : $this->post_data['url'];
     if (!isset($this->post_data['location'])) {
         $data = array();
         $data['action'] = 'wpmdb_fire_migration_complete';
         $data['url'] = home_url();
         $data['sig'] = $this->create_signature($data, $this->post_data['key']);
         $ajax_url = trailingslashit($this->post_data['url']) . 'wp-admin/admin-ajax.php';
         $response = $this->remote_post($ajax_url, $data, __FUNCTION__);
         ob_start();
         echo esc_html($response);
         $this->display_errors();
         $maybe_errors = trim(ob_get_clean());
         if (false === empty($maybe_errors)) {
             $result = $this->end_ajax($maybe_errors);
             return $result;
         }
     }
     // flush rewrite rules to prevent 404s and other oddities
     wp_cache_flush();
     global $wp_rewrite;
     $wp_rewrite->init();
     flush_rewrite_rules(true);
     // true = hard refresh, recreates the .htaccess file
     do_action('wpmdb_migration_complete', $type, $location);
 }
예제 #9
0
파일: upgrade.php 프로젝트: 7press/7press
/**
 * Runs before the schema is upgraded.
 *
 * @since 2.9.0
 *
 * @global int  $wp_current_db_version
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function pre_schema_upgrade()
{
    global $wp_current_db_version, $wpdb;
    // Upgrade versions prior to 2.9
    if ($wp_current_db_version < 11557) {
        // Delete duplicate options. Keep the option with the highest option_id.
        $wpdb->query("DELETE o1 FROM {$wpdb->options} AS o1 JOIN {$wpdb->options} AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
        // Drop the old primary key and add the new.
        $wpdb->query("ALTER TABLE {$wpdb->options} DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
        // Drop the old option_name index. dbDelta() doesn't do the drop.
        $wpdb->query("ALTER TABLE {$wpdb->options} DROP INDEX option_name");
    }
    // Upgrade versions prior to 4.2.
    if ($wp_current_db_version < 31351) {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        }
        $wpdb->query("ALTER TABLE {$wpdb->terms} DROP INDEX slug, ADD INDEX slug(slug(191))");
        $wpdb->query("ALTER TABLE {$wpdb->terms} DROP INDEX name, ADD INDEX name(name(191))");
        $wpdb->query("ALTER TABLE {$wpdb->commentmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        $wpdb->query("ALTER TABLE {$wpdb->postmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
        $wpdb->query("ALTER TABLE {$wpdb->posts} DROP INDEX post_name, ADD INDEX post_name(post_name(191))");
    }
    // Upgrade versions prior to 4.4.
    if ($wp_current_db_version < 34978) {
        // If compatible termmeta table is found, use it, but enforce a proper index and update collation.
        if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->termmeta}'") && $wpdb->get_results("SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'")) {
            $wpdb->query("ALTER TABLE {$wpdb->termmeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            maybe_convert_table_to_utf8mb4($wpdb->termmeta);
        }
    }
}
예제 #10
0
 /**
  * Updates Table collation to `utf8mb4`
  */
 function update_table_collation()
 {
     if (!version_compare($this->version, "1.0.8.2")) {
         return;
     }
     $migrated_version = get_option(self::MIGRATED_VERSION);
     if ($migrated_version === $this->version) {
         return;
     }
     $table = Chat::tablename('message');
     require_once ABSPATH . '/wp-admin/includes/upgrade.php';
     if (function_exists('maybe_convert_table_to_utf8mb4')) {
         maybe_convert_table_to_utf8mb4($table);
     }
     update_option(self::MIGRATED_VERSION, $this->version);
 }
예제 #11
0
function em_create_tickets_bookings_table()
{
    global $wpdb, $user_level;
    $table_name = $wpdb->prefix . 'em_tickets_bookings';
    // Creating the events table
    $sql = "CREATE TABLE {$table_name} (\r\n\t\t  ticket_booking_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t  booking_id bigint(20) unsigned NOT NULL,\r\n\t\t  ticket_id bigint(20) unsigned NOT NULL,\r\n\t\t  ticket_booking_spaces int(6) NOT NULL,\r\n\t\t  ticket_booking_price decimal(14,4) NOT NULL,\r\n\t\t  PRIMARY KEY  (ticket_booking_id)\r\n\t\t) DEFAULT CHARSET=utf8 ;";
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    dbDelta($sql);
    em_sort_out_table_nu_keys($table_name, array('booking_id', 'ticket_id'));
    if (em_check_utf8mb4_tables()) {
        maybe_convert_table_to_utf8mb4($table_name);
    }
}