PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/3.6.8/wp-shopping-cart/instructions.php

https://github.com/evadne/wp-e-commerce
PHP | 380 lines | 11 code | 12 blank | 357 comment | 0 complexity | f49ebfda9745fd603b3ce1e06801081e MD5 | raw file
  1. <?php
  2. global $wpdb;
  3. ?>
  4. <div class="wrap">
  5. <?php
  6. $regions = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}region_tax`", ARRAY_A);
  7. foreach((array)$regions as $region) {
  8. //echo "<pre>".print_r($region,true)."</pre>";
  9. echo "\$wpdb->query(\"INSERT INTO `{\$wpdb->prefix}region_tax` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '{$region['country_id']}', '{$region['name']}', '{$region['code']}', '{$region['tax']}')\");<br />";
  10. }
  11. /*
  12. $failure_reasons = array();
  13. $upgrade_failed = false;
  14. foreach((array)$wpsc_database_template as $table_name => $table_data) {
  15. if(!$wpdb->get_var("SHOW TABLES LIKE '$table_name'")) {
  16. //if the table does not exixt, create the table
  17. $constructed_sql_parts = array();
  18. $constructed_sql = "CREATE TABLE `{$table_name}` (\n";
  19. // loop through the columns
  20. foreach((array)$table_data['columns'] as $column => $properties) {
  21. $constructed_sql_parts[] = "`$column` $properties";
  22. }
  23. // then through the indexes
  24. foreach((array)$table_data['indexes'] as $properties) {
  25. $constructed_sql_parts[] = "$properties";
  26. }
  27. $constructed_sql .= implode(",\n", $constructed_sql_parts);
  28. $constructed_sql .= "\n) ENGINE=MyISAM;";
  29. if(!$wpdb->query($constructed_sql)) {
  30. $upgrade_failed = true;
  31. $failure_reasons[] = $wpdb->last_error;
  32. }
  33. //echo "<pre>$constructed_sql</pre>";
  34. } else {
  35. //check to see if the table needs updating
  36. $existing_table_columns = array();
  37. $existing_table_column_data = $wpdb->get_results("SHOW COLUMNS FROM `$table_name`", ARRAY_A);
  38. foreach((array)$existing_table_column_data as $existing_table_column) {
  39. $existing_table_columns[] = $existing_table_column['Field'];
  40. }
  41. $supplied_table_columns = array_keys($table_data['columns']);
  42. // compare the supplied and existing columns to find the differences
  43. $missing_or_extra_table_columns = array_diff($supplied_table_columns, $existing_table_columns);
  44. if(count($missing_or_extra_table_columns) > 0) {
  45. foreach((array)$missing_or_extra_table_columns as $missing_or_extra_table_column) {
  46. if(isset($table_data['columns'][$missing_or_extra_table_column])) {
  47. //table column is missing, add it
  48. $previous_column = $supplied_table_columns[array_search($missing_or_extra_table_column, $supplied_table_columns)-1];
  49. if($previous_column != '') {
  50. $previous_column = "AFTER `$previous_column`";
  51. }
  52. $constructed_sql = "ALTER TABLE `$table_name` ADD `$missing_or_extra_table_column` ".$table_data['columns'][$missing_or_extra_table_column]." $previous_column;";
  53. if(!$wpdb->query($constructed_sql)) {
  54. $upgrade_failed = true;
  55. $failure_reasons[] = $wpdb->last_error;
  56. }
  57. }
  58. }
  59. }
  60. // get the list of existing indexes
  61. $existing_table_index_data = $wpdb->get_results("SHOW INDEX FROM `$table_name`", ARRAY_A);
  62. $existing_table_indexes = array();
  63. foreach($existing_table_index_data as $existing_table_index) {
  64. $existing_table_indexes[] = $existing_table_index['Key_name'];
  65. }
  66. $existing_table_indexes = array_unique($existing_table_indexes);
  67. $supplied_table_indexes = array_keys($table_data['indexes']);
  68. // compare the supplied and existing indxes to find the differences
  69. $missing_or_extra_table_indexes = array_diff($supplied_table_indexes, $existing_table_indexes);
  70. if(count($missing_or_extra_table_indexes) > 0) {
  71. foreach($missing_or_extra_table_indexes as $missing_or_extra_table_index) {
  72. if(isset($table_data['indexes'][$missing_or_extra_table_index])) {
  73. $constructed_sql = "ALTER TABLE `$table_name` ADD ".$table_data['indexes'][$missing_or_extra_table_index].";";
  74. if(!$wpdb->query($constructed_sql)) {
  75. $upgrade_failed = true;
  76. $failure_reasons[] = $wpdb->last_error;
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }*/
  83. /*
  84. $num = 0;
  85. $wpsc_tables[$num]['table_name'] = $wpdb->prefix."also_bought_product";
  86. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."also_bought_product` (
  87. `id` bigint(20) unsigned NOT NULL auto_increment,
  88. `selected_product` bigint(20) unsigned NOT NULL default '0',
  89. `associated_product` bigint(20) unsigned NOT NULL default '0',
  90. `quantity` int(10) unsigned NOT NULL default '0',
  91. PRIMARY KEY (`id`)
  92. ) TYPE=MyISAM ;
  93. ";
  94. // Table structure for table `".$wpdb->prefix."cart_contents`
  95. $num++;
  96. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'cart_contents';
  97. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."cart_contents` (
  98. `id` bigint(20) unsigned NOT NULL auto_increment,
  99. `prodid` bigint(20) unsigned NOT NULL default '0',
  100. `purchaseid` bigint(20) unsigned NOT NULL default '0',
  101. `price` varchar(128) NOT NULL default '0',
  102. `pnp` varchar(128) NOT NULL default '0',
  103. `gst` varchar(128) NOT NULL default '0',
  104. `quantity` int(10) unsigned NOT NULL default '0',
  105. `donation` varchar(1) NOT NULL default '0',
  106. `no_shipping` varchar(1) NOT NULL default '0',
  107. `files` TEXT NOT NULL default '',
  108. PRIMARY KEY (`id`)
  109. ) TYPE=MyISAM ;
  110. ";
  111. // Table structure for table `".$wpdb->prefix."cart_item_extras`
  112. $num++;
  113. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'cart_item_extras';
  114. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."cart_item_extras` (
  115. `id` int(11) NOT NULL auto_increment,
  116. `cart_id` int(11) NOT NULL,
  117. `extra_id` int(11) NOT NULL,
  118. PRIMARY KEY (`id`)
  119. ) TYPE=MyISAM;
  120. ";
  121. // Table structure for table `".$wpdb->prefix."cart_item_variations`
  122. $num++;
  123. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'cart_item_variations';
  124. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."cart_item_variations` (
  125. `id` bigint(20) unsigned NOT NULL auto_increment,
  126. `cart_id` bigint(20) unsigned NOT NULL default '0',
  127. `variation_id` bigint(20) unsigned NOT NULL default '0',
  128. `value_id` bigint(20) unsigned NOT NULL default '0',
  129. PRIMARY KEY (`id`)
  130. ) TYPE=MyISAM;
  131. ";
  132. // Table structure for table `".$wpdb->prefix."collect_data_forms`
  133. $num++;
  134. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'collect_data_forms';
  135. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."collect_data_forms` (
  136. `id` bigint(20) unsigned NOT NULL auto_increment,
  137. `name` varchar(255) NOT NULL default '',
  138. `type` varchar(64) NOT NULL default '',
  139. `mandatory` varchar(1) NOT NULL default '0',
  140. `display_log` char(1) NOT NULL default '0',
  141. `default` varchar(128) NOT NULL default '0',
  142. `active` varchar(1) NOT NULL default '1',
  143. `order` int(10) unsigned NOT NULL default '0',
  144. PRIMARY KEY (`id`),
  145. KEY `order` (`order`)
  146. ) TYPE=MyISAM ;
  147. ";
  148. // Table structure for table `".$wpdb->prefix."currency_list`
  149. $num++;
  150. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'currency_list';
  151. $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `".$wpdb->prefix."currency_list` (
  152. `id` bigint(20) unsigned NOT NULL auto_increment,
  153. `country` varchar(255) NOT NULL default '',
  154. `isocode` char(2) default NULL,
  155. `currency` varchar(255) NOT NULL default '',
  156. `symbol` varchar(10) NOT NULL default '',
  157. `symbol_html` varchar(10) NOT NULL default '',
  158. `code` char(3) NOT NULL default '',
  159. `has_regions` char(1) NOT NULL default '0',
  160. `tax` varchar(8) NOT NULL default '',
  161. PRIMARY KEY (`id`)
  162. ) TYPE=MyISAM ;
  163. ";
  164. // Table structure for table `".$wpdb->prefix."download_status`
  165. $num++;
  166. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'download_status';
  167. // Table structure for table `".$wpdb->prefix."item_category_associations`
  168. $num++;
  169. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'item_category_associations';
  170. // Table structure for table `".$wpdb->prefix."product_brands`
  171. $num++;
  172. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_brands';
  173. // Table structure for table `".$wpdb->prefix."product_categories`
  174. $num++;
  175. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_categories';
  176. // Table structure for table `".$wpdb->prefix."product_extra`
  177. //$num++;
  178. //$wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_extra';
  179. // Table structure for table `".$wpdb->prefix."product_files`
  180. $num++;
  181. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_files';
  182. // Table structure for table `".$wpdb->prefix."product_images`
  183. $num++;
  184. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_images';
  185. // Table structure for table `".$wpdb->prefix."product_list`
  186. $num++;
  187. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_list';
  188. // Table structure for table `".$wpdb->prefix."product_order`
  189. $num++;
  190. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_order';
  191. // Table structure for table `".$wpdb->prefix."product_rating`
  192. $num++;
  193. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_rating';
  194. // Table structure for table `".$wpdb->prefix."product_variations`
  195. $num++;
  196. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'product_variations';
  197. // Table structure for table `".$wpdb->prefix."purchase_logs`
  198. $num++;
  199. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'purchase_logs';
  200. // Table structure for table `".$wpdb->prefix."purchase_statuses`
  201. $num++;
  202. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'purchase_statuses';
  203. // Table structure for table `".$wpdb->prefix."region_tax`
  204. $num++;
  205. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'region_tax';
  206. // Table structure for table `".$wpdb->prefix."submited_form_data`
  207. $num++;
  208. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'submited_form_data';
  209. // Table structure for table `".$wpdb->prefix."variation_associations`
  210. $num++;
  211. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'variation_associations';
  212. // Table structure for table `".$wpdb->prefix."variation_priceandstock`
  213. $num++;
  214. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'variation_priceandstock';
  215. // Table structure for table `".$wpdb->prefix."variation_values`
  216. $num++;
  217. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'variation_values';
  218. // Table structure for table `".$wpdb->prefix."variation_values_associations`
  219. $num++;
  220. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'variation_values_associations';
  221. // Table structure for table `".$wpdb->prefix."wpsc_coupon_codes`
  222. $num++;
  223. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'wpsc_coupon_codes';
  224. // Table structure for table `".$wpdb->prefix."wpsc_logged_subscriptions`
  225. $num++;
  226. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'wpsc_logged_subscriptions';
  227. // Table structure for table `".$wpdb->prefix."wpsc_productmeta`
  228. $num++;
  229. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'wpsc_productmeta';
  230. $num++;
  231. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'wpsc_categorisation_groups';
  232. $num++;
  233. $wpsc_tables[$num]['table_name'] = $wpdb->prefix.'wpsc_variation_combinations';
  234. echo "<pre>";
  235. foreach($wpsc_tables as $wpsc_table) {
  236. $table_name = $wpsc_table['table_name'];
  237. $table_cols = $wpdb->get_results("SHOW FULL COLUMNS FROM $table_name", ARRAY_A);
  238. $table_indexes = $wpdb->get_results("SHOW INDEX FROM $table_name", ARRAY_A);
  239. //echo "<h4>$table_name</h4>";
  240. //echo "<pre>".print_r($table_cols,true)."</pre>";
  241. //echo "<pre>".print_r($table_indexes,true)."</pre>";
  242. echo '$table_name = "'.str_replace($wpdb->prefix, "{\$wpdb->prefix}", $table_name)."\";\n";
  243. foreach($table_cols as $column) {
  244. if($column['Null'] == "YES") {
  245. $null_status = "NULL";
  246. } else {
  247. $null_status = "NOT NULL";
  248. }
  249. if($column['Extra'] != '') {
  250. $default = '';
  251. } else {
  252. $default = "DEFAULT '$column[Default]'";
  253. }
  254. //echo "`{$column['Field']}` {$column['Type']} {$null_status} $default {$column['Extra']} <br />";
  255. echo "\$wpsc_database_template[\$table_name]['columns']['{$column['Field']}'] = \"{$column['Type']} {$null_status} $default {$column['Extra']}\";\n";
  256. }
  257. foreach($table_indexes as $index) {
  258. if($index['Key_name'] == "PRIMARY") {
  259. $key_prefix = "PRIMARY";
  260. $key_name = '';
  261. $array_key_name = "PRIMARY";
  262. } else {
  263. if($index['Non_unique'] == 0) {
  264. $key_prefix = "UNIQUE";
  265. } else {
  266. $key_prefix = "";
  267. }
  268. $key_name = "`".$index['Key_name']."`";
  269. $array_key_name = $index['Key_name'];
  270. }
  271. //echo "{$key_prefix} KEY {$key_name} ( `{$index['Column_name']}` ) <br />";
  272. echo "\$wpsc_database_template[\$table_name]['indexes']['{$array_key_name}'] = \"{$key_prefix} KEY {$key_name} ( `{$index['Column_name']}` )\";\n";
  273. }
  274. echo "\n\r";
  275. }
  276. echo "</pre>";
  277. // */
  278. ?>
  279. </div>