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

Contents of /contributions/modules/quotes/quotes.install

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


Revision 1.7 - (show annotations) (download) (as text)
Mon Sep 7 18:26:23 2009 UTC (2 months, 3 weeks ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +35 -35 lines
File MIME type: text/x-php
Latest from Charles Mattice.
1 <?php
2 // $Id: quotes.install,v 1.6 2009/08/28 16:28:01 nancyw Exp $
3
4 /**
5 * @file
6 * Handles installation and updates for the quotes module.
7 *
8 * @copyright Copyright (c) 2003-2007 Jim Riggs. All rights reserved.
9 * @author Jim Riggs <drupal at jim and lissa dot com>
10 */
11
12 //********************************************************************
13 //* Drupal Hooks
14 //********************************************************************
15
16 /**
17 * Implements hook_schema().
18 */
19 function quotes_schema() {
20 $schema = array();
21 $schema['quotes'] = array(
22 'module' => 'Quotes',
23 'description' => 'Extra node data.',
24 'fields' => array(
25 'nid' => array(
26 'description' => 'Node identifier.',
27 'type' => 'int',
28 'unsigned' => TRUE,
29 'not null' => TRUE,
30 'disp-width' => '10',
31 ),
32 'vid' => array(
33 'description' => 'Version identifier.',
34 'type' => 'int',
35 'unsigned' => TRUE,
36 'not null' => TRUE,
37 'disp-width' => '10',
38 ),
39 'aid' => array(
40 'description' => 'Author identifier.',
41 'type' => 'int',
42 'unsigned' => TRUE,
43 'not null' => TRUE,
44 'disp-width' => '10',
45 ),
46 'citation' => array(
47 'description' => 'Source of the quote.',
48 'type' => 'text',
49 'not null' => FALSE,
50 ),
51 'promote' => array(
52 'description' => 'Status.',
53 'type' => 'int',
54 'size' => 'tiny',
55 'unsigned' => TRUE,
56 'not null' => TRUE,
57 'default' => 0,
58 ),
59 ),
60 'primary key' => array('vid'),
61 'indexes' => array(
62 'quotes_nid' => array('nid'),
63 'quotes_promote' => array('promote'),
64 'quotes_aid' => array('aid'),
65 ),
66 );
67
68 $schema['quotes_blocks'] = array(
69 'module' => 'Quotes',
70 'description' => 'Quotes blocks data.',
71 'fields' => array(
72 'bid' => array(
73 'description' => 'Block number',
74 'type' => 'serial',
75 'not null' => TRUE,
76 ),
77 'block_type' => array(
78 'description' => 'Type of block',
79 'type' => 'int',
80 'size' => 'tiny',
81 'not null' => TRUE,
82 ),
83 'vid' => array(
84 'description' => 'Version id',
85 'type' => 'int',
86 'not null' => TRUE,
87 ),
88 'count' => array(
89 'description' => 'Number of quotes in the block.',
90 'type' => 'int',
91 'not null' => FALSE,
92 'default' => 1,
93 ),
94 'cron_interval' => array(
95 'description' => 'Cron frequency',
96 'type' => 'int',
97 'not null' => TRUE,
98 ),
99 'cron_step' => array(
100 'description' => 'Cron step',
101 'type' => 'int',
102 'not null' => TRUE,
103 ),
104 'cron_last' => array(
105 'description' => 'Last Cron run time',
106 'type' => 'int',
107 'not null' => TRUE,
108 ),
109 'show_titles' => array(
110 'description' => 'Show titles.',
111 'type' => 'int',
112 'size' => 'small',
113 'not null' => FALSE,
114 'default' => 0,
115 ),
116 'show_citation' => array(
117 'description' => 'Show citation.',
118 'type' => 'int',
119 'size' => 'small',
120 'not null' => FALSE,
121 'default' => 0,
122 ),
123 'max_length' => array(
124 'description' => 'Maximum length of quote in block.',
125 'type' => 'int',
126 'not null' => FALSE,
127 'default' => 0,
128 ),
129 'rand_freq' => array(
130 'description' => 'Display frequency for random blocks.',
131 'type' => 'int',
132 'not null' => TRUE,
133 'default' => 100,
134 ),
135 'view_weight' => array(
136 'description' => 'Weight for the view link.',
137 'type' => 'int',
138 'size' => 'small',
139 'not null' => FALSE,
140 'default' => 1,
141 ),
142 'name' => array(
143 'description' => 'Name of this block',
144 'type' => 'varchar',
145 'length' => '255',
146 'not null' => TRUE,
147 ),
148 'nid_filter' => array(
149 'description' => 'Node filter',
150 'type' => 'text',
151 'not null' => TRUE,
152 ),
153 'aid_filter' => array(
154 'description' => 'Author filter',
155 'type' => 'text',
156 'not null' => TRUE,
157 ),
158 'rid_filter' => array(
159 'description' => 'Role filter',
160 'type' => 'text',
161 'not null' => TRUE,
162 ),
163 'uid_filter' => array(
164 'description' => 'User filter',
165 'type' => 'text',
166 'not null' => TRUE,
167 ),
168 'tid_filter' => array(
169 'description' => 'Term filter',
170 'type' => 'text',
171 'not null' => TRUE,
172 ),
173 'view_text' => array(
174 'description' => 'Text for the "view" link.',
175 'type' => 'varchar',
176 'length' => 64,
177 'not null' => FALSE,
178 ),
179 'more_text' => array(
180 'description' => 'Text for the "more" link.',
181 'type' => 'varchar',
182 'length' => 64,
183 'not null' => FALSE,
184 ),
185 ),
186 'primary key' => array('bid'),
187 'unique keys' => array(
188 'name' => array('name')),
189 );
190
191 $schema['quotes_authors'] = array(
192 'module' => 'Quotes',
193 'description' => 'Quotes authors data.',
194 'fields' => array(
195 'aid' => array(
196 'description' => 'Author identifier.',
197 'type' => 'serial',
198 'unsigned' => TRUE,
199 'not null' => TRUE,
200 'disp-width' => '10',
201 ),
202 'name' => array(
203 'description' => 'Author of the quote.',
204 'type' => 'text',
205 'not null' => TRUE,
206 ),
207 'bio' => array(
208 'description' => "Author's biography.",
209 'type' => 'text',
210 'not null' => FALSE,
211 ),
212 ),
213 'primary key' => array('aid'),
214 'unique keys' => array(
215 'name' => array(array('name', 255)),
216 ),
217 );
218
219 return $schema;
220 }
221
222 /**
223 * Implements hook_install().
224 */
225 function quotes_install() {
226 drupal_install_schema('quotes');
227 }
228
229 /**
230 * Implements hook_update_N().
231 */
232 function quotes_update_6100() {
233 // This update is provided for users upgrading from a release prior to 5.x-1.2.
234 $ret = array();
235
236 // 5.x-1.2 added 'citation'.
237 if (!db_column_exists('quotes', 'citation')) {
238 $spec = array(
239 'description' => 'Source of the quote.',
240 'type' => 'varchar',
241 'length' => '255',
242 'not null' => FALSE,
243 );
244 db_add_field($ret, 'quotes', 'citation', $spec);
245 }
246
247 return $ret;
248 }
249
250 /**
251 * Implements hook_update_N().
252 */
253 function quotes_update_6101() {
254 // This update adds a block count column.
255 $ret = array();
256
257 // Skip this if upgrading from 5.x later than this addition.
258 if (!db_column_exists('quotes_blocks', 'count')) {
259 $spec1 = array(
260 'description' => 'Number of quotes in the block.',
261 'type' => 'int',
262 'not null' => FALSE,
263 'default' => 1,
264 );
265 $spec2 = array(
266 'description' => 'Show titles.',
267 'type' => 'int',
268 'not null' => FALSE,
269 'default' => 0,
270 );
271 db_add_field($ret, 'quotes_blocks', 'count', $spec1);
272 db_add_field($ret, 'quotes_blocks', 'show_titles', $spec2);
273 }
274
275 return $ret;
276 }
277
278 /**
279 * Implements hook_update_N().
280 */
281 function quotes_update_6102() {
282 global $db_type;
283 $items = $create = array();
284
285 // Skip this if upgrading from 5.x later than this addition.
286 if (db_table_exists('quotes_authors')) {
287 return $items;
288 }
289
290 $schema['quotes_authors'] = array(
291 'module' => 'Quotes',
292 'description' => 'Quotes authors data.',
293 'fields' => array(
294 'aid' => array(
295 'description' => 'Author identifier.',
296 'type' => 'serial',
297 'unsigned' => TRUE,
298 'not null' => TRUE,
299 'disp-width' => '10',
300 ),
301 'name' => array(
302 'description' => 'Author of the quote.',
303 'type' => 'varchar',
304 'length' => '255',
305 'not null' => TRUE,
306 ),
307 'bio' => array(
308 'description' => "Author's biography.",
309 'type' => 'text',
310 'not null' => FALSE,
311 ),
312 ),
313 'primary key' => array('aid'),
314 'unique keys' => array(
315 'name' => array('name')),
316 );
317
318 db_create_table($items, 'quotes_authors', $schema['quotes_authors']);
319
320 // Add the aid column after the vid column.
321 db_add_column($items, 'quotes', 'aid', 'INT UNSIGNED NOT NULL AFTER vid');
322
323 $add = $items[count($items) - 1]['success'];
324 if (!$add) {
325 drupal_set_message(t('Add column "aid" failed.'), 'error');
326 return;
327 }
328
329 // Add an index for the aid.
330 db_add_index($items, 'quotes', 'quotes_aid', array('aid'));
331 $add = $items[count($items) - 1]['success'];
332 if (!$add) {
333 drupal_set_message(t('Add index for "aid" failed.'), 'error');
334 return;
335 }
336
337 // Get all the authors.
338 $result = db_query("SELECT DISTINCT(author) FROM {quotes} ORDER BY author");
339
340 while ($q = db_fetch_array($result)) {
341 $author = $q['author'];
342 // If the current author field has a mini-bio, split it off.
343 $paren = strpos($author, '(');
344 $comma = strpos($author, ',');
345 $sub = min(($paren === FALSE ? drupal_strlen($author) : $paren), ($comma === FALSE ? drupal_strlen($author) : $comma));
346 if ($sub === FALSE) {
347 $bio = NULL;
348 }
349 else {
350 $bio = trim(drupal_substr($author, $sub));
351 $author = trim(drupal_substr($author, 0, $sub));
352 }
353 // Add the row to the new table.
354 $items[] = update_sql("INSERT INTO {quotes_authors} (name, bio) VALUES ('" . db_escape_string($author) . "', '" . db_escape_string($bio) . "')");
355 $add = $items[count($items) - 1]['success'];
356 if ($add === FALSE) {
357 $aid = 'failed';
358 $upd = 'bypassed';
359 }
360 else {
361 $aid = db_result(db_query("SELECT LAST_INSERT_ID()"));
362 if ($aid < 1) {
363 drupal_set_message(t('Invalid aid returned:') . $aid, 'error');
364 }
365 $query = 'UPDATE {quotes} SET aid=' . $aid . " WHERE author='" . db_escape_string($q['author']) . "'";
366 $items[] = update_sql($query);
367 }
368 }
369
370 db_drop_field($items, 'quotes', 'author');
371 $del = $items[count($items) - 1]['success'];
372 if (!$del) {
373 drupal_set_message(t('Drop column "author" failed.'), 'error');
374 }
375
376 drupal_set_message(t('Update 6102 for Quotes complete.'), 'status');
377 return $items;
378 }
379
380 /**
381 * Implements hook_update_N().
382 * Change citation, author name to TEXT.
383 */
384 function quotes_update_6103() {
385 $ret = array();
386
387 db_change_field($ret, 'quotes', 'citation', 'citation', array('type' => 'text', 'not null' => FALSE));
388 db_drop_index($ret, 'quotes_authors', 'name');
389 db_change_field($ret, 'quotes_authors', 'name', 'name', array('type' => 'text', 'not null' => FALSE));
390 db_add_index($ret, 'quotes_authors', 'name', array(array('name', 255)));
391
392 return $ret;
393 }
394
395 /**
396 * Implements hook_update_N().
397 * Moving block variables to quotes_blocks table.
398 */
399 function quotes_update_6104() {
400 $ret = array();
401
402 db_change_field($ret, 'quotes_blocks', 'show_titles', 'show_titles', array('type' => 'int', 'size' => 'small'));
403 db_add_field($ret, 'quotes_blocks', 'show_citation',
404 array(
405 'description' => 'Show citation.',
406 'type' => 'int',
407 'size' => 'small',
408 'not null' => FALSE,
409 'default' => 0,
410 ));
411 db_add_field($ret, 'quotes_blocks', 'max_length',
412 array(
413 'description' => 'Maximum length of quote in block.',
414 'type' => 'int',
415 'not null' => TRUE,
416 'default' => 0,
417 ));
418 db_add_field($ret, 'quotes_blocks', 'view_weight',
419 array(
420 'description' => 'Weight for the view link.',
421 'type' => 'int',
422 'size' => 'small',
423 'not null' => FALSE,
424 'default' => 1,
425 ));
426 db_add_field($ret, 'quotes_blocks', 'more_text',
427 array(
428 'description' => 'Text for the "more" link.',
429 'type' => 'varchar',
430 'length' => 64,
431 'not null' => FALSE,
432 ));
433 db_add_field($ret, 'quotes_blocks', 'view_text',
434 array(
435 'description' => 'Text for the "view" link.',
436 'type' => 'varchar',
437 'length' => 64,
438 'not null' => FALSE,
439 ));
440
441 // Incorrectly set per block.
442 $max_len = variable_get('quotes_block_max_length', 0);
443
444 // Set globally in admin page.
445 $view_text = variable_get('quotes_block_view_text', t('View'));
446 $view_weight = variable_get('quotes_block_view_weight', 1);
447 $show_citation = variable_get('quotes_block_citation', TRUE);
448
449 $ret[] = update_sql("UPDATE {quotes_blocks} SET view_text='" . $view_text . "', view_weight=" . $view_weight . ", show_citation=" . $show_citation . ", max_length=" . $max_len . " WHERE 1=1");
450
451 // "more" text is per block already, but in a variable.
452 $result = db_query('SELECT bid FROM {quotes_blocks}');
453 while ($block = db_fetch_array($result)) {
454 $more_text = variable_get('quotes_more_' . $block['bid'], NULL);
455 $ret[] = update_sql("UPDATE {quotes_blocks} SET more_text='" . $more_text . "' WHERE bid=" . $block['bid']);
456 }
457 // Don't delete variables in case the update fails.
458
459 return $ret;
460 }
461
462 /**
463 * Implements hook_update_N().
464 * Adding author filter to quotes_blocks table.
465 */
466 function quotes_update_6105() {
467 $ret = array();
468
469 if (db_column_exists('quotes_blocks', 'aid_filter')) {
470 $ret[] = array('success' => TRUE, 'query' => t('The aid_filter column already exists.'));
471 db_change_field($ret, 'quotes_blocks', 'aid_filter', 'aid_filter', array('type' => 'text', 'not null' => TRUE));
472 }
473 else {
474 db_add_field($ret, 'quotes_blocks', 'aid_filter',
475 array(
476 'description' => 'Author filter.',
477 'type' => 'text',
478 'not null' => TRUE,
479 'initial' => 'none', /* see http://drupal.org/node/159329 */
480 ));
481 }
482
483 return $ret;
484 }
485
486 /**
487 * Implements hook_update_N().
488 * Adding random frequency to quotes_blocks table.
489 */
490 function quotes_update_6106() {
491 $ret = array();
492
493 if (db_column_exists('quotes_blocks', 'rand_freq')) {
494 $ret[] = array('success' => TRUE, 'query' => t('The rand_freq column already exists.'));
495 }
496 else {
497 db_add_field($ret, 'quotes_blocks', 'rand_freq',
498 array(
499 'description' => 'Display frequency for random blocks.',
500 'type' => 'int',
501 'not null' => TRUE,
502 'default' => 100,
503 ));
504 }
505
506 return $ret;
507 }
508
509 /**
510 * Implements hook_uninstall().
511 */
512 function quotes_uninstall() {
513 variable_del('quotes_author_bio');
514 variable_del('quotes_author_link');
515 variable_del('quotes_block_citation');
516 variable_del('quotes_block_view_text');
517 variable_del('quotes_block_view_weight');
518 variable_del('quotes_leader');
519 variable_del('quotes_node_view_link');
520 variable_del('quotes_node_view_weight');
521 variable_del('quotes_per_page');
522 variable_del('quotes_show_myquotes');
523 variable_del('quotes_showlink');
524 variable_del('quotes_user_recent');
525 db_query("DELETE FROM {variable} WHERE name LIKE ('quotes_more_%')");
526
527 // Remove all Quotes nodes.
528 $result = db_query("SELECT nid FROM {node} WHERE type = 'quotes'");
529 while ($obj = db_fetch_object($result)) {
530 node_delete($obj->nid);
531 }
532 drupal_uninstall_schema('quotes');
533
534 // Delete all our blocks.
535 db_query("DELETE FROM {blocks} WHERE module='quotes'");
536 }

  ViewVC Help
Powered by ViewVC 1.1.2