Make WordPress Core


Ignore:
Timestamp:
11/19/2006 07:56:05 AM (19 years ago)
Author:
ryan
Message:

Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes #986

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/install-helper.php

    r1429 r4495  
    1010 */
    1111function maybe_create_table($table_name, $create_ddl) {
    12     global $wpdb;
    13     foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
    14         if ($table == $table_name) {
    15             return true;
    16         }
    17     }
    18     //didn't find it try to create it.
    19     $q = $wpdb->query($create_ddl);
    20     // we cannot directly tell that whether this succeeded!
    21     foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
    22         if ($table == $table_name) {
    23             return true;
    24         }
    25     }
    26     return false;
     12    global $wpdb;
     13    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
     14        if ($table == $table_name) {
     15            return true;
     16        }
     17    }
     18    //didn't find it try to create it.
     19    $q = $wpdb->query($create_ddl);
     20    // we cannot directly tell that whether this succeeded!
     21    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
     22        if ($table == $table_name) {
     23            return true;
     24        }
     25    }
     26    return false;
    2727}
    2828
     
    3434 */
    3535function maybe_add_column($table_name, $column_name, $create_ddl) {
    36     global $wpdb, $debug;
    37     foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
    38         if ($debug) echo("checking $column == $column_name<br />");
    39         if ($column == $column_name) {
    40             return true;
    41         }
    42     }
    43     //didn't find it try to create it.
    44     $q = $wpdb->query($create_ddl);
    45     // we cannot directly tell that whether this succeeded!
    46     foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
    47         if ($column == $column_name) {
    48             return true;
    49         }
    50     }
    51     return false;
     36    global $wpdb, $debug;
     37    foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
     38        if ($debug) echo("checking $column == $column_name<br />");
     39            if ($column == $column_name) {
     40                return true;
     41            }
     42    }
     43    //didn't find it try to create it.
     44    $q = $wpdb->query($create_ddl);
     45    // we cannot directly tell that whether this succeeded!
     46    foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
     47        if ($column == $column_name) {
     48            return true;
     49        }
     50    }
     51    return false;
    5252}
    5353
     
    6060 */
    6161function maybe_drop_column($table_name, $column_name, $drop_ddl) {
    62     global $wpdb;
    63     foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
    64         if ($column == $column_name) {
    65             //found it try to drop it.
    66             $q = $wpdb->query($drop_ddl);
    67             // we cannot directly tell that whether this succeeded!
    68             foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
    69                 if ($column == $column_name) {
    70                     return false;
    71                 }
    72             }
    73         }
    74     }
    75     // else didn't find it
    76     return true;
     62    global $wpdb;
     63    foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
     64        if ($column == $column_name) {
     65            //found it try to drop it.
     66            $q = $wpdb->query($drop_ddl);
     67            // we cannot directly tell that whether this succeeded!
     68            foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
     69                if ($column == $column_name) {
     70                    return false;
     71                }
     72            }
     73        }
     74    }
     75    // else didn't find it
     76    return true;
    7777}
    7878
     
    9393 */
    9494function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {
    95     global $wpdb, $debug;
    96     $diffs = 0;
    97     $results = $wpdb->get_results("DESC $table_name");
    98    
    99     foreach ($results as $row ) {
    100         if ($debug > 1) print_r($row);
    101         if ($row->Field == $col_name) {
    102             // got our column, check the params
    103             if ($debug) echo ("checking $row->Type against $col_type\n");
    104             if (($col_type != null) && ($row->Type != $col_type)) {
    105                 ++$diffs;
    106             }
    107             if (($is_null != null) && ($row->Null != $is_null)) {
    108                 ++$diffs;
    109             }
    110             if (($key != null) && ($row->Key  != $key)) {
    111                 ++$diffs;
    112             }
    113             if (($default != null) && ($row->Default != $default)) {
    114                 ++$diffs;
    115             }
    116             if (($extra != null) && ($row->Extra != $extra)) {
    117                 ++$diffs;
    118             }
    119             if ($diffs > 0) {
    120                 if ($debug) echo ("diffs = $diffs returning false\n");
    121                 return false;
    122             }
    123             return true;
    124         } // end if found our column
    125     }
    126     return false;
     95    global $wpdb, $debug;
     96    $diffs = 0;
     97    $results = $wpdb->get_results("DESC $table_name");
     98
     99    foreach ($results as $row ) {
     100        if ($debug > 1) print_r($row);
     101            if ($row->Field == $col_name) {
     102                // got our column, check the params
     103                if ($debug) echo ("checking $row->Type against $col_type\n");
     104                if (($col_type != null) && ($row->Type != $col_type)) {
     105                    ++$diffs;
     106                }
     107                if (($is_null != null) && ($row->Null != $is_null)) {
     108                    ++$diffs;
     109                }
     110                if (($key != null) && ($row->Key  != $key)) {
     111                    ++$diffs;
     112                }
     113                if (($default != null) && ($row->Default != $default)) {
     114                    ++$diffs;
     115                }
     116                if (($extra != null) && ($row->Extra != $extra)) {
     117                    ++$diffs;
     118                }
     119                if ($diffs > 0) {
     120                    if ($debug) echo ("diffs = $diffs returning false\n");
     121                    return false;
     122                }
     123                return true;
     124            } // end if found our column
     125    }
     126    return false;
    127127}
    128    
     128
    129129/*
    130130echo "<p>testing</p>";
    131131echo "<pre>";
    132132
    133 //check_column('wp_links', 'link_description', 'mediumtext'); 
     133//check_column('wp_links', 'link_description', 'mediumtext');
    134134//if (check_column($wpdb->comments, 'comment_author', 'tinytext'))
    135135//    echo "ok\n";
     
    139139if (!check_column($wpdb->links, 'link_description', 'varchar(255)'))
    140140{
    141     $ddl = "ALTER TABLE $wpdb->links MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
    142     $q = $wpdb->query($ddl);
     141    $ddl = "ALTER TABLE $wpdb->links MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
     142    $q = $wpdb->query($ddl);
    143143}
    144144if (check_column($wpdb->links, 'link_description', 'varchar(255)')) {
    145     $res .= $tablename . ' - ok <br />';
     145    $res .= $tablename . ' - ok <br />';
    146146} else {
    147     $res .= 'There was a problem with ' . $tablename . '<br />';
    148     ++$error_count;
     147    $res .= 'There was a problem with ' . $tablename . '<br />';
     148    ++$error_count;
    149149}
    150150echo "</pre>";
Note: See TracChangeset for help on using the changeset viewer.