/[drupal]/contributions/modules/uc_coupon/uc_coupon.install
ViewVC logotype

Contents of /contributions/modules/uc_coupon/uc_coupon.install

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


Revision 1.12 - (show annotations) (download) (as text)
Thu Sep 17 18:24:54 2009 UTC (2 months, 1 week ago) by longwave
Branch: MAIN
Changes since 1.11: +2 -2 lines
File MIME type: text/x-php
#559972 by cha0s: uc_coupon_update_6001() PostgreSQL warning
1 <?php
2 // $Id: uc_coupon.install,v 1.11 2009/08/14 15:59:20 longwave Exp $
3
4 /**
5 * @file
6 * Ubercart uc_coupon.module schema
7 */
8
9 function uc_coupon_schema() {
10 $schema = array();
11
12 $schema['uc_coupons'] = array(
13 'description' => t('Ubercart Coupons'),
14 'fields' => array(
15 'cid' => array(
16 'type' => 'serial',
17 'unsigned' => TRUE,
18 'not null' => TRUE,
19 ),
20 'name' => array(
21 'type' => 'varchar',
22 'length' => 30,
23 'not null' => TRUE,
24 'default' => '',
25 ),
26 'code' => array(
27 'type' => 'varchar',
28 'length' => 40,
29 'not null' => TRUE,
30 'default' => '',
31 ),
32 'value' => array(
33 'type' => 'numeric',
34 'precision' => 6,
35 'scale' => 2,
36 'not null' => TRUE,
37 'default' => 0,
38 ),
39 'type' => array(
40 'type' => 'varchar',
41 'length' => '12',
42 'not null' => TRUE,
43 'default' => 'price',
44 ),
45 'status' => array(
46 'type' => 'int',
47 'size' => 'tiny',
48 'not null' => TRUE,
49 'default' => 1,
50 ),
51 'valid_from' => array(
52 'type' => 'int',
53 ),
54 'valid_until' => array(
55 'type' => 'int',
56 ),
57 'max_uses' => array(
58 'type' => 'int',
59 'size' => 'small',
60 'not null' => TRUE,
61 'default' => 0,
62 ),
63 'minimum_order' => array(
64 'type' => 'numeric',
65 'precision' => 6,
66 'scale' => 2,
67 'not null' => TRUE,
68 'default' => 0,
69 ),
70 'data' => array(
71 'type' => 'text',
72 ),
73 'bulk' => array(
74 'type' => 'int',
75 'size' => 'tiny',
76 'not null' => TRUE,
77 'default' => 0,
78 ),
79 'bulk_seed' => array(
80 'type' => 'char',
81 'length' => 32,
82 'not null' => TRUE,
83 'default' => '',
84 ),
85 ),
86 'primary key' => array('cid'),
87 );
88
89 $schema['uc_coupons_orders'] = array(
90 'description' => t('Ubercart Coupons used on Orders'),
91 'fields' => array(
92 'cuid' => array(
93 'type' => 'serial',
94 'unsigned' => TRUE,
95 'not null' => TRUE,
96 ),
97 'cid' => array(
98 'type' => 'int',
99 'unsigned' => TRUE,
100 'not null' => TRUE,
101 'default' => 0,
102 ),
103 'oid' => array(
104 'type' => 'int',
105 'unsigned' => TRUE,
106 'not null' => TRUE,
107 'default' => 0,
108 ),
109 'value' => array(
110 'type' => 'numeric',
111 'precision' => 10,
112 'scale' => 2,
113 'not null' => TRUE,
114 'default' => 0,
115 ),
116 'code' => array(
117 'type' => 'varchar',
118 'length' => 40,
119 'not null' => TRUE,
120 'default' => 'default_code',
121 ),
122 ),
123 'primary key' => array('cuid'),
124 );
125 return $schema;
126 }
127
128 function uc_coupon_install() {
129 drupal_install_schema('uc_coupon');
130 }
131
132 function uc_coupon_uninstall() {
133 drupal_uninstall_schema('uc_coupon');
134 }
135
136 function uc_coupon_update_6000() {
137 $ret = array();
138
139 if (!db_column_exists('uc_coupons', 'data')) {
140 db_add_field($ret, 'uc_coupons', 'data', array('type' => 'text'));
141
142 $result = db_query('SELECT cid, products, users, roles FROM {uc_coupons}');
143 while ($row = db_fetch_object($result)) {
144 $data = array('wholesale' => $row->roles);
145 if ($row->products) {
146 $data['products'] = explode(',', $row->products);
147 }
148 if ($row->users) {
149 // substr() removes the final comma that was present in the previous strings.
150 $data['users'] = explode(',', substr($row->users, 0, -1));
151 }
152 db_query("UPDATE {uc_coupons} SET data = '%s' WHERE cid = %d", serialize($data), $row->cid);
153 }
154
155 db_drop_field($ret, 'uc_coupons', 'products');
156 db_drop_field($ret, 'uc_coupons', 'users');
157 db_drop_field($ret, 'uc_coupons', 'roles');
158
159 db_drop_field($ret, 'uc_coupons_orders', 'user');
160 db_drop_field($ret, 'uc_coupons_orders', 'role');
161 }
162
163 return $ret;
164 }
165
166 function uc_coupon_update_6001() {
167 $ret = array();
168
169 if (!db_column_exists('uc_coupons', 'bulk')) {
170 $field = array(
171 'type' => 'int',
172 'size' => 'tiny',
173 'not null' => TRUE,
174 'default' => 0,
175 );
176 db_add_field($ret, 'uc_coupons', 'bulk', $field);
177
178 $field = array(
179 'type' => 'char',
180 'length' => 32,
181 'not null' => TRUE,
182 'default' => '',
183 );
184 db_add_field($ret, 'uc_coupons', 'bulk_seed', $field);
185 $ret[] = update_sql("UPDATE {uc_coupons} SET bulk_seed = MD5(CAST(RAND() AS CHAR(32))) WHERE bulk_seed = ''");
186 }
187
188 return $ret;
189 }
190
191 function uc_coupon_update_6002() {
192 $ret = array();
193
194 if (!db_column_exists('uc_coupons', 'valid_from')) {
195 db_add_field($ret, 'uc_coupons', 'valid_from', array('type' => 'int'));
196 $ret[] = update_sql("UPDATE {uc_coupons} SET valid_from = 0");
197 }
198
199 return $ret;
200 }

  ViewVC Help
Powered by ViewVC 1.1.2