comparison sites/all/modules/quicktabs/quicktabs.install @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents
children a75ead649730
comparison
equal deleted inserted replaced
1:67ce89da90df 2:b74b41bb73f0
1 <?php
2
3 /**
4 * @file
5 * Install, update and uninstall functions for the quicktabs module.
6 */
7
8 /**
9 * Implements hook_schema().
10 */
11 function quicktabs_schema() {
12 $schema['quicktabs'] = array(
13 'description' => 'The quicktabs table.',
14 'export' => array(
15 'key' => 'machine_name',
16 'identifier' => 'quicktabs',
17 'default hook' => 'quicktabs_default_quicktabs',
18 'api' => array(
19 'owner' => 'quicktabs',
20 'api' => 'quicktabs',
21 'minimum_version' => 1,
22 'current_version' => 1,
23 ),
24 'export callback' => 'quicktabs_export',
25 ),
26 'fields' => array(
27 'machine_name' => array(
28 'description' => 'The primary identifier for a qt block.',
29 'type' => 'varchar',
30 'length' => 255,
31 'not null' => TRUE,
32 ),
33 'ajax' => array(
34 'description' => 'Whether this is an ajax views block.',
35 'type' => 'int',
36 'unsigned' => TRUE,
37 'not null' => TRUE,
38 'default' => 0,
39 ),
40 'hide_empty_tabs' => array(
41 'description' => 'Whether this tabset hides empty tabs.',
42 'type' => 'int',
43 'size' => 'tiny',
44 'unsigned' => TRUE,
45 'not null' => TRUE,
46 'default' => 0,
47 ),
48 'default_tab' => array(
49 'description' => 'Default tab.',
50 'type' => 'int',
51 'unsigned' => TRUE,
52 'not null' => TRUE,
53 'default' => 0,
54 ),
55 'title' => array(
56 'description' => 'The title of this quicktabs block.',
57 'type' => 'varchar',
58 'length' => 255,
59 'not null' => TRUE,
60 ),
61 'tabs' => array(
62 'description' => 'A serialized array of the contents of this qt block.',
63 'type' => 'text',
64 'size' => 'medium',
65 'not null' => TRUE,
66 'serialize' => TRUE,
67 ),
68 'renderer' => array(
69 'description' => 'The rendering mechanism.',
70 'type' => 'varchar',
71 'length' => 255,
72 'not null' => TRUE,
73 ),
74 'style' => array(
75 'description' => 'The tab style.',
76 'type' => 'varchar',
77 'length' => 255,
78 'not null' => TRUE,
79 ),
80 'options' => array(
81 'description' => 'A serialized array of the options for this qt instance.',
82 'type' => 'text',
83 'size' => 'medium',
84 'not null' => FALSE,
85 'serialize' => TRUE,
86 ),
87 ),
88 'primary key' => array('machine_name'),
89 );
90 return $schema;
91 }
92
93
94 /**
95 * Update to 7.x-3.x
96 */
97 function quicktabs_update_7300() {
98
99 if (!db_field_exists('quicktabs', 'machine_name')) {
100 // Pull all existing quicktabs, and then delete existing quicktabs. We will reinsert.
101 $result = db_query("SELECT * FROM {quicktabs}");
102 if (!db_query("DELETE FROM {quicktabs}")) {
103 throw new DrupalUpdateException(t('Could not complete the update.'));
104 }
105
106 db_drop_field('quicktabs', 'qtid');
107 $name_field = array(
108 'description' => 'The primary identifier for a qt block.',
109 'type' => 'varchar',
110 'length' => 255,
111 'not null' => TRUE,
112 );
113 db_add_field('quicktabs', 'machine_name', $name_field);
114 db_add_primary_key('quicktabs', array('machine_name'));
115
116 $output = $used = array();
117 foreach ($result as $qt) {
118 $row = (array)$qt;
119 // Generate a machine-readable string
120 $qt_name = strtolower(preg_replace('/[^a-zA-Z0-9_]+/', '_', $row['title']));
121 $i = 0;
122 while (in_array($i == 0 ? $qt_name : "{$qt_name}_{$i}", $used)) {
123 $i++;
124 }
125 $row['machine_name'] = $used[] = $i == 0 ? $qt_name : "{$qt_name}_{$i}";
126 unset($row['qtid']);
127 unset($row['style']);
128 $row['renderer'] = 'tabs';
129 $placeholders = implode(', ', array_keys($row));
130 $values = array();
131 // Ugh - really?? Somebody tell me there's a better way to do this :-/
132 foreach ($row as $name => $value) {
133 $values[':' . $name] = $value;
134 }
135 $tokens = implode(', ', array_keys($values));
136 db_query("INSERT INTO {quicktabs} ($placeholders) VALUES($tokens)", $values);
137
138 $output[] = "Converted quicktab {$row['machine_name']}.";
139 }
140 }
141
142 // Add the renderer field
143 $renderer_field = array(
144 'description' => 'The rendering mechanism.',
145 'type' => 'varchar',
146 'length' => 255,
147 'not null' => TRUE,
148 'default' => 'quicktabs',
149 );
150 db_add_field('quicktabs', 'renderer', $renderer_field);
151 $output[] = "Added the renderer field";
152
153
154 return implode('<br />', $output);
155 }
156
157 /**
158 * Add the options field which will hold renderer-specific options.
159 */
160 function quicktabs_update_7301() {
161 $options_field = array(
162 'description' => 'A serialized array of the options for this qt instance.',
163 'type' => 'text',
164 'size' => 'medium',
165 'not null' => FALSE,
166 'serialize' => TRUE,
167 );
168 db_add_field('quicktabs', 'options', $options_field);
169 return "Added the options field";
170 }
171
172 /**
173 * Rebuild the registry because of changed method name.
174 */
175 function quicktabs_update_7302() {
176 registry_rebuild();
177 }