| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function uc_catalog_schema() {
|
| 5 |
$schema = array();
|
| 6 |
|
| 7 |
$schema['uc_catalog_images'] = array(
|
| 8 |
'fields' => array(
|
| 9 |
'fid' => array(
|
| 10 |
'type' => 'int',
|
| 11 |
'unsigned' => TRUE,
|
| 12 |
'not null' => TRUE,
|
| 13 |
'default' => 0,
|
| 14 |
),
|
| 15 |
'tid' => array(
|
| 16 |
'type' => 'int',
|
| 17 |
'unsigned' => TRUE,
|
| 18 |
'not null' => TRUE,
|
| 19 |
'default' => 0,
|
| 20 |
),
|
| 21 |
'filename' => array(
|
| 22 |
'type' => 'varchar',
|
| 23 |
'length' => 255,
|
| 24 |
'not null' => TRUE,
|
| 25 |
'default' => '',
|
| 26 |
),
|
| 27 |
'filepath' => array(
|
| 28 |
'type' => 'varchar',
|
| 29 |
'length' => 255,
|
| 30 |
'not null' => TRUE,
|
| 31 |
'default' => '',
|
| 32 |
),
|
| 33 |
'filemime' => array(
|
| 34 |
'type' => 'varchar',
|
| 35 |
'length' => 255,
|
| 36 |
'not null' => TRUE,
|
| 37 |
'default' => '',
|
| 38 |
),
|
| 39 |
'filesize' => array(
|
| 40 |
'type' => 'int',
|
| 41 |
'unsigned' => TRUE,
|
| 42 |
'not null' => TRUE,
|
| 43 |
'default' => 0,
|
| 44 |
),
|
| 45 |
),
|
| 46 |
'primary key' => array('fid'),
|
| 47 |
);
|
| 48 |
|
| 49 |
return $schema;
|
| 50 |
}
|
| 51 |
|
| 52 |
function uc_catalog_install() {
|
| 53 |
$t = get_t();
|
| 54 |
//Find possible Product Catalog vocabulary.
|
| 55 |
$result = db_query("SELECT vid FROM {vocabulary} WHERE name = 'Catalog'");
|
| 56 |
if ($vocab = db_fetch_object($result)) {
|
| 57 |
$vid = $vocab->vid;
|
| 58 |
}
|
| 59 |
else { //If none, create one.
|
| 60 |
db_query("INSERT INTO {vocabulary} (name, description, help, relations, hierarchy, multiple, required, tags, module, weight)
|
| 61 |
VALUES ('%s', '', '%s', 0, 2, 1, 0, 0, 'uc_catalog', 0)", $t('Catalog'), $t('Hold Ctrl while clicking to select multiple categories.'));
|
| 62 |
$vid = db_last_insert_id('vocabulary', 'vid');
|
| 63 |
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, 'product')", $vid);
|
| 64 |
}
|
| 65 |
variable_set('uc_catalog_vid', $vid);
|
| 66 |
variable_set('uc_catalog_name', t('Catalog'));
|
| 67 |
|
| 68 |
switch ($GLOBALS['db_type']) {
|
| 69 |
case 'mysql':
|
| 70 |
case 'mysqli':
|
| 71 |
// Initially allow everyone to view the catalog.
|
| 72 |
db_query("UPDATE {permission} SET perm = CONCAT_WS(', ', perm, 'view catalog')");
|
| 73 |
case 'pgsql':
|
| 74 |
// Initially allow everyone to view the catalog.
|
| 75 |
db_query("UPDATE {permission} SET perm = perm || ', view catalog'");
|
| 76 |
break;
|
| 77 |
}
|
| 78 |
|
| 79 |
drupal_install_schema('uc_catalog');
|
| 80 |
}
|
| 81 |
|
| 82 |
function uc_catalog_uninstall() {
|
| 83 |
drupal_uninstall_schema('uc_catalog');
|
| 84 |
if ($vid = variable_get('uc_catalog_vid', 0)) {
|
| 85 |
taxonomy_del_vocabulary($vid);
|
| 86 |
}
|
| 87 |
variable_del('uc_catalog_vid');
|
| 88 |
variable_del('uc_catalog_name');
|
| 89 |
variable_del('uc_catalog_description');
|
| 90 |
variable_del('uc_catalog_breadcrumb');
|
| 91 |
variable_del('uc_catalog_block_nodecount');
|
| 92 |
variable_del('uc_catalog_breadcrumb_nodecount');
|
| 93 |
variable_del('uc_catalog_show_subcategories');
|
| 94 |
variable_del('uc_catalog_expand_categories');
|
| 95 |
variable_del('uc_catalog_category_columns');
|
| 96 |
}
|
| 97 |
|
| 98 |
function uc_catalog_update_1() {
|
| 99 |
$ret = array();
|
| 100 |
switch ($GLOBALS['db_type']) {
|
| 101 |
case 'mysql':
|
| 102 |
case 'mysqli':
|
| 103 |
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_catalog_images} (
|
| 104 |
`fid` int(10) unsigned NOT NULL default '0',
|
| 105 |
`tid` int(10) unsigned NOT NULL default '0',
|
| 106 |
`filename` varchar(255) NOT NULL default '',
|
| 107 |
`filepath` varchar(255) NOT NULL default '',
|
| 108 |
`filemime` varchar(255) NOT NULL default '',
|
| 109 |
`filesize` int(10) unsigned NOT NULL default '0',
|
| 110 |
PRIMARY KEY (`fid`)
|
| 111 |
);");
|
| 112 |
break;
|
| 113 |
case 'pgsql':
|
| 114 |
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_catalog_images} (
|
| 115 |
fid integer unsigned NOT NULL default 0,
|
| 116 |
tid integer unsigned NOT NULL default 0,
|
| 117 |
filename varchar(255) NOT NULL default '',
|
| 118 |
filepath varchar(255) NOT NULL default '',
|
| 119 |
filemime varchar(255) NOT NULL default '',
|
| 120 |
filesize integer unsigned NOT NULL default 0,
|
| 121 |
PRIMARY KEY (fid)
|
| 122 |
);");
|
| 123 |
break;
|
| 124 |
}
|
| 125 |
return $ret;
|
| 126 |
}
|
| 127 |
|
| 128 |
function uc_catalog_update_2() {
|
| 129 |
variable_del('uc_catalog_url');
|
| 130 |
return array(array('success' => TRUE, 'query' => "variable_del('uc_catalog_url')"));
|
| 131 |
}
|
| 132 |
|
| 133 |
function uc_catalog_update_3() {
|
| 134 |
$ret = array();
|
| 135 |
switch ($GLOBALS['db_type']) {
|
| 136 |
case 'pgsql':
|
| 137 |
db_change_column($ret, 'uc_catalog_images', 'fid', 'fid', 'int_unsigned', array('not null' => true, 'default' => 0));
|
| 138 |
db_change_column($ret, 'uc_catalog_images', 'tid', 'tid', 'int_unsigned', array('not null' => true, 'default' => 0));
|
| 139 |
db_change_column($ret, 'uc_catalog_images', 'filesize', 'filesize', 'int_unsigned', array('not null' => true, 'default' => 0));
|
| 140 |
break;
|
| 141 |
}
|
| 142 |
return $ret;
|
| 143 |
}
|
| 144 |
|
| 145 |
function uc_catalog_update_4() {
|
| 146 |
$ret = array();
|
| 147 |
$result = db_query("SELECT rid FROM {permission} WHERE perm NOT LIKE '%%%s%%'", 'view catalog');
|
| 148 |
while ($role = db_fetch_object($result)) {
|
| 149 |
$sql_result = db_query("UPDATE {permission} SET perm = CONCAT_WS(', ', perm, 'view catalog') WHERE rid = %d", $role->rid);
|
| 150 |
$ret[] = array('success' => $sql_result !== FALSE, 'query' => "UPDATE {permission} SET perm = CONCAT_WS(', ', perm, 'view catalog') WHERE rid = ". $role->rid);
|
| 151 |
}
|
| 152 |
return $ret;
|
| 153 |
}
|
| 154 |
|
| 155 |
function uc_catalog_update_5() {
|
| 156 |
variable_del('uc_catalog_special_block');
|
| 157 |
variable_del('uc_catalog_special_block_lines');
|
| 158 |
variable_del('uc_catalog_special_block_help');
|
| 159 |
variable_del('uc_catalog_special_block_help_allowed');
|
| 160 |
variable_del('uc_catalog_special_block_title');
|
| 161 |
variable_del('uc_catalog_bestsellers_block');
|
| 162 |
variable_del('uc_catalog_bestsellers_block_lines');
|
| 163 |
variable_del('uc_catalog_bestsellers_block_help');
|
| 164 |
variable_del('uc_catalog_bestsellers_block_help_allowed');
|
| 165 |
variable_del('uc_catlaog_bestsellers_block_title');
|
| 166 |
variable_del('uc_catalog_contact_url');
|
| 167 |
variable_del('uc_catalog_consult_block');
|
| 168 |
|
| 169 |
return array(array('success' => TRUE, 'query' => "DELETE unused variables"));
|
| 170 |
}
|
| 171 |
|
| 172 |
function uc_catalog_update_6() {
|
| 173 |
$ret = array();
|
| 174 |
|
| 175 |
if (module_exists('imagecache')) {
|
| 176 |
$preset_id = db_next_id('{imagecache_preset}_presetid');
|
| 177 |
$action_id = db_next_id('{imagecache_action}_actionid');
|
| 178 |
db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'uc_catalog')", $preset_id);
|
| 179 |
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:"96";s:6:"height";s:2:"96";}');
|
| 180 |
cache_clear_all('imagecache:presets', 'cache');
|
| 181 |
$ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (". $preset_id .", 'uc_catalog')");
|
| 182 |
$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:"96";s:6:"height";s:2:"96";}' ."')");
|
| 183 |
}
|
| 184 |
|
| 185 |
return $ret;
|
| 186 |
}
|
| 187 |
|
| 188 |
function uc_catalog_update_7() {
|
| 189 |
$ret = array();
|
| 190 |
|
| 191 |
if (module_exists('imagecache')) {
|
| 192 |
if (db_num_rows(db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'uc_category'")) == 0) {
|
| 193 |
$preset_id = db_next_id('{imagecache_preset}_presetid');
|
| 194 |
$action_id = db_next_id('{imagecache_action}_actionid');
|
| 195 |
db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'uc_category')", $preset_id);
|
| 196 |
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:"96";s:6:"height";s:2:"96";}');
|
| 197 |
cache_clear_all('imagecache:presets', 'cache');
|
| 198 |
$ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (". $preset_id .", 'uc_category')");
|
| 199 |
$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:"96";s:6:"height";s:2:"96";}' ."')");
|
| 200 |
if ($old_id = db_result(db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'uc_catalog'"))) {
|
| 201 |
_imagecache_preset_flush($old_id);
|
| 202 |
db_query("DELETE FROM {imagecache_preset} WHERE presetid = %d", $old_id);
|
| 203 |
db_query("DELETE FROM {imagecache_action} WHERE presetid = %d", $old_id);
|
| 204 |
$ret[] = array('success' => TRUE, 'query' => "DELETE FROM {imagecache_action} WHERE presetid = $old_id");
|
| 205 |
$ret[] = array('success' => TRUE, 'query' => "DELETE FROM {imagecache_action} WHERE presetid = $old_id");
|
| 206 |
_imagecache_get_presets(TRUE);
|
| 207 |
}
|
| 208 |
}
|
| 209 |
}
|
| 210 |
|
| 211 |
return $ret;
|
| 212 |
}
|