/[drupal]/contributions/modules/ubercart/uc_product_kit/uc_product_kit.install
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_product_kit/uc_product_kit.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Thu Jul 10 12:41:03 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.10: +30 -17 lines
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
3
4 function uc_product_kit_install() {
5 switch ($GLOBALS['db_type']) {
6 case 'mysql':
7 case 'mysqli':
8 db_query("CREATE TABLE {uc_product_kits} (
9 `vid` mediumint(9) NOT NULL default 0,
10 `nid` mediumint(9) NOT NULL default 0,
11 `product_id` mediumint(9) NOT NULL,
12 `mutable` tinyint(1) NOT NULL default 0,
13 `qty` smallint(6) NOT NULL,
14 `discount` float NOT NULL default 0.0,
15 `ordering` smallint NOT NULL default 0,
16 PRIMARY KEY (`vid`, `product_id`)
17 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
18 break;
19 case 'pgsql':
20 db_query("CREATE TABLE {uc_product_kits} (
21 vid integer NOT NULL default 0,
22 nid integer NOT NULL default 0,
23 product_id integer NOT NULL default 0,
24 mutable smallint NOT NULL default 0,
25 qty smallint NOT NULL default 0,
26 discount float NOT NULL default 0.0,
27 ordering smallint NOT NULL default 0,
28 PRIMARY KEY (vid, product_id)
29 );");
30 break;
31 }
32 }
33
34 function uc_product_kit_uninstall() {
35 db_query("DROP TABLE {uc_product_kits}");
36 variable_del('uc_product_kit_mutable');
37 }
38
39 function uc_product_kit_update_1() {
40 $ret = array();
41 switch ($GLOBALS['db_type']) {
42 case 'mysql':
43 case 'mysqli':
44 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (nid, product_id)");
45 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN mutable tinyint(1) NOT NULL default 0 AFTER product_id");
46 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN discount float NOT NULL default 0.0 AFTER qty");
47 break;
48 case 'pgsql':
49 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (nid, product_id)");
50 db_add_column($ret, 'uc_product_kits', 'mutable', 'smallint', array('not null' => true, 'default' => 0));
51 db_add_column($ret, 'uc_product_kits', 'discount', 'float', array('not null' => true, 'default' => 0.0));
52 break;
53 }
54 return $ret;
55 }
56
57 function uc_product_kit_update_2() {
58 $ret = array();
59 switch ($GLOBALS['db_type']) {
60 case 'mysql':
61 case 'mysqli':
62 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN ordering smallint NOT NULL default 0");
63 break;
64 case 'pgsql':
65 db_add_column($ret, 'uc_product_kits', 'ordering', 'smallint', array('not null' => true, 'default' => 0));
66 break;
67 }
68 return $ret;
69 }
70
71 function uc_product_kit_update_3() {
72 $ret = array();
73 switch ($GLOBALS['db_type']) {
74 case 'mysql':
75 case 'mysqli':
76 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN vid mediumint(9) NOT NULL default 0 FIRST");
77 $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP PRIMARY KEY");
78 $result = db_query("SELECT nid, vid FROM {node}");
79 while ($product = db_fetch_object($result)) {
80 db_query("UPDATE {uc_product_kits} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
81 }
82 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (vid, product_id)");
83 break;
84 case 'pgsql':
85 db_add_column($ret, 'uc_product_kits', 'vid', 'mediumint', array('not null' => true, 'default' => 0));
86 $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP CONSTRAINT {uc_products}_pkey");
87 $result = db_query("SELECT nid, vid FROM {node}");
88 while ($product = db_fetch_object($result)) {
89 db_query("UPDATE {uc_product_kits} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
90 }
91 $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (vid, product_id)");
92 break;
93 }
94 return $ret;
95 }
96
97 function uc_product_kit_update_4() {
98 $ret = array();
99 db_query("UPDATE {node} SET type = 'product_kit' WHERE type = 'kit'");
100 if (module_exists('content')) {
101 $ret[] = update_sql("ALTER TABLE {content_type_kit} RENAME TO {content_type_product_kit}");
102 }
103 node_types_rebuild();
104 menu_rebuild();
105 return $ret;
106 }
107
108 function uc_product_kit_update_5() {
109 $ret = array();
110 switch ($GLOBALS['db_type']) {
111 case 'mysql':
112 case 'mysqli':
113 $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP data");
114 break;
115 case 'pgsql':
116 $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP data");
117 break;
118 }
119 return $ret;
120 }

  ViewVC Help
Powered by ViewVC 1.1.2