Make WordPress Core

Changeset 994


Ignore:
Timestamp:
03/24/2004 10:53:30 PM (22 years ago)
Author:
michelvaldrighi
Message:

the big GMT/local changes, part 1: adding _gmt fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r969 r994  
    716716    }
    717717
    718     // Convert all datetime fields' values to GMT, add a gmt_offset option
     718    // Get the GMT offset, we'll use that later on
     719    $all_options = get_alloptions();
     720    $time_difference = $all_options->time_difference;
     721
     722    $server_time = time()+date('Z');
     723    $weblogger_time = $server_time + $time_difference*3600;
     724    $gmt_time = time();
     725
     726    $diff_gmt_server = ($gmt_time - $server_time) / 3600;
     727    $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
     728    $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
     729    $gmt_offset = -$diff_gmt_weblogger;
     730
     731    // Add a gmt_offset option, with value $gmt_offset
    719732    if (!get_settings('gmt_offset')) {
    720         // echo '1';
    721         $all_options = get_alloptions();
    722         $time_difference = $all_options->time_difference;
    723 
    724         $server_time = time()+date('Z');
    725         $weblogger_time = $server_time + $time_difference*3600;
    726         $gmt_time = time();
    727 
    728         $diff_gmt_server = ($gmt_time - $server_time) / 3600;
    729         $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
    730         $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
    731 
    732         if ($diff_gmt_weblogger != 0) {
    733             //echo '<br>2: ';
    734             $gmt_offset = -$diff_gmt_weblogger;
    735 
    736             $add_hours = intval($diff_gmt_weblogger);
    737             $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
    738             // echo $add_hours.':'.$add_minutes;
    739            
    740             // Add or substract time to all dates, to get GMT dates
    741             $wpdb->query("UPDATE $tableposts SET post_date = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
    742             $wpdb->query("UPDATE $tableposts SET post_modified = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'");
    743             $wpdb->query("UPDATE $tablecomments SET comment_date = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
    744             $wpdb->query("UPDATE $tableusers SET dateYMDhour = DATE_ADD(dateYMDhour, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
    745 
    746 
    747         } else {
    748             //echo '3';
    749             $gmt_offset = 0;
    750         }
    751 
    752         // Add gmt_field option, with value $gmt_offset
    753733        if(!$wpdb->get_var("SELECT * FROM $tableoptions WHERE option_name = 'gmt_offset'")) {
    754             // echo "<br>4: $gmt_offset";
    755734            $wpdb->query("INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES (94, 'gmt_offset', 8, $gmt_offset, 'The difference in hours between GMT and your timezone', 8)");
    756735        }
    757736
    758737    }
    759  
     738
     739    // Add post_date_gmt, post_modified_gmt, comment_date_gmt fields
     740    $got_gmt_fields = 0;
     741    foreach ($wpdb->get_col("DESC $tableposts", 0) as $column ) {
     742        if ($debug) echo("checking $column == $column_name<br />");
     743        if ($column == 'post_date_gmt') {
     744            $got_gmt_fields++;
     745        }
     746    }
     747    if (!$got_gmt_fields) {
     748        $wpdb->query("ALTER TABLE $tableposts ADD post_date_gmt DATETIME NOT NULL AFTER post_date");
     749        $wpdb->query("ALTER TABLE $tableposts ADD post_modified_gmt DATETIME NOT NULL AFTER post_modified");
     750        $wpdb->query("ALTER TABLE $tablecomments ADD comment_date_gmt DATETIME NOT NULL AFTER comment_date");
     751
     752        // Add or substract time to all dates, to get GMT dates
     753        $add_hours = intval($diff_gmt_weblogger);
     754        $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
     755        $wpdb->query("UPDATE $tableposts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
     756        $wpdb->query("UPDATE $tableposts SET post_modified_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'");
     757        $wpdb->query("UPDATE $tablecomments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
     758        $wpdb->query("UPDATE $tableusers SET dateYMDhour = DATE_ADD(dateYMDhour, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
     759    }
     760
    760761    // post-meta
    761762    maybe_create_table($tablepostmeta, "
Note: See TracChangeset for help on using the changeset viewer.