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

Contents of /contributions/modules/nodeorder/nodeorder.install

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


Revision 1.2 - (show annotations) (download) (as text)
Wed Apr 22 18:45:19 2009 UTC (7 months ago) by pvanderspek
Branch: MAIN
Changes since 1.1: +106 -36 lines
File MIME type: text/x-php
merged changes from 6.x branch into HEAD
1 <?php
2 // $Id: nodeorder.install,v 1.1.6.9 2009/01/17 16:45:09 pvanderspek Exp $
3
4 /**
5 * @file
6 * Nodeorder install file.
7 */
8
9 /**
10 * Implementation of hook_install()
11 *
12 * Adds field 'weight_in_tid' to core table 'term_node'.
13 */
14 function nodeorder_install() {
15 $module_name = 'nodeorder';
16
17 // Set field properties
18 $spec = array(
19 'type' => 'int',
20 'signed' => TRUE,
21 'not null' => TRUE,
22 'default' => 0,
23 'initial' => 0,
24 'description' => t('A user-defined weight for each node in its respective category.')
25 );
26
27 // Create an index for 'weight_in_tid'
28 $keys['indexes'] = array('weight_in_tid' => array('weight_in_tid'));
29
30 // Add the column to the table
31 $ret = array();
32 db_add_field($ret, 'term_node', 'weight_in_tid', $spec, $keys);
33
34 // Check for query errors
35 for ($i = 0; $i < count($ret); $i++) {
36 if ($ret[$i]['success'] !== TRUE) {
37 $installation_failed = TRUE;
38 break;
39 }
40 }
41
42 if ($installation_failed) {
43 drupal_set_message(st('Table installation for the %name module was unsuccessful. The tables may need to be installed by hand. See %name.install file for a list of the installation queries.', array('%name' => $module_name)), 'error');
44 }
45 else {
46 // Set the weight of the nodeorder module in the system table
47 // so that we come after most other modules in module_invoke_all()
48 // calls. This ensures that we can alter forms after, for instance,
49 // the taxonomy module...
50 db_query("UPDATE {system} SET weight = 5 WHERE name = 'nodeorder' AND type = 'module'");
51
52 drupal_set_message(st('The %name module installed successfully.', array('%name' => $module_name)));
53 }
54 }
55
56 /**
57 * Implementation of hook_uninstall()
58 *
59 * Drops field 'weight_in_tid' from core table 'term_node'.
60 */
61 function nodeorder_uninstall() {
62 $module_name = 'nodeorder';
63
64 $ret = array();
65 db_drop_index($ret, 'term_node', 'weight_in_tid');
66 db_drop_field($ret, 'term_node', 'weight_in_tid');
67
68 // Check for query errors
69 for ($i = 0; $i < count($ret); $i++) {
70 if ($ret[$i]['success'] !== TRUE) {
71 $installation_failed = TRUE;
72 break;
73 }
74 }
75
76 if ($installation_failed) {
77 drupal_set_message(st('Table uninstallation for the %name module was unsuccessful. The tables may need to be installed by hand. See %name.install file for a list of the installation queries.', array('%name' => $module_name)), 'error');
78 }
79 else {
80 drupal_set_message(st('The %name module uninstalled successfully.', array('%name' => $module_name)));
81 }
82 }
83
84 /**
85 * Implementation of hook_schema_alter()
86 *
87 * Informs drupal_get_schema() of the field addition to 'term_node'.
88 */
89 function nodeorder_schema_alter(&$schema) {
90 $schema['term_node']['fields']['weight_in_tid'] = array(
91 'type' => 'int',
92 'signed' => TRUE,
93 'not null' => TRUE,
94 'default' => 0,
95 'initial' => 0,
96 'description' => t('A user-defined weight for each node in its respective category.'),
97 );
98 }
99
100 /**
101 * Update function for Nodeorder-6.x-1.*
102 * Original nodeorder schema used an unsigned field for the weight.
103 * With the new ordering from core this should be changed to a signed field.
104 * We therefore take the following measures:
105 * - change the field to a signed field
106 */
107 function nodeorder_update_6100() {
108 $ret = array();
109
110 // Create an index for 'weight_in_tid'
111 $keys['indexes'] = array('weight_in_tid' => array('weight_in_tid'));
112
113 // Set field properties
114 $spec = array(
115 'type' => 'int',
116 'signed' => TRUE,
117 'not null' => TRUE,
118 'default' => 0,
119 'initial' => 0,
120 'description' => t('A user-defined weight for each node in its respective category.')
121 );
122
123 // change field to a SIGNED int
124 db_change_field($ret, 'term_node', 'weight_in_tid', 'weight_in_tid', $spec, $keys);
125
126 return $ret;
127 }

  ViewVC Help
Powered by ViewVC 1.1.2