Exemple #1
0
/**
 * Upgrade routine. Hooked onto admin_init
 *
 *@since 1.1
 *@access private
 *@ignore
*/
function eventorganiser_upgradecheck()
{
    global $wpdb, $EO_Errors;
    $eventorganiser_db_version = defined('EVENT_ORGANISER_VER') ? EVENT_ORGANISER_VER : false;
    $installed_ver = get_option('eventorganiser_version');
    if (empty($installed_ver)) {
        //This is a fresh install. Add current database version
        add_option('eventorganiser_version', $eventorganiser_db_version);
        //But a bug in 1.5 means that it could be that they first installed in 1.5 (as no db version was added)
        //So set to 1.5.  Fresh installs will have to go through the 1.6 (and above) update, but this is ok.
        $installed_ver = '1.5';
        eventorganiser_install();
    }
    //If this is an old version, perform some updates.
    if (!empty($installed_ver) && $installed_ver != $eventorganiser_db_version) {
        if (version_compare($installed_ver, '1.3', '<')) {
            wp_die('You cannot upgrade to this version from 1.3 or before. Please upgrade to 1.5.7 first.');
        }
        if (version_compare($installed_ver, '1.4', '<')) {
            eventorganiser_140_update();
        }
        if (version_compare($installed_ver, '1.5', '<')) {
            eventorganiser_150_update();
        }
        if (version_compare($installed_ver, '1.6', '<')) {
            //Remove columns:
            $columns = $wpdb->get_col("DESC {$wpdb->eo_events}", 0);
            $remove_columns = array('Venue', 'event_schedule', 'event_schedule_meta', 'event_frequency', 'reoccurrence_start', 'reoccurrence_end');
            $delete_columns = array_intersect($remove_columns, $columns);
            if (!empty($delete_columns)) {
                $sql = $wpdb->query("ALTER TABLE {$wpdb->eo_events} DROP COLUMN " . implode(', DROP COLUMN ', $delete_columns) . ';');
            }
            eventorganiser_install();
        }
        if (version_compare($installed_ver, '1.6.2', '<')) {
            $options = get_option('eventorganiser_options');
            if (!empty($options['eventtag'])) {
                $options['supports'][] = 'eventtag';
                update_option('eventorganiser_options', $options);
            }
        }
        if (version_compare($installed_ver, '2.7.3', '<')) {
            //Ensure event_allday columns is removed. This causes problems on Windows servers.
            $columns = $wpdb->get_col("DESC {$wpdb->eo_events}", 0);
            $remove_columns = array('event_allday');
            $delete_columns = array_intersect($remove_columns, $columns);
            if (!empty($delete_columns)) {
                $sql = $wpdb->query("ALTER TABLE {$wpdb->eo_events} DROP COLUMN " . implode(', DROP COLUMN ', $delete_columns) . ';');
            }
            flush_rewrite_rules();
        }
        if (version_compare($installed_ver, '2.12.0', '<') && version_compare(get_bloginfo('version'), '4.2-alpha-31007-src', '>=')) {
            //If the user is upgrading from an earlier version (without the split term fix)
            //and they have already upgraded to WP 4.2.0, then run the update routine
            eventorganiser_021200_update();
        }
        update_option('eventorganiser_version', $eventorganiser_db_version);
        //Run upgrade checks
        add_action('admin_notices', 'eventorganiser_db_checks', 0);
    }
    //eventorganiser_021200_update();
}
/**
 * Upgrade routine. Hooked onto admin_init
 *
 *@since 1.1
 *@access private
 *@ignore
*/
function eventorganiser_upgradecheck()
{
    global $wpdb, $EO_Errors;
    $eventorganiser_db_version = defined('EVENT_ORGANISER_VER') ? EVENT_ORGANISER_VER : false;
    $installed_ver = get_option('eventorganiser_version');
    if (empty($installed_ver)) {
        //This is a fresh install. Add current database version
        add_option('eventorganiser_version', $eventorganiser_db_version);
        //But a bug in 1.5 means that it could be that they first installed in 1.5 (as no db version was added)
        //So set to 1.5.  Fresh installs will have to go through the 1.6 (and above) update, but this is ok.
        $installed_ver = '1.5';
    }
    //If this is an old version, perform some updates.
    if (!empty($installed_ver) && $installed_ver != $eventorganiser_db_version) {
        if ($installed_ver < '1.3') {
            wp_die('You cannot upgrade to this version from 1.3 or before. Please upgrade to 1.5.7 first.');
        }
        if ($installed_ver < '1.4') {
            eventorganiser_140_update();
        }
        if ($installed_ver < '1.5') {
            eventorganiser_150_update();
        }
        if ($installed_ver < '1.6') {
            //Remove columns:
            $columns = $wpdb->get_col("DESC {$wpdb->eo_events}", 0);
            $remove_columns = array('Venue', 'event_schedule', 'event_schedule_meta', 'event_frequency', 'reoccurrence_start', 'reoccurrence_end');
            $delete_columns = array_intersect($remove_columns, $columns);
            if (!empty($delete_columns)) {
                $sql = $wpdb->query("ALTER TABLE {$wpdb->eo_events} DROP COLUMN " . implode(', DROP COLUMN ', $delete_columns) . ';');
            }
            eventorganiser_install();
        }
        if ($installed_ver < '1.6.2') {
            $options = get_option('eventorganiser_options');
            if (!empty($options['eventtag'])) {
                $options['supports'][] = 'eventtag';
                update_option('eventorganiser_options', $options);
            }
        }
        if ($installed_ver < '1.7.1') {
            //Forgot to remove event_allday in 1.6 upgrade. This causes problems no Windows servers.
            $columns = $wpdb->get_col("DESC {$wpdb->eo_events}", 0);
            $remove_columns = array('event_allday');
            if (!empty($delete_columns)) {
                $sql = $wpdb->query("ALTER TABLE {$wpdb->eo_events} DROP COLUMN " . implode(', DROP COLUMN ', $delete_columns) . ';');
            }
            flush_rewrite_rules();
        }
        update_option('eventorganiser_version', $eventorganiser_db_version);
        //Run upgrade checks
        add_action('admin_notices', 'eventorganiser_db_checks', 0);
    }
}
function eventorganiser_upgradecheck()
{
    global $eventorganiser_db_version, $wpdb;
    global $EO_Errors;
    $installed_ver = get_option('eventorganiser_version');
    //If this is an old version, perform some updates.
    if (!empty($installed_ver) && $installed_ver != $eventorganiser_db_version) {
        if ($installed_ver < '1.1') {
            $query = $wpdb->prepare("SELECT* \n\t\t\t\tFROM {$wpdb->eo_events}\n\t\t\t\tWHERE {$wpdb->eo_events}.event_schedule = 'monthly'\n\t\t\t\tGROUP BY {$wpdb->eo_events}.post_id");
            $results = $wpdb->get_results($query);
            foreach ($results as $event) {
                $meta = $event->event_schedule_meta;
                $start = new DateTime(esc_attr($event->StartDate));
                $post_id = $event->post_id;
                $bymonthday = preg_match('/^BYMONTHDAY=(\\d{1,2})/', $meta, $matches);
                $byday = preg_match('/^BYDAY=(-?\\d{1,2})([a-zA-Z]{2})/', $meta, $matchesOLD);
                if (!($bymonthday || $byday)) {
                    if ($meta == 'date') {
                        $meta = 'BYMONTHDAY=' . $start->format('d');
                    } else {
                        $meta = 'BYDAY=' . $meta;
                    }
                    $result = $wpdb->update($wpdb->eo_events, array('event_schedule_meta' => $meta), array('post_id' => $post_id));
                }
            }
        }
        if ($installed_ver < '1.2') {
            $settings = get_option('eventorganiser_options');
            //Add new settings
            $settings['url_event'] = 'events/event';
            $settings['url_venue'] = 'events/venue';
            $settings['url_cat'] = 'events/category';
            $settings['url_tag'] = 'events/tag';
            $settings['navtitle'] = __('Events', 'eventorganiser');
            $settings['group_events'] = '';
            $settings['feed'] = 1;
            $settings['eventtag'] = 1;
            $settings['deleteexpired'] = 0;
            update_option('eventorganiser_options', $settings);
        }
        if ($installed_ver < '1.2.1') {
            $settings = get_option('eventorganiser_options');
            $settings['url_venue'] = empty($settings['url_venue']) ? 'events/venue' : $settings['url_venue'];
            update_option('eventorganiser_options', $settings);
            flush_rewrite_rules();
        }
        if ($installed_ver < '1.3') {
            eventorgniaser_130_update();
        }
        if ($installed_ver < '1.4') {
            eventorganiser_140_update();
        }
        update_option('eventorganiser_version', $eventorganiser_db_version);
        //Run upgrade checks
        add_action('admin_notices', 'eventorganiser_db_checks', 0);
    }
}