Newer
Older
Arto Bendiken
committed
<?php
// $Id$
/**
* @file
* Handles Boost module installation and upgrade tasks.
*/
//////////////////////////////////////////////////////////////////////////////
// Core API hooks
/**
* Implementation of hook_enable().
*/
function boost_enable() {
Arto Bendiken
committed
drupal_set_message(t('Boost successfully installed. Please review the available <a href="@settings">configuration settings</a>.', array('@settings' => url('admin/settings/performance'))));
// Forcibly disable Drupal's built-in SQL caching to prevent any conflicts of interest:
if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) {
variable_set('cache', CACHE_DISABLED);
drupal_set_message(t('Drupal\'s standard page caching disabled by Boost.'));
}
Arto Bendiken
committed
/**
* Implementation of hook_disable().
*/
function boost_disable() {
// Make sure that the static page cache is wiped when the module is disabled:
Arto Bendiken
committed
boost_cache_clear_all();
drupal_set_message(t('Static page cache cleared.'));
}
Arto Bendiken
committed
/**
Arto Bendiken
committed
* Implementation of hook_install().
Arto Bendiken
committed
*/
function boost_install() {
Arto Bendiken
committed
// Ensure that the module is loaded early in the bootstrap:
db_query("UPDATE {system} SET weight = -90 WHERE name = '%s'", 'boost');
// Create tables.
drupal_install_schema('boost');
Arto Bendiken
committed
/**
* Implementation of hook_uninstall().
*/
function boost_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%'", 'boost');
cache_clear_all('variables', 'cache');
// Delete tables.
drupal_uninstall_schema('boost');
Arto Bendiken
committed
}
/**
* Implementation of hook_requirements().
*/
function boost_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'runtime':
$cache_directory = variable_get('boost_file_path', boost_cache_directory(NULL, FALSE));
$htaccess = file_get_contents('.htaccess');
Mike Carper
committed
_boost_mkdir_p($cache_directory);
Mike Carper
committed
$root_file = file_put_contents($cache_directory . '/' . variable_get('boost_root_file', '.boost'), $cache_directory);
if ($cache_directory != boost_cache_directory(NULL, FALSE)) {
$requirements['boost'] = array(
'title' => $t('Boost'),
'description' => $t('!url: is not set to the default(!default). ', array('!url' => l('Cache file path', 'admin/settings/performance'), '!default' => boost_cache_directory(NULL, FALSE))),
'severity' => REQUIREMENT_WARNING,
Mike Carper
committed
'value' => $t('Cache path'),
elseif (!is_dir($cache_directory)) {
$requirements['boost'] = array(
'title' => $t('Boost'),
Mike Carper
committed
'description' => $t('!cache_dir: does not exist.', array('!cache_dir' => $cache_directory)),
'severity' => REQUIREMENT_ERROR,
Mike Carper
committed
'value' => $t('Cache path'),
elseif ($htaccess && count(explode("%{REQUEST_URI}_%{QUERY_STRING}\.html", $htaccess)) < 5) {
$requirements['boost'] = array(
'title' => $t('Boost'),
'description' => $t('.htaccess file does not contain the boost specific rewrite rules, or the rewrite rules have changed and they need to be updated.', array()),
'severity' => REQUIREMENT_ERROR,
'value' => $t('.htaccess file'),
elseif (!$root_file || !is_writable($cache_directory)) {
Mike Carper
committed
$requirements['boost'] = array(
'title' => $t('Boost'),
'description' => $t('Directory %dir credentials - Permissions: %fp. Owner %fo. Group %fg.<br /> Your credentials - Group ID: %gid. User ID: %uid. Current script owner: %user.', array('%dir' => getcwd() . '/' . $cache_directory, '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user(), '%fp' => substr(sprintf('%o', fileperms($cache_directory)), -4), '%fo' => fileowner($cache_directory), '%fg' => filegroup($cache_directory) )),
Mike Carper
committed
'severity' => REQUIREMENT_ERROR,
'value' => $t('Can not write to filesystem'),
);
}
elseif ((variable_get('statistics_count_content_views', 0) || variable_get('statistics_enable_access_log', 0)) && !file_exists('boost_stats.php')) {
$requirements['boost'] = array(
'title' => $t('Boost'),
'description' => $t('Copy the boost_stats.php file to your webroot. It should be located in the modules/boost/stats directory.'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('boost_stats.php missing from root dir'),
);
}
else {
$requirements['boost'] = array(
'title' => $t('Boost'),
'severity' => REQUIREMENT_OK,
'value' => t(''),
);
}
break;
return $requirements;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* Implementation of hook_schema().
*/
function boost_schema() {
$schema['boost_cache'] = array(
'description' => t('List of the cached page'),
'fields' => array(
'filename' => array(
'description' => 'Path of the cached file relative to Drupal root.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'expire' => array(
'description' => t('UNIX timestamp for the expiration date of cached page.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'lifetime' => array(
'description' => t('Number of seconds this page should be considered fresh. Used to set the expiration column.'),
'type' => 'int',
'not null' => TRUE,
'default' => -1,
),
'push' => array(
'description' => 'A flag to indicate whether page should be crawled so it is fresh in the cache.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => -1,
),
'page_callback' => array(
'description' => 'The name of the function that renders the page.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'page_arguments' => array(
'description' => 'The name of the content type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
),
'indexes' => array(
'expire' => array('expire'),
'push' => array('push'),
),
'primary key' => array('filename'),
);
$schema['boost_cache_settings'] = array(
'description' => t('Boost cache settings'),
'fields' => array(
'csid' => array(
'description' => 'Primary Key: Unique cache settings ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'page_callback' => array(
'description' => 'The name of the function that renders the page.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'page_arguments' => array(
'description' => 'The name of the content type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'lifetime' => array(
'description' => t('Number of seconds this page should be considered fresh. Used to set the expiration column.'),
'type' => 'int',
'not null' => TRUE,
'default' => -1,
),
'push' => array(
'description' => 'A flag to indicate whether page should be crawled so it is fresh in the cache.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => -1,
),
),
'indexes' => array(
'page_callback' => array('page_callback'),
'page_arguments' => array('page_arguments'),
),
'primary key' => array('csid'),
);
return $schema;
}
/**
* Update 6100 - Install Boost Database.
*/
function boost_update_6100() {
// Create tables.
return drupal_install_schema('boost');
}
/**
* Update 6101 - Copy old variable to new one.
*/
function boost_update_6101() {
Mike Carper
committed
// copy variable
return update_sql("UPDATE {variable} SET name = 'boost_enabled' WHERE name = 'boost'");
}
/**
* Update 6102 - Delete old boost permissions variable.
*/
function boost_update_6102() {
// del variable
variable_del('boost_permissions');
return array(array('success' => TRUE, 'query' => 'Old permissions variable deleted.'));