Changeset 29206 for trunk/src/wp-admin/includes/upgrade.php
- Timestamp:
- 07/17/2014 09:13:53 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r29154 r29206 62 62 update_option('default_pingback_flag', 0); 63 63 64 // Create default user. If the user already exists, the user tables are 65 // being shared among blogs. Just set the role in that case. 64 /* 65 * Create default user. If the user already exists, the user tables are 66 * being shared among blogs. Just set the role in that case. 67 */ 66 68 $user_id = username_exists($user_name); 67 69 $user_password = trim($user_password); … … 626 628 $active_plugins = __get_option('active_plugins'); 627 629 628 // If plugins are not stored in an array, they're stored in the old 629 // newline separated format. Convert to new format. 630 /* 631 * If plugins are not stored in an array, they're stored in the old 632 * newline separated format. Convert to new format. 633 */ 630 634 if ( !is_array( $active_plugins ) ) { 631 635 $active_plugins = explode("\n", trim($active_plugins)); … … 717 721 $wpdb->show_errors(); 718 722 719 // populate comment_count field of posts table723 // Populate comment_count field of posts table. 720 724 $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); 721 725 if ( is_array( $comments ) ) … … 723 727 $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) ); 724 728 725 // Some alpha versions used a post status of object instead of attachment and put 726 // the mime type in post_type instead of post_mime_type. 729 /* 730 * Some alpha versions used a post status of object instead of attachment 731 * and put the mime type in post_type instead of post_mime_type. 732 */ 727 733 if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) { 728 734 $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); … … 881 887 // < 3570 we used linkcategories. >= 3570 we used categories and link2cat. 882 888 if ( $wp_current_db_version < 3570 ) { 883 // Create link_category terms for link categories. Create a map of link cat IDs 884 // to link_category terms. 889 /* 890 * Create link_category terms for link categories. Create a map of link 891 * cat IDs to link_category terms. 892 */ 885 893 $link_cat_id_map = array(); 886 894 $default_link_cat = 0; … … 990 998 */ 991 999 function upgrade_old_slugs() { 992 // upgrade people who were using the Redirect Old Slugs plugin1000 // Upgrade people who were using the Redirect Old Slugs plugin. 993 1001 global $wpdb; 994 1002 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'"); … … 1305 1313 global $wp_current_db_version, $wpdb; 1306 1314 1307 // Always 1315 // Always. 1308 1316 if ( is_main_network() ) { 1309 // Deletes all expired transients. 1310 // The multi-table delete syntax is used to delete the transient record from table a, 1311 // and the corresponding transient_timeout record from table b. 1317 /* 1318 * Deletes all expired transients. The multi-table delete syntax is used 1319 * to delete the transient record from table a, and the corresponding 1320 * transient_timeout record from table b. 1321 */ 1312 1322 $time = time(); 1313 1323 $sql = "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b … … 1319 1329 } 1320 1330 1321 // 2.8 1331 // 2.8. 1322 1332 if ( $wp_current_db_version < 11549 ) { 1323 1333 $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); … … 1416 1426 return true; 1417 1427 } 1418 //didn't find it try to create it. 1428 1429 // Didn't find it try to create it.. 1419 1430 $wpdb->query($create_ddl); 1420 // we cannot directly tell that whether this succeeded! 1431 1432 // We cannot directly tell that whether this succeeded! 1421 1433 if ( $wpdb->get_var( $query ) == $table_name ) { 1422 1434 return true; … … 1479 1491 } 1480 1492 } 1481 //didn't find it try to create it. 1493 1494 // Didn't find it try to create it. 1482 1495 $wpdb->query($create_ddl); 1483 // we cannot directly tell that whether this succeeded! 1496 1497 // We cannot directly tell that whether this succeeded! 1484 1498 foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { 1485 1499 if ($column == $column_name) { … … 1552 1566 // Note: \\\ inside a regex denotes a single backslash. 1553 1567 1554 // Replace one or more backslashes followed by a single quote with 1555 // a single quote. 1568 /* 1569 * Replace one or more backslashes followed by a single quote with 1570 * a single quote. 1571 */ 1556 1572 $content = preg_replace("/\\\+'/", "'", $content); 1557 1573 1558 // Replace one or more backslashes followed by a double quote with 1559 // a double quote. 1574 /* 1575 * Replace one or more backslashes followed by a double quote with 1576 * a double quote. 1577 */ 1560 1578 $content = preg_replace('/\\\+"/', '"', $content); 1561 1579 … … 1656 1674 continue; 1657 1675 1658 // Clear the field and index arrays 1676 // Clear the field and index arrays. 1659 1677 $cfields = $indices = array(); 1660 // Get all of the field names in the query from between the parens 1678 1679 // Get all of the field names in the query from between the parentheses. 1661 1680 preg_match("|\((.*)\)|ms", $qry, $match2); 1662 1681 $qryline = trim($match2[1]); 1663 1682 1664 // Separate field lines into an array 1683 // Separate field lines into an array. 1665 1684 $flds = explode("\n", $qryline); 1666 1685 1686 // todo: Remove this? 1667 1687 //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>"; 1668 1688 1669 // For every field line specified in the query 1689 // For every field line specified in the query. 1670 1690 foreach ($flds as $fld) { 1671 // Extract the field name 1691 1692 // Extract the field name. 1672 1693 preg_match("|^([^ ]*)|", trim($fld), $fvals); 1673 1694 $fieldname = trim( $fvals[1], '`' ); 1674 1695 1675 // Verify the found field name 1696 // Verify the found field name. 1676 1697 $validfield = true; 1677 1698 switch (strtolower($fieldname)) { … … 1688 1709 $fld = trim($fld); 1689 1710 1690 // If it's a valid field, add it to the field array 1711 // If it's a valid field, add it to the field array. 1691 1712 if ($validfield) { 1692 1713 $cfields[strtolower($fieldname)] = trim($fld, ", \n"); … … 1694 1715 } 1695 1716 1696 // For every field in the table 1717 // For every field in the table. 1697 1718 foreach ($tablefields as $tablefield) { 1698 // If the table field exists in the field array... 1719 1720 // If the table field exists in the field array ... 1699 1721 if (array_key_exists(strtolower($tablefield->Field), $cfields)) { 1700 // Get the field type from the query 1722 1723 // Get the field type from the query. 1701 1724 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches); 1702 1725 $fieldtype = $matches[1]; … … 1710 1733 1711 1734 // Get the default value from the array 1735 // todo: Remove this? 1712 1736 //echo "{$cfields[strtolower($tablefield->Field)]}<br>"; 1713 1737 if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) { … … 1720 1744 } 1721 1745 1722 // Remove the field from the array (so it's not added) 1746 // Remove the field from the array (so it's not added). 1723 1747 unset($cfields[strtolower($tablefield->Field)]); 1724 1748 } else { … … 1727 1751 } 1728 1752 1729 // For every remaining field specified for the table 1753 // For every remaining field specified for the table. 1730 1754 foreach ($cfields as $fieldname => $fielddef) { 1731 // Push a query line into $cqueries that adds the field to that table 1755 // Push a query line into $cqueries that adds the field to that table. 1732 1756 $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef"; 1733 1757 $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname; 1734 1758 } 1735 1759 1736 // Index stuff goes here 1737 // Fetch the table index structure from the database 1760 // Index stuff goes here. Fetch the table index structure from the database. 1738 1761 $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};"); 1739 1762 1740 1763 if ($tableindices) { 1741 // Clear the index array 1764 // Clear the index array. 1742 1765 unset($index_ary); 1743 1766 1744 // For every index in the table 1767 // For every index in the table. 1745 1768 foreach ($tableindices as $tableindex) { 1746 // Add the index to the index data array 1769 1770 // Add the index to the index data array. 1747 1771 $keyname = $tableindex->Key_name; 1748 1772 $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part); … … 1750 1774 } 1751 1775 1752 // For each actual index in the index array 1776 // For each actual index in the index array. 1753 1777 foreach ($index_ary as $index_name => $index_data) { 1754 // Build a create string to compare to the query 1778 1779 // Build a create string to compare to the query. 1755 1780 $index_string = ''; 1756 1781 if ($index_name == 'PRIMARY') { … … 1764 1789 } 1765 1790 $index_columns = ''; 1766 // For each column in the index 1791 1792 // For each column in the index. 1767 1793 foreach ($index_data['columns'] as $column_data) { 1768 1794 if ($index_columns != '') $index_columns .= ','; 1769 // Add the field to the column list string 1795 1796 // Add the field to the column list string. 1770 1797 $index_columns .= $column_data['fieldname']; 1771 1798 if ($column_data['subpart'] != '') { … … 1773 1800 } 1774 1801 } 1775 // Add the column list to the index create string 1802 // Add the column list to the index create string. 1776 1803 $index_string .= ' ('.$index_columns.')'; 1777 1804 if (!(($aindex = array_search($index_string, $indices)) === false)) { 1778 1805 unset($indices[$aindex]); 1806 // todo: Remove this? 1779 1807 //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n"; 1780 1808 } 1809 // todo: Remove this? 1781 1810 //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"; 1782 1811 } 1783 1812 } 1784 1813 1785 // For every remaining index specified for the table 1814 // For every remaining index specified for the table. 1786 1815 foreach ( (array) $indices as $index ) { 1787 // Push a query line into $cqueries that adds the index to that table 1816 // Push a query line into $cqueries that adds the index to that table. 1788 1817 $cqueries[] = "ALTER TABLE {$table} ADD $index"; 1789 1818 $for_update[] = 'Added index ' . $table . ' ' . $index; 1790 1819 } 1791 1820 1792 // Remove the original table creation query from processing 1821 // Remove the original table creation query from processing. 1793 1822 unset( $cqueries[ $table ], $for_update[ $table ] ); 1794 1823 } … … 1797 1826 if ($execute) { 1798 1827 foreach ($allqueries as $query) { 1828 // todo: Remove this? 1799 1829 //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n"; 1800 1830 $wpdb->query($query); … … 1848 1878 return false; 1849 1879 1850 // Copy files from the old locations to the site theme. 1851 // TODO: This does not copy arbitrary include dependencies. Only the 1852 // standard WP files are copied. 1880 /* 1881 * Copy files from the old locations to the site theme. 1882 * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied. 1883 */ 1853 1884 $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php'); 1854 1885 … … 1859 1890 $oldpath = ABSPATH; 1860 1891 1861 if ($oldfile == 'index.php') { // Check to make sure it's not a new index 1892 // Check to make sure it's not a new index. 1893 if ($oldfile == 'index.php') { 1862 1894 $index = implode('', file("$oldpath/$oldfile")); 1863 1895 if (strpos($index, 'WP_USE_THEMES') !== false) { 1864 1896 if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) 1865 1897 return false; 1866 continue; // Don't copy anything 1898 1899 // Don't copy anything. 1900 continue; 1867 1901 } 1868 1902 }
Note: See TracChangeset
for help on using the changeset viewer.