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

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

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


Revision 1.12 - (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.11: +255 -108 lines
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Database installation, uninstallation, and updates for the product module.
7 */
8
9 /**
10 * Ubercart uc_product.module schema
11 */
12 function uc_product_schema() {
13 $schema = array();
14
15 $schema['uc_product_classes'] = array(
16 'description' => t('The list of product node types.'),
17 'fields' => array(
18 'pcid' => array(
19 'description' => t('The node type identifier.'),
20 'type' => 'varchar',
21 'length' => 32,
22 'not null' => TRUE,
23 'default' => '',
24 ),
25 'name' => array(
26 'description' => t('The human-readable name.'),
27 'type' => 'varchar',
28 'length' => 255,
29 'not null' => TRUE,
30 'default' => '',
31 ),
32 'description' => array(
33 'type' => 'text',
34 ),
35 ),
36 'primary key' => array('pcid'),
37 );
38 $schema['uc_product_features'] = array(
39 'fields' => array(
40 'pfid' => array(
41 'description' => t('The product feature id.'),
42 'type' => 'serial',
43 'unsigned' => TRUE,
44 'not null' => TRUE,
45 ),
46 'nid' => array(
47 'description' => t('The identifier of the node that has a feature.'),
48 'type' => 'int',
49 'unsigned' => TRUE,
50 'not null' => TRUE,
51 'default' => 0,
52 ),
53 'fid' => array(
54 'type' => 'varchar',
55 'length' => 32,
56 'not null' => TRUE,
57 'default' => '',
58 ),
59 'description' => array(
60 'type' => 'text',
61 ),
62 ),
63 'indexes' => array(
64 'uc_product_features_nid' => array('nid'),
65 ),
66 'primary key' => array('pfid'),
67 );
68 $schema['uc_products'] = array(
69 'description' => t('Product information for nodes.'),
70 'fields' => array(
71 'vid' => array(
72 'description' => t('Revision id of the product node.'),
73 'type' => 'int',
74 'unsigned' => TRUE,
75 'not null' => TRUE,
76 'default' => 0,
77 ),
78 'nid' => array(
79 'description' => t('The product node id.'),
80 'type' => 'int',
81 'unsigned' => TRUE,
82 'not null' => TRUE,
83 'default' => 0,
84 ),
85 'model' => array(
86 'description' => t('SKU or model number.'),
87 'type' => 'varchar',
88 'length' => 255,
89 'not null' => TRUE,
90 'default' => '',
91 ),
92 'list_price' => array(
93 'description' => t('Suggested retail price.'),
94 'type' => 'numeric',
95 'precision' => 10,
96 'scale' => 2,
97 'unsigned' => TRUE,
98 'not null' => TRUE,
99 'default' => 0.0,
100 ),
101 'cost' => array(
102 'description' => t('The amount the store pays to sell the product.'),
103 'type' => 'numeric',
104 'precision' => 10,
105 'scale' => 2,
106 'unsigned' => TRUE,
107 'not null' => TRUE,
108 'default' => 0.0,
109 ),
110 'sell_price' => array(
111 'description' => t('The amount the customer pays for the product.'),
112 'type' => 'numeric',
113 'precision' => 10,
114 'scale' => 2,
115 'unsigned' => TRUE,
116 'not null' => TRUE,
117 'default' => 0.0,
118 ),
119 'weight' => array(
120 'description' => t('Physical weight.'),
121 'type' => 'float',
122 'unsigned' => TRUE,
123 'not null' => TRUE,
124 'default' => 0.0,
125 ),
126 'weight_units' => array(
127 'description' => t('Unit of measure for the weight field.'),
128 'type' => 'varchar',
129 'length' => 255,
130 'not null' => TRUE,
131 'default' => 'lb',
132 ),
133 'length' => array(
134 'description' => t('Physical length of the product or its packaging.'),
135 'type' => 'float',
136 'unsigned' => TRUE,
137 'not null' => TRUE,
138 'default' => 0.0,
139 ),
140 'width' => array(
141 'description' => t('Physical width of the product or its packaging.'),
142 'type' => 'float',
143 'unsigned' => TRUE,
144 'not null' => TRUE,
145 'default' => 0.0,
146 ),
147 'height' => array(
148 'description' => t('Physical height of the product or its packaging.'),
149 'type' => 'float',
150 'unsigned' => TRUE,
151 'not null' => TRUE,
152 'default' => 0.0,
153 ),
154 'length_units' => array(
155 'description' => t('Unit of measure for the length, width, and height.'),
156 'type' => 'varchar',
157 'length' => 255,
158 'not null' => TRUE,
159 'default' => 'in',
160 ),
161 'pkg_qty' => array(
162 'description' => t('The number of this product that fit in one package.'),
163 'type' => 'int',
164 'size' => 'small',
165 'unsigned' => TRUE,
166 'not null' => TRUE,
167 'default' => 1,
168 ),
169 'default_qty' => array(
170 'description' => t('The default value for the quantity field in the "Add to Cart" form.'),
171 'type' => 'int',
172 'size' => 'small',
173 'unsigned' => TRUE,
174 'not null' => TRUE,
175 'default' => 1,
176 ),
177 'unique_hash' => array(
178 'description' => t('A multi-site unique identifier for a product.'),
179 'type' => 'varchar',
180 'length' => 32,
181 'not null' => TRUE,
182 'default' => md5(''),
183 ),
184 'ordering' => array(
185 'description' => t('The sort criteria for products.'),
186 'type' => 'int',
187 'size' => 'tiny',
188 'not null' => TRUE,
189 'default' => 0,
190 ),
191 'shippable' => array(
192 'description' => t('Boolean flag signifying that the product can be shipped.'),
193 'type' => 'int',
194 'size' => 'tiny',
195 'unsigned' => TRUE,
196 'not null' => TRUE,
197 'default' => 1,
198 ),
199 ),
200 'primary key' => array('vid'),
201 );
202
203 return $schema;
204 }
205
206 function uc_product_install() {
207 drupal_install_schema('uc_product');
208 }
209
210 function uc_product_uninstall() {
211 drupal_uninstall_schema('uc_product');
212
213 variable_del('uc_product_nodes_per_page');
214 variable_del('uc_product_add_to_cart_qty');
215 variable_del('uc_product_add_to_cart_teaser');
216 variable_del('uc_teaser_add_to_cart_text');
217 variable_del('uc_product_add_to_cart_text');
218 variable_del('uc_product_field_enabled');
219 variable_del('uc_product_field_weight');
220 }
221
222 function uc_product_update_1() {
223 $ret = array();
224 switch ($GLOBALS['db_type']) {
225 case 'mysql':
226 case 'mysqli':
227 $ret[] = update_sql("ALTER TABLE {uc_class_choices} CHANGE name name varchar(255) NOT NULL");
228 $ret[] = update_sql("ALTER TABLE {uc_class_fields} CHANGE name name varchar(255) NOT NULL, DROP COLUMN title");
229 $ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE name name varchar(255) NOT NULL");
230 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} CHANGE value value varchar(255) NOT NULL, ADD PRIMARY KEY (nid, cfid, value)");
231 $ret[] = update_sql("ALTER TABLE {uc_products} CHANGE model model varchar(255) NOT NULL");
232 break;
233 case 'pgsql':
234 db_change_column($ret, 'uc_class_choices', 'name', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
235 db_change_column($ret, 'uc_class_fields', 'name', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
236 $ret[] = update_sql("ALTER TABLE {uc_class_fields} DROP title");
237 db_change_column($ret, 'uc_product_classes', 'name', 'name', 'varchar(255)', array('not null' => true, 'default' => ''));
238 db_change_column($ret, 'uc_product_class_choices', 'value', 'value', 'varchar(255)', array('not null' => true, 'default' => ''));
239 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value)");
240 db_change_column($ret, 'uc_products', 'model', 'model', 'varchar(255)', array('not null' => true, 'default' => ''));
241 break;
242 }
243
244 if ($max_id = db_result(db_query_range("SELECT cfid FROM {uc_class_fields} ORDER BY cfid DESC", 0, 1))) {
245 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{uc_class_fields}_cfid', %d)", $max_id);
246 }
247
248 return $ret;
249 }
250
251 function uc_product_update_2() {
252 $ret = array();
253 switch ($GLOBALS['db_type']) {
254 case 'mysql':
255 case 'mysqli':
256 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} DROP PRIMARY KEY");
257 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} CHANGE value value text NOT NULL");
258 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value (3))");
259 break;
260 case 'pgsql':
261 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} DROP CONSTRAINT {uc_product_class_choices}_pkey");
262 db_change_column($ret, 'uc_product_class_choices', 'value', 'value', 'text', array('not null' => true, 'default' => ''));
263 $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value (3))");
264 break;
265 }
266 return $ret;
267 }
268
269 function uc_product_update_3() {
270 $ret = array();
271 switch ($GLOBALS['db_type']) {
272 case 'mysql':
273 case 'mysqli':
274 $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN units varchar(255) NOT NULL default 'lbs' AFTER weight");
275 break;
276 case 'pgsql':
277 db_add_column($ret, 'uc_products', 'units', 'varchar(255)', array('not null' => true, 'default' => 'lbs'));
278 break;
279 }
280 return $ret;
281 }
282
283 function uc_product_update_4() {
284 $ret = array();
285
286 $ret[] = update_sql("UPDATE {node} AS n, {uc_products} AS p, {uc_product_classes} AS pc SET n.type = REPLACE(LOWER(pc.name), ' ', '_') WHERE n.nid = p.nid AND p.pcid = pc.pcid");
287 switch ($GLOBALS['db_type']) {
288 case 'mysql':
289 case 'mysqli':
290 $ret[] = update_sql("DROP TABLE {uc_class_choices}");
291 $ret[] = update_sql("DROP TABLE {uc_class_fields}");
292 $ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
293 $ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE pcid pcid varchar(32) NOT NULL");
294 $ret[] = update_sql("ALTER TABLE {uc_product_classes} ADD COLUMN description text");
295 $ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
296 break;
297 case 'pgsql':
298 $ret[] = update_sql("DROP TABLE {uc_class_choices}");
299 $ret[] = update_sql("DROP TABLE {uc_class_fields}");
300 $ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
301 $ret[] = update_sql("DROP INDEX {uc_product_classes}_pcid_idx");
302 db_change_column($ret, 'uc_product_classes', 'pcid', 'pcid', 'varchar(32)', array('not null' => true, 'default' => ''));
303 db_add_column($ret, 'uc_product_classes', 'description', 'text');
304 $ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
305 break;
306 }
307 $ret[] = update_sql("UPDATE {uc_product_classes} SET pcid = REPLACE(LOWER(name), ' ', '_')");
308 if ($vid = variable_get('uc_catalog_vid', 0)) {
309 $types = module_invoke_all('product_types');
310 unset($types['product']);
311 foreach ($types as $type) {
312 $placeholders[] = "(%d, '%s')";
313 $values[] = $vid;
314 $values[] = $type;
315 }
316 $result = db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES ". implode(',', $placeholders), $values);
317 $ret[] = array('success' => $result, 'query' => t('Added the following node types to the Catalog vocabulary: %list', array('%list' => implode(', ', $values))));
318 }
319
320 node_types_rebuild();
321
322 return $ret;
323 }
324
325 function uc_product_update_5() {
326 $ret = array();
327
328 switch ($GLOBALS['db_type']) {
329 case 'mysql':
330 case 'mysqli':
331 $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN default_qty smallint(5) unsigned NOT NULL default '1' AFTER units");
332 break;
333 case 'pgsql':
334 db_add_column($ret, 'uc_products', 'default_qty', 'smallint unsigned', array('not null' => true, 'default' => 1));
335 break;
336 }
337
338 return $ret;
339 }
340
341 function uc_product_update_6() {
342 $ret = array();
343
344 switch ($GLOBALS['db_type']) {
345 case 'mysql':
346 case 'mysqli':
347 $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN ordering smallint(2) NOT NULL default 0");
348 break;
349 case 'pgsql':
350 db_add_column($ret, 'uc_products', 'default_qty', 'smallint(2)', array('not null' => true, 'default' => 0));
351 break;
352 }
353
354 return $ret;
355 }
356
357 function uc_product_update_7() {
358 $ret = array();
359 switch ($GLOBALS['db_type']) {
360 case 'mysql':
361 case 'mysqli':
362 $ret[] = update_sql("ALTER TABLE {uc_products} CHANGE units weight_units varchar(255) NOT NULL default 'lb'");
363 $ret[] = update_sql("ALTER TABLE {uc_products} ADD length float unsigned NOT NULL default 0 AFTER weight_units");
364 $ret[] = update_sql("ALTER TABLE {uc_products} ADD width float unsigned NOT NULL default 0 AFTER length");
365 $ret[] = update_sql("ALTER TABLE {uc_products} ADD height float unsigned NOT NULL default 0 AFTER width");
366 $ret[] = update_sql("ALTER TABLE {uc_products} ADD length_units varchar(255) NOT NULL default 'in' AFTER height");
367 $ret[] = update_sql("ALTER TABLE {uc_products} ADD pkg_qty smallint unsigned NOT NULL default 1 AFTER length_units");
368 break;
369 case 'pgsql':
370 db_change_column($ret, 'uc_products', 'units', 'weight_units', 'varchar(255)', array('not null' => true, 'default' => 'lb'));
371 db_add_column($ret, 'uc_products', 'pkg_qty', 'smallint unsigned', array('not null' => true, 'default' => 1));
372 db_add_column($ret, 'uc_products', 'length', 'float unsigned', array('not null' => true, 'default' => 0));
373 db_add_column($ret, 'uc_products', 'width', 'float unsigned', array('not null' => true, 'default' => 0));
374 db_add_column($ret, 'uc_products', 'height', 'float unsigned', array('not null' => true, 'default' => 0));
375 db_add_column($ret, 'uc_products', 'length_units', 'varchar(255)', array('not null' => true, 'default' => 'in'));
376 break;
377 }
378 return $ret;
379 }
380
381 function uc_product_update_8() {
382 $ret = array();
383 switch ($GLOBALS['db_type']) {
384 case 'mysql':
385 case 'mysqli':
386 $ret[] = update_sql("ALTER TABLE {uc_products} ADD vid mediumint(9) NOT NULL default 0 FIRST");
387 $ret[] = update_sql("ALTER TABLE {uc_products} DROP PRIMARY KEY");
388 $result = db_query("SELECT nid, vid FROM {node}");
389 while ($product = db_fetch_object($result)) {
390 db_query("UPDATE {uc_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
391 }
392 $ret[] = update_sql("ALTER TABLE {uc_products} ADD PRIMARY KEY (vid)");
393 break;
394 case 'pgsql':
395 db_add_column($ret, 'uc_products', 'vid', 'integer', array('not null' => true, 'default' => 0));
396 $ret[] = update_sql("ALTER TABLE {uc_products} DROP CONSTRAINT {uc_products}_pkey");
397 $result = db_query("SELECT nid, vid FROM {node}");
398 while ($product = db_fetch_object($result)) {
399 db_query("UPDATE {uc_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
400 }
401 $ret[] = update_sql("ALTER TABLE {uc_products} ADD PRIMARY KEY (vid)");
402 break;
403 }
404 return $ret;
405 }
406
407 // Update to add in product feature support.
408 function uc_product_update_9() {
409 $ret = array();
410 switch ($GLOBALS['db_type']) {
411 case 'mysql':
412 case 'mysqli':
413 $ret[] = update_sql("CREATE TABLE {uc_product_features} (
414 `pfid` mediumint(9) NOT NULL default 0,
415 `nid` mediumint(9) NOT NULL default 0,
416 `fid` varchar(32) NOT NULL,
417 `description` text,
418 PRIMARY KEY (`pfid`),
419 KEY nid (nid)
420 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
421 break;
422 }
423
424 return $ret;
425 }
426
427 // Update to add the shippable column to the product table.
428 function uc_product_update_10() {
429 $ret = array();
430 switch ($GLOBALS['db_type']) {
431 case 'mysql':
432 case 'mysqli':
433 $ret[] = update_sql("ALTER TABLE {uc_products} ADD shippable tinyint(2) NOT NULL default 1");
434 break;
435 case 'pgsql':
436 db_add_column($ret, 'uc_products', 'shippable', 'tinyint', array('not null' => true, 'default' => 1));
437 break;
438 }
439 return $ret;
440 }
441
442 function uc_product_update_11() {
443 $ret = array();
444 switch ($GLOBALS['db_type']) {
445 case 'pgsql':
446 db_change_column($ret, 'uc_products', 'pkg_qty', 'pkg_qty', 'smallint_unsigned', array('not null' => true, 'default' => 1));
447 db_change_column($ret, 'uc_products', 'default_qty', 'defautl_qty', 'smallint_unsigned', array('not null' => true, 'default' => 1));
448 break;
449 }
450 return $ret;
451 }
452
453 function uc_product_update_12() {
454 $ret = array();
455
456 if (module_exists('imagecache')) {
457 $preset_id = db_next_id('{imagecache_preset}_presetid');
458 $action_id = db_next_id('{imagecache_action}_actionid');
459 db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'uc_thumbnail')", $preset_id);
460 db_query("INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (%d, %d, 0, '%s')", $action_id, $preset_id, 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"35";s:6:"height";s:2:"35";}');
461 cache_clear_all('imagecache:presets', 'cache');
462 $ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (". $preset_id .", 'uc_thumbnail')");
463 $ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (". $action_id .", ". $preset_id .", 0, '". 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"35";s:6:"height";s:2:"35";}' ."')");
464 }
465
466 return $ret;
467 }

  ViewVC Help
Powered by ViewVC 1.1.2