Add validation and access checking to addressable content.
[project/ctools.git] / ctools.install
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 // DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
56 // Changes to this table must be made in schema_3 or higher.
57 $schema['ctools_css_cache'] = array(
58 'description' => 'A special cache used to store CSS that must be non-volatile.',
59 'fields' => array(
60 'cid' => array(
61 'type' => 'varchar',
62 'length' => '128',
63 'description' => 'The CSS ID this cache object belongs to.',
64 'not null' => TRUE,
65 ),
66 'filename' => array(
67 'type' => 'varchar',
68 'length' => '255',
69 'description' => 'The filename this CSS is stored in.',
70 ),
71 'css' => array(
72 'type' => 'text',
73 'size' => 'big',
74 'description' => 'CSS being stored.',
75 'serialize' => TRUE,
76 ),
77 'filter' => array(
78 'type' => 'int',
79 'size' => 'tiny',
80 'description' => 'Whether or not this CSS needs to be filtered.',
81 ),
82 ),
83 'primary key' => array('cid'),
84 );
85
86 return $schema;
87 }
88
89 /**
90 * CTools' initial schema; separated for the purposes of updates.
91 *
92 * DO NOT MAKE CHANGES HERE. This schema version is locked.
93 */
94 function ctools_schema_1() {
95 $schema['ctools_object_cache'] = array(
96 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
97 'fields' => array(
98 'sid' => array(
99 'type' => 'varchar',
100 'length' => '64',
101 'not null' => TRUE,
102 'description' => 'The session ID this cache object belongs to.',
103 ),
104 'name' => array(
105 'type' => 'varchar',
106 'length' => '32',
107 'not null' => TRUE,
108 'description' => 'The name of the object this cache is attached to.',
109 ),
110 'obj' => array(
111 'type' => 'varchar',
112 'length' => '32',
113 'not null' => TRUE,
114 '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.',
115 ),
116 'updated' => array(
117 'type' => 'int',
118 'unsigned' => TRUE,
119 'not null' => TRUE,
120 'default' => 0,
121 'description' => 'The time this cache was created or updated.',
122 ),
123 'data' => array(
124 'type' => 'text',
125 'size' => 'big',
126 'description' => 'Serialized data being stored.',
127 'serialize' => TRUE,
128 ),
129 ),
130 'primary key' => array('sid', 'obj', 'name'),
131 'indexes' => array('updated' => array('updated')),
132 );
133 return $schema;
134 }
135
136 /**
137 * Enlarge the ctools_object_cache.name column to prevent truncation and weird
138 * errors.
139 */
140 function ctools_update_6001() {
141 // Perform updates like this to reduce code duplication.
142 $schema = ctools_schema_2();
143
144 db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
145 }
146
147 /**
148 * Add the new css cache table.
149 */
150 function ctools_update_6002() {
151 // Schema 2 is locked and should not be changed.
152 $schema = ctools_schema_2();
153
154 db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
155 }
156
157 /**
158 * Take over for the panels_views module if it was on.
159 */
160 function ctools_update_6003() {
161 $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
162 if ($result) {
163 db_delete('system')->condition('name', 'panels_views')->execute();
164 module_enable(array('views_content'), TRUE);
165 }
166 }
167
168 /**
169 * Add primary key to the ctools_object_cache table.
170 */
171 function ctools_update_6004() {
172 db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
173 db_drop_index('ctools_object_cache', 'sid_obj_name');
174 }
175
176 /**
177 * Removed update.
178 */
179 function ctools_update_6005() {
180 return array();
181 }
182
183 /**
184 * ctools_custom_content table was originally here, but is now moved to
185 * its own module.
186 */
187 function ctools_update_6007() {
188 $ret = array();
189 if (db_table_exists('ctools_custom_content')) {
190 // Enable the module to make everything as seamless as possible.
191 module_enable(array('ctools_custom_content'), TRUE);
192 }
193
194 return $ret;
195 }
196
197