| [ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 <?php 2 /* 3 $Id: ms1_to_ms2.php,v 1.3 2003/06/23 01:27:34 thomasamoulton Exp $ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Copyright (c) 2003 osCommerce 9 10 Released under the GNU General Public License 11 */ 12 ?> 13 14 <script language="JavaScript"><!-- 15 function changeStyle(what, how) { 16 if (document.getElementById) { 17 document.getElementById(what).style.fontWeight = how; 18 } else if (document.all) { 19 document.all[what].style.fontWeight = how; 20 } 21 } 22 23 function changeText(where, what) { 24 if (document.getElementById) { 25 document.getElementById(where).innerHTML = what; 26 } else if (document.all) { 27 document.all[where].innerHTML = what; 28 } 29 } 30 //--></script> 31 32 <html> 33 <head> 34 <title>osCommerce Preview Release 2.2 Database Update Script</title> 35 <style type=text/css><!-- 36 A:link, A:visited { color: #0029A3; text-decoration: none; } 37 A:hover { color: #5D59ac; text-decoration: underline; } 38 TD, UL, P, BODY { font-family: Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5; } 39 .boxMe { font-family: Verdana, Arial, sans-serif; font-size: 11px; color: #000000; background-color: #e5e5e5; } 40 .noteBox { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 1.5; background-color: #fef3da; border: thin dashed; padding: 6px; } 41 .navigationBar { font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; color: #ffffff; } 42 .footerBar { font-family: Verdana, Arial, sans-serif; font-size: 10px; color: #ffffff; } 43 .mainText { font-family: Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5; } 44 .smallText { font-family: Verdana, Arial, sans-serif; font-size: 10px; line-height: 1.5; } 45 .infoBoxHeading { font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; color: #ffffff; } 46 .infoBoxText { font-family: Verdana, Arial, sans-serif; font-size: 10px; } 47 .pageHeading { font-family: Verdana, Arial, sans-serif; font-size: 20px; color: #9a9a9a; font-weight: bold; } 48 .pageTitle { font-family: Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5; font-weight: bold; text-decoration: underline; } 49 } 50 //--></style> 51 </head> 52 <body> 53 <p> 54 <b>osCommerce Release 2.2 MS1 to MS2 Database Update Script</b> 55 <p>This script can be copied to any web directory to upgrade a MS1 database 56 to a MS2 database. By MS1 and MS2 I mean the state of the database the DAY 57 that the MS release was made, not *any* MS1 like CVS tree. 58 59 So if you upgraded to MS1 and stayed there you can use this script. 60 <?php 61 if (!$HTTP_POST_VARS['DB_SERVER']) { 62 ?> 63 <form name="database" action="<?php echo basename($PHP_SELF); ?>" method="post"> 64 <table border="0" cellspacing="2" cellpadding="2"> 65 <tr> 66 <td colspan="2"><b>Database Server Information</b></td> 67 </tr> 68 <tr> 69 <td>Server:</td> 70 <td><input type="text" name="DB_SERVER"> <small>(eg, 192.168.0.1)</small></td> 71 </tr> 72 <tr> 73 <td>Username:</td> 74 <td><input type="text" name="DB_SERVER_USERNAME"> <small>(eg, root)</small></td> 75 </tr> 76 <tr> 77 <td>Password:</td> 78 <td><input type="text" name="DB_SERVER_PASSWORD"> <small>(eg, bee)</small></td> 79 </tr> 80 <tr> 81 <td>Database:</td> 82 <td><input type="text" name="DB_DATABASE"> <small>(eg, catalog)</small></td> 83 </tr> 84 <tr> 85 <td> </td> 86 <td><input type="submit" value="Submit"></td> 87 </tr> 88 </table> 89 </form> 90 </body> 91 </html> 92 <?php 93 exit; 94 } 95 96 function osc_db_connect() { 97 global $db_link, $HTTP_POST_VARS; 98 99 $db_link = mysql_connect($HTTP_POST_VARS['DB_SERVER'], $HTTP_POST_VARS['DB_SERVER_USERNAME'], $HTTP_POST_VARS['DB_SERVER_PASSWORD']); 100 101 if ($db_link) mysql_select_db($HTTP_POST_VARS['DB_DATABASE']); 102 103 return $db_link; 104 } 105 106 function osc_db_error ($query, $errno, $error) { 107 die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>'); 108 } 109 110 function osc_db_query($db_query) { 111 global $db_link; 112 113 $result = mysql_query($db_query, $db_link) or osc_db_error($db_query, mysql_errno(), mysql_error()); 114 115 return $result; 116 } 117 118 function osc_db_fetch_array($db_query) { 119 $result = mysql_fetch_array($db_query); 120 121 return $result; 122 } 123 124 function osc_db_num_rows($db_query) { 125 return mysql_num_rows($db_query); 126 } 127 128 // Sets timeout for the current script. 129 // Cant be used in safe mode. 130 function osc_set_time_limit($limit) { 131 if (!get_cfg_var('safe_mode')) { 132 set_time_limit($limit); 133 } 134 } 135 136 osc_db_connect() or die('Unable to connect to database server!'); 137 ?> 138 <p><span class="pageHeading">osCommerce</span><br><font color="#9a9a9a">Open Source E-Commerce Solutions</font></p> 139 140 <p class="pageTitle">Upgrade</p> 141 142 <p><b>Step 1: Database Upgrade</b></p> 143 144 <?php 145 function osc_db_update_configuration_key($key, $new_key) { 146 147 $sql = "update configuration set configuration_key = '" . $new_key . "' where configuration_key = '" . $key . "'"; 148 osc_db_query($sql); 149 $db_error = mysql_error(); 150 if ($db_error != false) die($db_error); 151 osc_db_query("update configuration set last_modified = NOW() where configuration_key = '" . $new_key . "'"); 152 } 153 154 function osc_db_update_configuration_title($key, $new_title) { 155 156 $sql = "update configuration set configuration_title = '" . $new_title . "' where configuration_key = '" . $key . "'"; 157 osc_db_query($sql); 158 $db_error = mysql_error(); 159 if ($db_error != false) die($db_error); 160 osc_db_query("update configuration set last_modified = NOW() where configuration_key = '" . $key . "'"); 161 } 162 163 function osc_db_update_configuration_description($key, $new_description) { 164 165 $sql = "update configuration set configuration_description = '" . $new_description . "' where configuration_key = '" . $key . "'"; 166 osc_db_query($sql); 167 $db_error = mysql_error(); 168 if ($db_error != false) die($db_error); 169 osc_db_query("update configuration set last_modified = NOW() where configuration_key = '" . $key . "'"); 170 } 171 172 function osc_db_update_configuration_use_null($key) { 173 174 $sql = "update configuration set use_function = NULL where configuration_key = '" . $key . "'"; 175 osc_db_query($sql); 176 $db_error = mysql_error(); 177 if ($db_error != false) die($db_error); 178 osc_db_query("update configuration set last_modified = NOW() where configuration_key = '" . $key . "'"); 179 } 180 181 osc_set_time_limit(0); 182 183 // send data to the browser, so the flushing works with IE 184 for ($i=0; $i<300; $i++) print(' '); 185 print ("\n"); 186 ?> 187 188 <p><span id="addressBook"><span id="addressBookMarker">-</span> Address Book</span><br> 189 <span id="configuration"><span id="configurationMarker">-</span> Configuration</span><br> 190 191 <p>Status: <span id="statusText">Preparing</span></p> 192 193 <?php flush(); ?> 194 195 <script language="javascript"><!-- 196 changeStyle('addressBook', 'bold'); 197 changeText('addressBookMarker', '?'); 198 changeText('statusText', 'Updating Address Book'); 199 //--></script> 200 201 <?php 202 flush(); 203 204 /* Now convert the address_book_id to unique entries, now most are =1 */ 205 osc_db_query("alter table address_book add temp_id int(11) not NULL default '0' FIRST"); 206 $ab_query = osc_db_query("select customers_id, address_book_id from address_book order by address_book_id"); 207 $ab_id = 1; 208 while ($ab = osc_db_fetch_array($ab_query)) { 209 osc_db_query("update customers set customers_default_address_id = '" . $ab_id . "' where customers_id = '" . $ab['customers_id'] . "'"); 210 osc_db_query("update address_book set temp_id = '" . $ab_id . "' where customers_id = '" . $ab['customers_id'] . "' and address_book_id = '" . $ab['address_book_id'] . "'"); 211 $ab_id++; 212 } 213 214 osc_db_query("ALTER TABLE address_book DROP PRIMARY KEY"); 215 osc_db_query("ALTER TABLE address_book DROP COLUMN address_book_id"); 216 osc_db_query("ALTER TABLE address_book ADD PRIMARY KEY (temp_id)"); 217 osc_db_query("ALTER TABLE address_book CHANGE COLUMN temp_id address_book_id int(11) NOT NULL auto_increment"); 218 osc_db_query("ALTER TABLE address_book ADD INDEX idx_address_book_customers_id (customers_id)"); 219 220 osc_db_query("ALTER TABLE customers CHANGE COLUMN customers_default_address_id customers_default_address_id int(11) NOT NULL default '0'"); 221 ?> 222 <script language="javascript"><!-- 223 changeStyle('addressBook', 'normal'); 224 changeText('addressBookMarker', '*'); 225 changeText('statusText', 'Updating Address Book .. done!'); 226 227 changeStyle('configuration', 'bold'); 228 changeText('configurationMarker', '?'); 229 changeText('statusText', 'Updating Configuration'); 230 //--></script> 231 232 <?php 233 flush(); 234 235 osc_db_update_configuration_key('ENTRY_COMPANY_LENGTH', 'ENTRY_COMPANY_MIN_LENGTH'); 236 237 osc_db_query("update configuration set use_function = 'tep_cfg_get_zone_name' where configuration_key = 'STORE_ZONE'"); 238 239 osc_db_update_configuration_key('STORE_ORIGIN_ZIP', 'SHIPPING_ORIGIN_ZIP'); 240 241 osc_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Country of Origin', 'SHIPPING_ORIGIN_COUNTRY', '223', 'Select the country of origin to be used in shipping quotes.', '7', '1', 'tep_get_country_name', 'tep_cfg_pull_down_country_list(', now())"); 242 243 $country_query = osc_db_query("select configuration_value as name from configuration where configuration_key = 'STORE_ORIGIN_COUNTRY'"); 244 if (osc_db_num_rows($country_query) > 0) { 245 $country = osc_db_fetch_array($country_query); 246 if ($country['name'] != '') { 247 $new_country_query = osc_db_query("select countries_id from countries where countries_iso_code_2 = '" . $country['name'] . "'"); 248 $new_country = osc_db_fetch_array($new_country_query); 249 if ($new_country['countries_iso_code_2'] != NULL) { 250 osc_db_query("update configuration set configuration_value = " . $new_country['countries_iso_code_2'] . " where configuration_key = 'SHIPPING_ORIGIN_COUNTRY'"); 251 } 252 } 253 } 254 255 osc_db_query("delete from configuration where configuration_key = 'STORE_ORIGIN_COUNTRY'"); 256 257 osc_db_query("insert into configuration_group values ('15', 'Sessions', 'Session options', '15', '1')"); 258 259 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Session Directory', 'SESSION_WRITE_DIRECTORY', '/tmp', 'If sessions are file based, store them in this directory.', '15', '1', now())"); 260 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Force Cookie Use', 'SESSION_FORCE_COOKIE_USE', 'False', 'Force the use of sessions when cookies are only enabled.', '15', '2', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 261 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Check SSL Session ID', 'SESSION_CHECK_SSL_SESSION_ID', 'False', 'Validate the SSL_SESSION_ID on every secure HTTPS page request.', '15', '3', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 262 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Check User Agent', 'SESSION_CHECK_USER_AGENT', 'False', 'Validate the clients browser user agent on every page request.', '15', '4', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 263 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Check IP Address', 'SESSION_CHECK_IP_ADDRESS', 'False', 'Validate the clients IP address on every page request.', '15', '5', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 264 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Prevent Spider Sessions', 'SESSION_BLOCK_SPIDERS', 'False', 'Prevent known spiders from starting a session.', '15', '6', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 265 osc_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Recreate Session', 'SESSION_RECREATE', 'False', 'Recreate the session to generate a new session ID when the customer logs on or creates an account (PHP >=4.1 needed).', '15', '7', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 266 267 osc_db_update_configuration_title('SHIPPING_ORIGIN_COUNTRY', 'Country of Origin'); 268 269 osc_db_update_configuration_description('ACCOUNT_COMPANY', 'Display company in the customers account'); 270 osc_db_update_configuration_description('ACCOUNT_DOB', 'Display date of birth in the customers account'); 271 osc_db_update_configuration_description('ACCOUNT_GENDER', 'Display gender in the customers account'); 272 osc_db_update_configuration_description('ACCOUNT_STATE', 'Display state in the customers account'); 273 osc_db_update_configuration_description('ACCOUNT_SUBURB', 'Display suburb in the customers account'); 274 osc_db_update_configuration_description('SHIPPING_ORIGIN_COUNTRY', 'Select the country of origin to be used in shipping quotes.'); 275 ?> 276 277 <script language="javascript"><!-- 278 changeStyle('configuration', 'normal'); 279 changeText('configurationMarker', '*'); 280 changeText('statusText', 'Updating Configuration .. done!'); 281 282 changeStyle('statusText', 'bold'); 283 changeText('statusText', 'Update Complete!'); 284 //--></script> 285 286 <?php flush(); ?> 287 288 <p>The database upgrade procedure was successful!</p>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
|