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() {
drupal_set_message(t('Boost successfully installed. Please review the available <a href="@config">configuration</a> <a href="@settings">settings</a>.', array('@config' => url('admin/settings/performance'), '@settings' => url('admin/settings/performance/boost'))));
Arto Bendiken
committed
// 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');
variable_set('boost_crawler_key', md5(mt_rand()));
// 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_directories = array();
$cache_directories[] = BOOST_FILE_PATH;
if (BOOST_GZIP) {
$cache_directories[] = BOOST_GZIP_FILE_PATH;
$htaccess = file_get_contents('.htaccess');
$crawler_response = drupal_http_request(BOOST_CRAWLER_SELF);
$crawler_response = $crawler_response->code;
foreach($cache_directories as $cache_directory) {
_boost_mkdir_p($cache_directory);
$root_file = file_put_contents($cache_directory . '/' . variable_get('boost_root_file', '.boost'), $cache_directory);
if (!is_dir($cache_directory)) {
Mike Carper
committed
$requirements['boost_default'] = array(
'title' => $t('Boost'),
'description' => $t('!cache_dir: does not exist.', array('!cache_dir' => $cache_directory)),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Cache path'),
);
}
Mike Carper
committed
if (!$root_file || !is_writable($cache_directory)) {
$requirements['boost_permissions'] = 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) )),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Can not write to file-system'),
Mike Carper
committed
if (BOOST_FILE_PATH != boost_cache_directory(NULL, FALSE)) {
$requirements['boost_dir_exists'] = array(
'title' => $t('Boost'),
'description' => $t('<a href="@url">Cache file path</a>: is not set to the default(!default). ', array('@url' => url('admin/settings/performance/boost#edit-boost-file-path'), '!default' => boost_cache_directory(NULL, FALSE))),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Cache path'),
);
}
Mike Carper
committed
if ($htaccess && count(explode("%{REQUEST_URI}$char%{QUERY_STRING}\.html", $htaccess)) < 3) {
$requirements['boost_htaccess'] = 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. Get rules: <a href="@url">Boost Apache .htaccess settings generation</a>.', array('@url' => url('admin/settings/performance/boost#edit-boost-verbose'))),
'severity' => REQUIREMENT_ERROR,
'value' => $t('.htaccess file'),
Mike Carper
committed
if (!boost_chk_module_versions()) {
$requirements['boost_other_modules'] = array(
'title' => $t('Boost'),
'description' => $t('You need to get a newer version of <a href="@url">poormanscron</a>, most likely the latest dev.', array('@url' => "http://drupal.org/project/poormanscron")),
'severity' => REQUIREMENT_ERROR,
'value' => $t('poormanscron is the wrong version'),
);
}
Mike Carper
committed
if (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) {
$requirements['boost_language'] = array(
'title' => $t('Boost'),
'description' => $t('Boost is not compatible with '.
'<a href="!url">language negotiation</a> set to "language '.
'fallback". An anonymous user with their browser set to a '.
"language other than the site's default language will navigate ".
"to a non-cached page. The page will be displayed in the user's ".
'browser language. Boost will cache the non-default-language '.
'page. ', array('!url' => url('admin/settings/language/configure'))),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Cannot use "language fallback" language negotiation'),
);
}
if (!variable_get('boost_crawler_key', FALSE)) {
$requirements['boost_crawler'] = array(
'title' => $t('Boost'),
'description' => $t('Please Run the database update, as the crawler key is not generated yet.'),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Boost Crawler Key Not Found.'),
);
}
elseif ($crawler_response != 200) {
$requirements['boost_crawler'] = array(
'title' => $t('Boost'),
'description' => $t('@number returned. Crawler URL (@url) is not available, please <a href="@link">report this issue</a>', array('@number' => $crawler_response, '@url' => BOOST_CRAWLER_SELF, '@link' => 'http://drupal.org/node/add/project-issue/boost')),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Boost crawler did not get a 200 response.'),
);
}
Mike Carper
committed
if (empty($requirements)) {
$requirements['boost'] = array(
'title' => $t('Boost'),
'severity' => REQUIREMENT_OK,
Mike Carper
committed
'value' => t('Configured correctly, should be working.'),
);
}
break;
return $requirements;
/**
* Check for bad versions of modules.
*/
function boost_chk_module_versions() {
// chk poormanscron
if (module_exists('poormanscron')) {
$info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE name LIKE 'poormanscron'")));
if ($info['version'] == '6.x-1.0') {
return FALSE;
}
else {
return TRUE;
}
}
else {
return TRUE;
}
}
/**
* 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 webroot.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'base_dir' => array(
'description' => 'Path of the cache root dir relative to Drupal webroot.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
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
226
227
228
229
230
231
'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' => ''
),
'page_id' => array(
'description' => 'The ID of the page.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'extension' => array(
'description' => 'File Extension/Mime content type of this page.',
'type' => 'varchar',
'length' => 8,
'not null' => TRUE,
'default' => '',
),
'timer' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Time in milliseconds that the page took to be generated.',
),
'timer_average' => array(
'type' => 'float',
'not null' => TRUE,
'default' => 0,
'description' => 'Average time in milliseconds that the page took to be generated.',
),
'url' => array(
'description' => 'URL of cached page',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'indexes' => array(
'expire' => array('expire'),
'push' => array('push'),
'base_dir' => array('base_dir'),
'page_id' => array('page_id'),
'timer' => array('timer'),
'timer_average' => array('timer_average'),
'page_callback' => array('page_callback'),
'page_arguments' => array('page_arguments'),
'extension' => array('extension'),
),
'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
),
'base_dir' => array(
'description' => 'Path of the cache root dir relative to Drupal webroot.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'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' => '0'
),
'page_id' => array(
'description' => 'The ID of the page.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'extension' => array(
'description' => 'File Extension/Mime content type of this page.',
'type' => 'varchar',
'length' => 8,
'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'),
'base_dir' => array('base_dir'),
'page_id' => array('page_id'),
'extension' => array('extension'),
),
'primary key' => array('csid'),
);
$schema['boost_crawler'] = array(
'description' => t('Boost crawler - temp table'),
'fields' => array(
'id' => array(
'description' => 'Primary Key: Unique ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'url' => array(
'description' => 'URL of page',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
'unique keys' => array(
'url' => array('url'),
),
);
return $schema;
}
/**
* Update 6100 - Install Boost Database.
*/
function boost_update_6100() {
// Create tables.
$schema['boost_cache'] = array(
'description' => t('List of the cached page'),
'fields' => array(
'filename' => array(
'description' => 'Path of the cached file relative to Drupal webroot.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'url' => array(
'description' => 'URL of cached page',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
'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'),
);
$ret = array();
db_create_table($ret, 'boost_cache', $schema['boost_cache']);
db_create_table($ret, 'boost_cache_settings', $schema['boost_cache_settings']);
return $ret;
}
/**
* Update 6101 - Copy old variable to new one.
*/
function boost_update_6101() {
Mike Carper
committed
// copy variable
return array(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.'));
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
/**
* Update 6103 - Add new columns to tables
*/
function boost_update_6103() {
$ret = array();
// Add in base_dir column
db_add_field($ret, 'boost_cache', 'base_dir', array(
'description' => 'Path of the cache root dir relative to Drupal webroot.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, 'boost_cache_settings', 'base_dir', array(
'description' => 'Path of the cache root dir relative to Drupal webroot.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
));
db_add_index($ret, 'boost_cache', 'base_dir', array('base_dir'));
db_add_index($ret, 'boost_cache_settings', 'base_dir', array('base_dir'));
// Add in page_id column
db_add_field($ret, 'boost_cache', 'page_id', array(
'description' => 'The ID of the page.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_add_field($ret, 'boost_cache_settings', 'page_id', array(
'description' => 'The ID of the page.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_add_index($ret, 'boost_cache', 'page_id', array('page_id'));
db_add_index($ret, 'boost_cache_settings', 'page_id', array('page_id'));
// Add in timer column
db_add_field($ret, 'boost_cache', 'timer', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Time in milliseconds that the page took to be generated.',
));
db_add_index($ret, 'boost_cache', 'timer', array('timer'));
// Add in timer_average column
db_add_field($ret, 'boost_cache', 'timer_average', array(
'type' => 'float',
'not null' => TRUE,
'default' => 0,
'description' => 'Average time in milliseconds that the page took to be generated.',
));
db_add_index($ret, 'boost_cache', 'timer_average', array('timer_average'));
// Add indexes
db_add_index($ret, 'boost_cache', 'page_callback', array('page_callback'));
db_add_index($ret, 'boost_cache', 'page_arguments', array('page_arguments'));
// Set Defaults
db_field_set_default($ret, 'boost_cache_settings', 'page_arguments', '0');
return $ret;
}
/**
* Update 6104 - Add new column to tables
* Add in mime_type column
*/
function boost_update_6104() {
$ret = array();
db_add_field($ret, 'boost_cache', 'extension', array(
'description' => 'File Extension/Mime content type of this page.',
'type' => 'varchar',
'length' => 8,
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, 'boost_cache_settings', 'extension', array(
'description' => 'File Extension/Mime content type of this page.',
'type' => 'varchar',
'length' => 8,
'not null' => TRUE,
'default' => '',
));
db_add_index($ret, 'boost_cache', 'extension', array('extension'));
db_add_index($ret, 'boost_cache_settings', 'extension', array('extension'));
return $ret;
}
/**
* Update 6105 - Add new column to boost_cache table
* Add in url column
*/
function boost_update_6105() {
$ret = array();
db_add_field($ret, 'boost_cache', 'url', array(
'description' => 'URL of cached page',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
return $ret;
}
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/**
* Update 6106 - Add boost_crawler table to DB
*/
function boost_update_6106() {
$schema['boost_crawler'] = array(
'description' => t('Boost crawler - temp table'),
'fields' => array(
'id' => array(
'description' => 'Primary Key: Unique ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'url' => array(
'description' => 'URL of page',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
'unique keys' => array(
'url' => array('url'),
),
);
$ret = array();
db_create_table($ret, 'boost_crawler', $schema['boost_crawler']);
return $ret;
}
/**
* Update 6107 - Flush core caches
*/
function boost_update_6107() {
// Flush caches, needed since some functions got renamed.
drupal_flush_all_caches();
return array(array('success' => TRUE, 'query' => 'Core Caches Flushed.'));
}
/**
* Update 6108 - Create crawler key
*/
function boost_update_6108() {
variable_set('boost_crawler_key', md5(mt_rand()));
return array(array('success' => TRUE, 'query' => 'Crawler key generated.'));