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

Contents of /contributions/modules/api/api.install

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


Revision 1.11 - (show annotations) (download) (as text)
Mon Dec 29 21:36:19 2008 UTC (10 months, 3 weeks ago) by drumm
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.10: +26 -1 lines
File MIME type: text/x-php
Do not show duplicate function signatures.
1 <?php
2 // $Id: api.install,v 1.10 2008/12/27 00:02:49 drumm Exp $
3
4 function api_schema() {
5 $schema['api_branch'] = array(
6 'fields' => array(
7 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''),
8 'title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
9 'directory' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
10 'weight' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
11 ),
12 'primary key' => array('branch_name'),
13 'indexes' => array(
14 'weight' => array('weight'),
15 ),
16 );
17 $schema['api_documentation'] = array(
18 'fields' => array(
19 'did' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
20 'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''),
21 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''),
22 'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''),
23 'title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
24 'file_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''),
25 'summary' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
26 'documentation' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
27 'code' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
28 ),
29 'primary key' => array('did'),
30 'unique keys' => array(
31 'object_name' => array('object_name', 'branch_name', 'object_type'),
32 ),
33 'indexes' => array(
34 'branch_name' => array('branch_name'),
35 'title' => array('title'),
36 ),
37 );
38 $schema['api_file'] = array(
39 'fields' => array(
40 'did' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
41 'modified' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
42 'version' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
43 'found' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '1'),
44 ),
45 'primary key' => array('did'),
46 );
47 $schema['api_function'] = array(
48 'fields' => array(
49 'did' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
50 'signature' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
51 'start_line' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
52 'parameters' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
53 'return_value' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
54 ),
55 'primary key' => array('did'),
56 );
57 $schema['api_reference_storage'] = array(
58 'fields' => array(
59 'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''),
60 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''),
61 'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''),
62 'from_did' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
63 'to_did' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
64 ),
65 'indexes' => array(
66 'object_ref' => array('object_name', 'branch_name', 'object_type'),
67 ),
68 );
69
70 return $schema;
71 }
72
73 function api_install() {
74 drupal_install_schema('api');
75 }
76
77 function api_update_1() {
78 return _system_update_utf8(array('api_branch', 'api_documentation', 'api_file', 'api_function', 'api_reference'));
79 }
80
81 function api_update_2() {
82 $ret = array();
83 db_add_column($ret, 'api_file', 'found', 'tinyint', array('not null' => TRUE, 'default' => 0, 'length' => 1, 'unsigned' => TRUE));
84
85 return $ret;
86 }
87
88 function api_update_3() {
89 $ret[] = update_sql("CREATE TABLE {api_reference_storage} (
90 reference_key text NOT NULL,
91 from_did int(10) NOT NULL default '0'
92 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
93
94 $reference = variable_get('api_reference', array());
95 foreach (array_keys($reference) as $key) {
96 foreach ($reference[$key] as $from_did) {
97 db_query("INSERT INTO {api_reference_storage} (reference_key, from_did) VALUES ('%s', %d)", $key, $from_did);
98 }
99 }
100 variable_del('api_reference');
101 }
102
103 function api_update_4() {
104 $return = array();
105 db_add_index($return, 'api_documentation', '', 'branch_name');
106 return $return;
107 }
108
109 function api_update_5() {
110 $return = array();
111 db_add_index($return, 'api_documentation', '', 'title');
112
113 return $return;
114 }
115
116 /**
117 * Further optimize the reference storage by letting the database handle the aggregrate
118 * operations.
119 */
120 function api_update_6() {
121 $return = array();
122 $schema['api_reference_storage'] = array(
123 'fields' => array(
124 'object_name' => array(
125 'type' => 'varchar',
126 'length' => '127',
127 'not null' => TRUE,
128 'default' => '',
129 ),
130 'branch_name' => array(
131 'type' => 'varchar',
132 'length' => 31,
133 'not null' => TRUE,
134 'default' => '',
135 ),
136 'object_type' => array(
137 'type' => 'varchar',
138 'length' => 31,
139 'not null' => TRUE,
140 'default' => '',
141 ),
142 'from_did' => array(
143 'type' => 'int',
144 'not null' => TRUE,
145 'default' => '0'
146 ),
147 'to_did' => array(
148 'type' => 'int',
149 'not null' => TRUE,
150 'default' => '0'),
151 ),
152 'indexes' => array(
153 'api_documentation_object_ref' => array('object_name', 'branch_name', 'object_type'),
154 ),
155 );
156
157 db_rename_table($return, 'api_reference_storage', 'api_reference_storage_old');
158 db_create_table($return, 'api_reference_storage', $schema['api_reference_storage']);
159
160 $result = db_query('SELECT * FROM {api_reference_storage}');
161 while ($row = db_fetch_object($result)) {
162 list($branch_name, $to_type, $to_name) = unserialize($row->reference_key);
163 db_query("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch_name, $to_type, $row->from_did);
164 }
165
166 db_drop_table($return, 'api_reference_storage_old');
167
168 return $return;
169 }
170
171 /**
172 * Move data from {api_reference} to {api_reference_storage}.
173 */
174 function api_update_7() {
175 $return = array();
176
177 $return[] = update_sql("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did, to_did) SELECT d.object_name, d.branch_name, d.object_type, r.from_did, r.to_did FROM {api_reference} r INNER JOIN {api_documentation} d ON d.did = r.to_did");
178 db_drop_table($return, 'api_reference');
179
180 return $return;
181 }
182
183 function api_update_8() {
184 $return = array();
185
186 db_drop_primary_key($return, 'api_documentation');
187 db_change_field($return, 'api_documentation', 'did', 'did',
188 array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
189 array('primary key' => array('did'))
190 );
191
192 return $return;
193 }
194
195 /**
196 * Change the branch directories delimiter from : to \n.
197 */
198 function api_update_9() {
199 $return = array();
200
201 $result = db_query("SELECT branch_name, directory FROM {api_branch} WHERE directory LIKE '%:%'");
202 while ($branch = db_fetch_object($result)) {
203 db_query("UPDATE {api_branch} SET directory = '%s' WHERE branch_name = '%s'", strtr($branch->directory, ':', "\n"), $branch->branch_name);
204 }
205
206 return $return;
207 }
208
209 /**
210 * Make sure block cache rules are set properly.
211 */
212 function api_update_10() {
213 $return = array();
214
215 $return[] = update_sql("UPDATE {blocks} SET cache = ". (BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE) ." WHERE module = 'api'");
216
217 return $return;
218 }
219
220 /**
221 * return is a reserved word.
222 */
223 function api_update_11() {
224 $return = array();
225
226 db_change_field($return, 'api_function', '`return`', 'return_value',
227 array('type' => 'text', 'size' => 'medium', 'not null' => TRUE)
228 );
229
230 return $return;
231 }
232
233 /**
234 * Add a weight column to branches to simplify various algorithms.
235 */
236 function api_update_12() {
237 $return = array();
238
239 db_add_field($return, 'api_branch', 'weight', array(
240 'type' => 'int',
241 'unsigned' => TRUE,
242 'size' => 'tiny',
243 'not null' => TRUE,
244 'default' => 0,
245 ), array(
246 'indexes' => array(
247 'weight' => array('weight'),
248 ),
249 ));
250
251 return $return;
252 }
253
254 function api_uninstall() {
255 drupal_uninstall_schema('api');
256 variable_del('api_default_branch');
257 variable_del('api_php_funcsummary');
258 variable_del('api_php_funcpath');
259 variable_del('api_files_per_cron');
260 variable_del('api_reference');
261 }

  ViewVC Help
Powered by ViewVC 1.1.2