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

Contents of /contributions/modules/faceted_search/faceted_search.install

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


Revision 1.12 - (show annotations) (download) (as text)
Sun Jan 4 19:36:25 2009 UTC (10 months, 3 weeks ago) by davidlesieur
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA2, DRUPAL-6--1-0-BETA1, HEAD
Changes since 1.11: +89 -17 lines
File MIME type: text/x-php
Improved data model for search environment settings.
1 <?php
2 // $Id: faceted_search.install,v 1.11 2008/08/26 04:28:10 davidlesieur Exp $
3
4 /**
5 * Implementation of hook_schema().
6 */
7 function faceted_search_schema() {
8 $schema['faceted_search_env'] = array(
9 'fields' => array(
10 'env_id' => array(
11 'type' => 'serial',
12 'unsigned' => TRUE,
13 'not null' => TRUE,
14 'description' => t('The primary identifier for a faceted search environment.'),
15 ),
16 'name' => array(
17 'type' => 'varchar',
18 'length' => '32',
19 'default' => '',
20 'not null' => TRUE,
21 'description' => t('The unique name of the faceted search environment. May only be alphanumeric characters plus underscores.'),
22 ),
23 'description' => array(
24 'type' => 'varchar',
25 'length' => '255',
26 'default' => '',
27 'description' => t('The description of the faceted search environment.'),
28 ),
29 'settings' => array(
30 'type' => 'text',
31 'size' => 'big',
32 'not null' => FALSE,
33 'serialize' => TRUE,
34 'description' => t('A serialized array of settings for the faceted search environment.'),
35 ),
36 ),
37 'primary key' => array('env_id'),
38 );
39
40 $schema['faceted_search_filters'] = array(
41 'description' => t(''),
42 'fields' => array(
43 'env_id' => array(
44 'description' => t(''),
45 'type' => 'int',
46 'unsigned' => TRUE,
47 'not null' => TRUE,
48 'default' => 0,
49 'disp-width' => '10'
50 ),
51 'filter_key' => array(
52 'description' => t(''),
53 'type' => 'varchar',
54 'length' => '32',
55 'not null' => TRUE,
56 'default' => ''
57 ),
58 'filter_id' => array(
59 'description' => t(''),
60 'type' => 'varchar',
61 'length' => '32',
62 'not null' => TRUE,
63 'default' => ''
64 ),
65 'status' => array(
66 'description' => t(''),
67 'type' => 'int',
68 'not null' => TRUE,
69 'default' => 0,
70 'disp-width' => '11'
71 ),
72 'weight' => array(
73 'description' => t(''),
74 'type' => 'int',
75 'not null' => TRUE,
76 'default' => 0,
77 'disp-width' => '11'
78 ),
79 'sort' => array(
80 'description' => t(''),
81 'type' => 'varchar',
82 'length' => '32',
83 'not null' => TRUE,
84 'default' => ''
85 ),
86 'max_categories' => array(
87 'description' => t(''),
88 'type' => 'int',
89 'not null' => TRUE,
90 'default' => 0,
91 'disp-width' => '11'
92 )
93 ),
94 'primary key' => array('env_id', 'filter_key', 'filter_id'),
95 'indexes' => array(
96 'status' => array('status')
97 ),
98 );
99
100 return $schema;
101 }
102
103 /**
104 * Implementation of hook_install().
105 */
106 function faceted_search_install() {
107 drupal_install_schema('faceted_search');
108 }
109
110 /**
111 * Implementation of hook_uninstall().
112 */
113 function faceted_search_uninstall() {
114 drupal_uninstall_schema('faceted_search');
115 }
116
117 /**
118 * Replace the faceted_search_variables table with a better data structure.
119 */
120 function faceted_search_update_6000() {
121 $ret = array();
122
123 $schema['faceted_search_env'] = array(
124 'fields' => array(
125 'env_id' => array(
126 'type' => 'serial',
127 'unsigned' => TRUE,
128 'not null' => TRUE,
129 'description' => t('The primary identifier for a faceted search environment.'),
130 ),
131 'name' => array(
132 'type' => 'varchar',
133 'length' => '32',
134 'default' => '',
135 'not null' => TRUE,
136 'description' => t('The unique name of the faceted search environment. May only be alphanumeric characters plus underscores.'),
137 ),
138 'description' => array(
139 'type' => 'varchar',
140 'length' => '255',
141 'default' => '',
142 'description' => t('The description of the faceted search environment.'),
143 ),
144 'settings' => array(
145 'type' => 'text',
146 'size' => 'big',
147 'not null' => FALSE,
148 'serialize' => TRUE,
149 'description' => t('A serialized array of settings for the faceted search environment.'),
150 ),
151 ),
152 'primary key' => array('env_id'),
153 );
154 db_create_table($ret, 'faceted_search_env', $schema['faceted_search_env']);
155
156 // Retrieve all the old variables.
157 $variables = array();
158 $results = db_query("SELECT * FROM {faceted_search_variables}");
159 while ($result = db_fetch_object($results)) {
160 $variables[$result->env_id][$result->name] = unserialize($result->value);
161 }
162
163 // Rearrange and write them into the new structure.
164 foreach ($variables as $env_id => $settings) {
165 // Write base record.
166 $name = db_escape_string($settings['name']);
167 $description = db_escape_string($settings['description']);
168 $ret[] = update_sql("INSERT INTO {faceted_search_env} (env_id, name, description) VALUES ($env_id, '$name', '$description')");
169
170 // Remove unwanted variables.
171 unset($settings['name']);
172 unset($settings['description']);
173 unset($settings['form_build_id']); // An error had introduced this variable in older versions.
174
175 // Write settings data. Because update_sql() does not support placeholders and
176 // would remove the curly braces contained in our serialized data if we
177 // embedded it directly in the query string, we use db_query() instead.
178 db_query("UPDATE {faceted_search_env} SET settings = '%s' WHERE env_id = %d", serialize($settings), $env_id);
179 }
180
181 // Delete old table.
182 db_drop_table($ret, 'faceted_search_variables');
183
184 return $ret;
185 }
186

  ViewVC Help
Powered by ViewVC 1.1.2