comparison sites/all/modules/ctools/ctools.install @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?php
2
3 /**
4 * @file
5 * Contains install and update functions for ctools.
6 */
7
8 /**
9 * Use requirements to ensure that the CTools CSS cache directory can be
10 * created and that the PHP version requirement is met.
11 */
12 function ctools_requirements($phase) {
13 $requirements = array();
14 if ($phase == 'runtime') {
15 $requirements['ctools_css_cache'] = array(
16 'title' => t('CTools CSS Cache'),
17 'severity' => REQUIREMENT_OK,
18 'value' => t('Exists'),
19 );
20
21 $path = 'public://ctools/css';
22 if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
23 $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory, %path could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.', array('%path' => file_uri_target($path)));
24 $requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
25 $requirements['ctools_css_cache']['value'] = t('Unable to create');
26 }
27
28 if (!function_exists('error_get_last')) {
29 $requirements['ctools_php_52']['title'] = t('CTools PHP requirements');
30 $requirements['ctools_php_52']['description'] = t('CTools requires certain features only available in PHP 5.2.0 or higher.');
31 $requirements['ctools_php_52']['severity'] = REQUIREMENT_WARNING;
32 $requirements['ctools_php_52']['value'] = t('PHP !version', array('!version' => phpversion()));
33 }
34 }
35
36 return $requirements;
37 }
38
39 /**
40 * Implements hook_schemea
41 */
42 function ctools_schema() {
43 return ctools_schema_2();
44 }
45
46 /**
47 * Version 2 of the CTools schema.
48 */
49 function ctools_schema_2() {
50 $schema = ctools_schema_1();
51
52 // update the 'name' field to be 128 bytes long:
53 $schema['ctools_object_cache']['fields']['name']['length'] = 128;
54
55 // Update the 'data' field to be type 'blob'.
56 $schema['ctools_object_cache']['fields']['data'] = array(
57 'type' => 'blob',
58 'size' => 'big',
59 'description' => 'Serialized data being stored.',
60 'serialize' => TRUE,
61 );
62
63 // DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
64 // Changes to this table must be made in schema_3 or higher.
65 $schema['ctools_css_cache'] = array(
66 'description' => 'A special cache used to store CSS that must be non-volatile.',
67 'fields' => array(
68 'cid' => array(
69 'type' => 'varchar',
70 'length' => '128',
71 'description' => 'The CSS ID this cache object belongs to.',
72 'not null' => TRUE,
73 ),
74 'filename' => array(
75 'type' => 'varchar',
76 'length' => '255',
77 'description' => 'The filename this CSS is stored in.',
78 ),
79 'css' => array(
80 'type' => 'text',
81 'size' => 'big',
82 'description' => 'CSS being stored.',
83 'serialize' => TRUE,
84 ),
85 'filter' => array(
86 'type' => 'int',
87 'size' => 'tiny',
88 'description' => 'Whether or not this CSS needs to be filtered.',
89 ),
90 ),
91 'primary key' => array('cid'),
92 );
93
94 return $schema;
95 }
96
97 /**
98 * CTools' initial schema; separated for the purposes of updates.
99 *
100 * DO NOT MAKE CHANGES HERE. This schema version is locked.
101 */
102 function ctools_schema_1() {
103 $schema['ctools_object_cache'] = array(
104 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
105 'fields' => array(
106 'sid' => array(
107 'type' => 'varchar',
108 'length' => '64',
109 'not null' => TRUE,
110 'description' => 'The session ID this cache object belongs to.',
111 ),
112 'name' => array(
113 'type' => 'varchar',
114 'length' => '32',
115 'not null' => TRUE,
116 'description' => 'The name of the object this cache is attached to.',
117 ),
118 'obj' => array(
119 'type' => 'varchar',
120 'length' => '32',
121 'not null' => TRUE,
122 'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
123 ),
124 'updated' => array(
125 'type' => 'int',
126 'unsigned' => TRUE,
127 'not null' => TRUE,
128 'default' => 0,
129 'description' => 'The time this cache was created or updated.',
130 ),
131 'data' => array(
132 'type' => 'text',
133 'size' => 'big',
134 'description' => 'Serialized data being stored.',
135 'serialize' => TRUE,
136 ),
137 ),
138 'primary key' => array('sid', 'obj', 'name'),
139 'indexes' => array('updated' => array('updated')),
140 );
141 return $schema;
142 }
143
144 /**
145 * Enlarge the ctools_object_cache.name column to prevent truncation and weird
146 * errors.
147 */
148 function ctools_update_6001() {
149 // Perform updates like this to reduce code duplication.
150 $schema = ctools_schema_2();
151
152 db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
153 }
154
155 /**
156 * Add the new css cache table.
157 */
158 function ctools_update_6002() {
159 // Schema 2 is locked and should not be changed.
160 $schema = ctools_schema_2();
161
162 db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
163 }
164
165 /**
166 * Take over for the panels_views module if it was on.
167 */
168 function ctools_update_6003() {
169 $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
170 if ($result) {
171 db_delete('system')->condition('name', 'panels_views')->execute();
172 module_enable(array('views_content'), TRUE);
173 }
174 }
175
176 /**
177 * Add primary key to the ctools_object_cache table.
178 */
179 function ctools_update_6004() {
180 db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
181 db_drop_index('ctools_object_cache', 'sid_obj_name');
182 }
183
184 /**
185 * Removed update.
186 */
187 function ctools_update_6005() {
188 return array();
189 }
190
191 /**
192 * ctools_custom_content table was originally here, but is now moved to
193 * its own module.
194 */
195 function ctools_update_6007() {
196 $ret = array();
197 if (db_table_exists('ctools_custom_content')) {
198 // Enable the module to make everything as seamless as possible.
199 module_enable(array('ctools_custom_content'), TRUE);
200 }
201
202 return $ret;
203 }
204
205 /**
206 * ctools_object_cache needs to be defined as a blob.
207 */
208 function ctools_update_6008() {
209 db_delete('ctools_object_cache')
210 ->execute();
211
212 db_change_field('ctools_object_cache', 'data', 'data', array(
213 'type' => 'blob',
214 'size' => 'big',
215 'description' => 'Serialized data being stored.',
216 'serialize' => TRUE,
217 )
218 );
219 }