? boost_batch_export.patch Index: boost.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v retrieving revision 1.1.2.1.2.3.2.10 diff -u -p -r1.1.2.1.2.3.2.10 boost.admin.inc --- boost.admin.inc 25 Oct 2008 16:09:24 -0000 1.1.2.1.2.3.2.10 +++ boost.admin.inc 22 Nov 2008 21:22:01 -0000 @@ -29,6 +29,14 @@ function boost_admin_settings($form = ar '#description' => t('Static page caching is a mechanism that stores dynamically generated web pages as HTML files in a special cache directory located under the Drupal installation directory. By caching a web page in this manner, the web server can serve it out in the fastest possible manner, without invoking PHP or Drupal at all. While this does provide a significant performance and scalability boost, you should note that it could have negative usability side-effects unless your site is targeted at an audience consisting mostly of "anonymous" visitors.'), '#weight' => -10, ); + if (BOOST_ENABLED == 1) { + $form['boost_export_button'] = array( + '#type' => 'submit', + '#submit' => array('boost_export_submit'), + '#value' => t('Click this button to export all pages to HTML now'), + '#weight' => -9, + ); + } $form['boost_file_path'] = array( '#type' => 'textfield', '#title' => t('Cache file path'), @@ -161,3 +169,8 @@ function boost_admin_site_offline_submit } } } + +function boost_export_submit($form, &$form_state) { + module_load_include('inc', 'boost', 'boost.pages'); + boost_collect_pages(); +} Index: boost.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v retrieving revision 1.3.2.2.2.5.2.18 diff -u -p -r1.3.2.2.2.5.2.18 boost.module --- boost.module 25 Oct 2008 16:30:34 -0000 1.3.2.2.2.5.2.18 +++ boost.module 22 Nov 2008 21:22:01 -0000 @@ -33,6 +33,9 @@ define('BOOST_BANNER', var // This is needed since the $user object is already destructed in _boost_ob_handler(): define('BOOST_USER_ID', @$GLOBALS['user']->uid); +// Include boost.pages.inc for batch functions. +require_once('boost.pages.inc'); + ////////////////////////////////////////////////////////////////////////////// // Core API hooks Index: boost.pages.inc =================================================================== RCS file: boost.pages.inc diff -N boost.pages.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ boost.pages.inc 22 Nov 2008 21:22:01 -0000 @@ -0,0 +1,92 @@ +nid, '')); + } + + // Get all terms + if (module_exists('taxonomy')) { + $result = db_query("SELECT tid FROM {term_data}"); + while ($row = db_fetch_object($result)) { + $operations[] = array('boost_export_html', array('taxonomy/term/'. $row->tid, '')); + } + } + + // Invoke hook_boost_export() + foreach (module_implements('boost_export') as $module) { + if (($result = module_invoke($module, 'boost_export')) != NULL) { + $operations = array_merge($operations, $result); + } + } + + // TODO more support for modules (views, panels, ... ?) + + // Batch properties. + $batch = array( + 'title' => t('Exporting html'), + 'operations' => $operations, + 'finished' => 'boost_export_done', + ); + batch_set($batch); +} + +/** + * Batch callback function. + * @param $page + * The drupal page we are going to fetch. + * @param $path + * Override path we take from $page, ie for frontpage. + */ +function boost_export_html($page, $path, &$context) { + // Set initial variable. + if (!isset($context['results']['num_html'])) { + $context['results']['num_html'] = 0; + } + + if (boost_is_cacheable($page) == TRUE && boost_is_cached($page) == FALSE) { + // Fetch a page with drupal_http_request, this does an anonymous request. + $url = url($page, array('absolute' => TRUE)); + $data = drupal_http_request($url); + + // Write the file away if code is 200 and we have data. + if ($data->code == 200 && strlen($data->data) > 0) { + $path = (!empty($path)) ? $path : $page; + boost_cache_set($path, $data->data); + $context['results']['num_html']++; + } + } +} + +/** + * Batch finished callback. + */ +function boost_export_done($success, $results, $operations) { + if ($success) { + // Count the number of pages we processed. + $message = $results['num_html'] .' html files created.'; + } + else { + // An error occurred. + $error_operation = reset($operations); + $message = 'An error occurred while creating the html files'; + } + drupal_set_message($message); +}