<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[19041] trunk/wp-admin/includes/upgrade.php: Undent (by two tabs) a whole lot of code in dbDelta().</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/19041">19041</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-10-21 22:40:30 +0000 (Fri, 21 Oct 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Undent (by two tabs) a whole lot of code in dbDelta(). Thx. see <a href="http://core.trac.wordpress.org/ticket/17998">#17998</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesupgradephp">trunk/wp-admin/includes/upgrade.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/upgrade.php (19040 => 19041)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/upgrade.php        2011-10-21 22:35:33 UTC (rev 19040)
+++ trunk/wp-admin/includes/upgrade.php        2011-10-21 22:40:30 UTC (rev 19041)
</span><span class="lines">@@ -1473,140 +1473,140 @@
</span><span class="cx">                 if ( ! $tablefields )
</span><span class="cx">                         continue;
</span><span class="cx">
</span><del>-                                // Clear the field and index arrays
-                                $cfields = $indices = array();
-                                // Get all of the field names in the query from between the parens
-                                preg_match("|\((.*)\)|ms", $qry, $match2);
-                                $qryline = trim($match2[1]);
</del><ins>+                // Clear the field and index arrays
+                $cfields = $indices = array();
+                // Get all of the field names in the query from between the parens
+                preg_match("|\((.*)\)|ms", $qry, $match2);
+                $qryline = trim($match2[1]);
</ins><span class="cx">
</span><del>-                                // Separate field lines into an array
-                                $flds = explode("\n", $qryline);
</del><ins>+                // Separate field lines into an array
+                $flds = explode("\n", $qryline);
</ins><span class="cx">
</span><del>-                                //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
</del><ins>+                //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
</ins><span class="cx">
</span><del>-                                // For every field line specified in the query
-                                foreach ($flds as $fld) {
-                                        // Extract the field name
-                                        preg_match("|^([^ ]*)|", trim($fld), $fvals);
-                                        $fieldname = trim( $fvals[1], '`' );
</del><ins>+                // For every field line specified in the query
+                foreach ($flds as $fld) {
+                        // Extract the field name
+                        preg_match("|^([^ ]*)|", trim($fld), $fvals);
+                        $fieldname = trim( $fvals[1], '`' );
</ins><span class="cx">
</span><del>-                                        // Verify the found field name
-                                        $validfield = true;
-                                        switch (strtolower($fieldname)) {
-                                        case '':
-                                        case 'primary':
-                                        case 'index':
-                                        case 'fulltext':
-                                        case 'unique':
-                                        case 'key':
-                                                $validfield = false;
-                                                $indices[] = trim(trim($fld), ", \n");
-                                                break;
-                                        }
-                                        $fld = trim($fld);
</del><ins>+                        // Verify the found field name
+                        $validfield = true;
+                        switch (strtolower($fieldname)) {
+                        case '':
+                        case 'primary':
+                        case 'index':
+                        case 'fulltext':
+                        case 'unique':
+                        case 'key':
+                                $validfield = false;
+                                $indices[] = trim(trim($fld), ", \n");
+                                break;
+                        }
+                        $fld = trim($fld);
</ins><span class="cx">
</span><del>-                                        // If it's a valid field, add it to the field array
-                                        if ($validfield) {
-                                                $cfields[strtolower($fieldname)] = trim($fld, ", \n");
-                                        }
-                                }
</del><ins>+                        // If it's a valid field, add it to the field array
+                        if ($validfield) {
+                                $cfields[strtolower($fieldname)] = trim($fld, ", \n");
+                        }
+                }
</ins><span class="cx">
</span><del>-                                // For every field in the table
-                                foreach ($tablefields as $tablefield) {
-                                        // If the table field exists in the field array...
-                                        if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
-                                                // Get the field type from the query
-                                                preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
-                                                $fieldtype = $matches[1];
</del><ins>+                // For every field in the table
+                foreach ($tablefields as $tablefield) {
+                        // If the table field exists in the field array...
+                        if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
+                                // Get the field type from the query
+                                preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
+                                $fieldtype = $matches[1];
</ins><span class="cx">
</span><del>-                                                // Is actual field type different from the field type in query?
-                                                if ($tablefield->Type != $fieldtype) {
-                                                        // Add a query to change the column type
-                                                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
-                                                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
-                                                }
</del><ins>+                                // Is actual field type different from the field type in query?
+                                if ($tablefield->Type != $fieldtype) {
+                                        // Add a query to change the column type
+                                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
+                                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
+                                }
</ins><span class="cx">
</span><del>-                                                // Get the default value from the array
-                                                        //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
-                                                if (preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
-                                                        $default_value = $matches[1];
-                                                        if ($tablefield->Default != $default_value) {
-                                                                // Add a query to change the column's default value
-                                                                $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
-                                                                $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
-                                                        }
-                                                }
-
-                                                // Remove the field from the array (so it's not added)
-                                                unset($cfields[strtolower($tablefield->Field)]);
-                                        } else {
-                                                // This field exists in the table, but not in the creation queries?
</del><ins>+                                // Get the default value from the array
+                                        //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
+                                if (preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
+                                        $default_value = $matches[1];
+                                        if ($tablefield->Default != $default_value) {
+                                                // Add a query to change the column's default value
+                                                $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
+                                                $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
</ins><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx">
</span><del>-                                // For every remaining field specified for the table
-                                foreach ($cfields as $fieldname => $fielddef) {
-                                        // Push a query line into $cqueries that adds the field to that table
-                                        $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
-                                        $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
-                                }
</del><ins>+                                // Remove the field from the array (so it's not added)
+                                unset($cfields[strtolower($tablefield->Field)]);
+                        } else {
+                                // This field exists in the table, but not in the creation queries?
+                        }
+                }
</ins><span class="cx">
</span><del>-                                // Index stuff goes here
-                                // Fetch the table index structure from the database
-                                $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
</del><ins>+                // For every remaining field specified for the table
+                foreach ($cfields as $fieldname => $fielddef) {
+                        // Push a query line into $cqueries that adds the field to that table
+                        $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
+                        $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
+                }
</ins><span class="cx">
</span><del>-                                if ($tableindices) {
-                                        // Clear the index array
-                                        unset($index_ary);
</del><ins>+                // Index stuff goes here
+                // Fetch the table index structure from the database
+                $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
</ins><span class="cx">
</span><del>-                                        // For every index in the table
-                                        foreach ($tableindices as $tableindex) {
-                                                // Add the index to the index data array
-                                                $keyname = $tableindex->Key_name;
-                                                $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
-                                                $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
-                                        }
</del><ins>+                if ($tableindices) {
+                        // Clear the index array
+                        unset($index_ary);
</ins><span class="cx">
</span><del>-                                        // For each actual index in the index array
-                                        foreach ($index_ary as $index_name => $index_data) {
-                                                // Build a create string to compare to the query
-                                                $index_string = '';
-                                                if ($index_name == 'PRIMARY') {
-                                                        $index_string .= 'PRIMARY ';
-                                                } else if($index_data['unique']) {
-                                                        $index_string .= 'UNIQUE ';
-                                                }
-                                                $index_string .= 'KEY ';
-                                                if ($index_name != 'PRIMARY') {
-                                                        $index_string .= $index_name;
-                                                }
-                                                $index_columns = '';
-                                                // For each column in the index
-                                                foreach ($index_data['columns'] as $column_data) {
-                                                        if ($index_columns != '') $index_columns .= ',';
-                                                        // Add the field to the column list string
-                                                        $index_columns .= $column_data['fieldname'];
-                                                        if ($column_data['subpart'] != '') {
-                                                                $index_columns .= '('.$column_data['subpart'].')';
-                                                        }
-                                                }
-                                                // Add the column list to the index create string
-                                                $index_string .= ' ('.$index_columns.')';
-                                                if (!(($aindex = array_search($index_string, $indices)) === false)) {
-                                                        unset($indices[$aindex]);
-                                                        //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
-                                                }
-                                                //else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
</del><ins>+                        // For every index in the table
+                        foreach ($tableindices as $tableindex) {
+                                // Add the index to the index data array
+                                $keyname = $tableindex->Key_name;
+                                $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
+                                $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
+                        }
+
+                        // For each actual index in the index array
+                        foreach ($index_ary as $index_name => $index_data) {
+                                // Build a create string to compare to the query
+                                $index_string = '';
+                                if ($index_name == 'PRIMARY') {
+                                        $index_string .= 'PRIMARY ';
+                                } else if($index_data['unique']) {
+                                        $index_string .= 'UNIQUE ';
+                                }
+                                $index_string .= 'KEY ';
+                                if ($index_name != 'PRIMARY') {
+                                        $index_string .= $index_name;
+                                }
+                                $index_columns = '';
+                                // For each column in the index
+                                foreach ($index_data['columns'] as $column_data) {
+                                        if ($index_columns != '') $index_columns .= ',';
+                                        // Add the field to the column list string
+                                        $index_columns .= $column_data['fieldname'];
+                                        if ($column_data['subpart'] != '') {
+                                                $index_columns .= '('.$column_data['subpart'].')';
</ins><span class="cx">                                         }
</span><span class="cx">                                 }
</span><del>-
-                                // For every remaining index specified for the table
-                                foreach ( (array) $indices as $index ) {
-                                        // Push a query line into $cqueries that adds the index to that table
-                                        $cqueries[] = "ALTER TABLE {$table} ADD $index";
-                                        $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
</del><ins>+                                // Add the column list to the index create string
+                                $index_string .= ' ('.$index_columns.')';
+                                if (!(($aindex = array_search($index_string, $indices)) === false)) {
+                                        unset($indices[$aindex]);
+                                        //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
</ins><span class="cx">                                 }
</span><ins>+                                //else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
+                        }
+                }
</ins><span class="cx">
</span><ins>+                // For every remaining index specified for the table
+                foreach ( (array) $indices as $index ) {
+                        // Push a query line into $cqueries that adds the index to that table
+                        $cqueries[] = "ALTER TABLE {$table} ADD $index";
+                        $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
+                }
+
</ins><span class="cx">                 // Remove the original table creation query from processing
</span><span class="cx">                 unset( $cqueries[ $table ], $for_update[ $table ] );
</span><span class="cx">         }
</span></span></pre>
</div>
</div>
</body>
</html>