Commit 52d3b493 authored by catch's avatar catch

Issue #2097189 by damiankloip, sun, Albert Volkman, chx: Add a rebuild script.

parent f2e66e87
...@@ -111,7 +111,8 @@ DirectoryIndex index.php index.html index.htm ...@@ -111,7 +111,8 @@ DirectoryIndex index.php index.html index.htm
# Redirect common PHP files to their new locations. # Redirect common PHP files to their new locations.
RewriteCond %{REQUEST_URI} ^(.*)?/(update.php) [OR] RewriteCond %{REQUEST_URI} ^(.*)?/(update.php) [OR]
RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
RewriteCond %{REQUEST_URI} !core RewriteCond %{REQUEST_URI} !core
RewriteRule ^ %1/core/%2 [L,QSA,R=301] RewriteRule ^ %1/core/%2 [L,QSA,R=301]
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
*/ */
use Drupal\Component\Utility\Variable; use Drupal\Component\Utility\Variable;
use Drupal\Component\PhpStorage\PhpStorageFactory;
use Drupal\Core\Cache\Cache;
/** /**
* Drupal-friendly var_export(). * Drupal-friendly var_export().
...@@ -23,3 +25,29 @@ ...@@ -23,3 +25,29 @@
function drupal_var_export($var, $prefix = '') { function drupal_var_export($var, $prefix = '') {
return Variable::export($var, $prefix); return Variable::export($var, $prefix);
} }
/**
* Rebuilds all caches even when Drupal itself does not work.
*
* Requires DRUPAL_BOOTSTRAP_CONFIGURATION.
*
* @see rebuild.php
*/
function drupal_rebuild() {
// drupal_bootstrap(DRUPAL_BOOTSTRAP_KERNEL) will build a new kernel. This
// comes before DRUPAL_BOOTSTRAP_PAGE_CACHE.
PhpStorageFactory::get('service_container')->deleteAll();
PhpStorageFactory::get('twig')->deleteAll();
// Disable the page cache.
drupal_page_is_cacheable(FALSE);
// Bootstrap up to where caches exist and clear them.
drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE);
foreach (Cache::getBins() as $bin) {
$bin->deleteAll();
}
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_flush_all_caches();
}
...@@ -518,6 +518,15 @@ function system_requirements($phase) { ...@@ -518,6 +518,15 @@ function system_requirements($phase) {
); );
} }
$requirements['update status']['title'] = t('Update notifications'); $requirements['update status']['title'] = t('Update notifications');
if (settings()->get('rebuild_access')) {
$requirements['rebuild access'] = array(
'title' => t('Rebuild access'),
'value' => t('Enabled'),
'severity' => REQUIREMENT_ERROR,
'description' => t('The rebuild_access setting is enabled in settings.php. It is recommended to have this setting disabled unless you are performing a rebuild.'),
);
}
} }
// Ensure that if upgrading from 7 to 8 we have no disabled modules. // Ensure that if upgrading from 7 to 8 we have no disabled modules.
......
<?php
/**
* @file
* Rebuilds all Drupal caches even when Drupal itself does not work.
*
* Needs a token query argument which can be calculated using the
* scripts/rebuild_token_calculator.sh script.
*
* @see drupal_rebuild()
*/
use Drupal\Component\Utility\Crypt;
// Change the directory to the Drupal root.
chdir('..');
require_once dirname(__DIR__) . '/core/includes/bootstrap.inc';
require_once dirname(__DIR__) . '/core/includes/utility.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (settings()->get('rebuild_access', FALSE) ||
(isset($_GET['token'], $_GET['timestamp']) &&
((REQUEST_TIME - $_GET['timestamp']) < 300) &&
($_GET['token'] === Crypt::hmacBase64($_GET['timestamp'], $GLOBALS['drupal_hash_salt']))
)) {
drupal_rebuild();
drupal_set_message('Cache rebuild complete.');
}
header('Location: ' . $GLOBALS['base_url']);
#!/usr/bin/env php
<?php
/**
* @file
* Command line token calculator for rebuild.php.
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once dirname(__DIR__) . '/includes/bootstrap.inc';
use Drupal\Component\Utility\Crypt;
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (!drupal_is_cli()) {
exit;
}
$timestamp = time();
$token = Crypt::hmacBase64($timestamp, $drupal_hash_salt);
print "timestamp=$timestamp&token=$token\n";
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
drupal_handle_request(); drupal_handle_request();
} }
catch (Exception $e) { catch (Exception $e) {
print 'If you have just changed code (for example deployed a new module or moved an existing one) read http://drupal.org/documentation/rebuild'; $message = 'If you have just changed code (for example deployed a new module or moved an existing one) read <a href="http://drupal.org/documentation/rebuild">http://drupal.org/documentation/rebuild</a>';
if (settings()->get('rebuild_access', FALSE)) {
$rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
$message .= " or run the <a href=\"$rebuild_path\">rebuild script</a>";
}
print $message;
throw $e; throw $e;
} }
...@@ -501,6 +501,16 @@ ...@@ -501,6 +501,16 @@
*/ */
# $settings['maintenance_theme'] = 'bartik'; # $settings['maintenance_theme'] = 'bartik';
/**
* Enable access to rebuild.php.
*
* This setting can be enabled to allow Drupal's php and database cached
* storage to be cleared via the rebuild.php page. Access to this page can also
* be gained by generating a query string from rebuild_token_calculator.sh and
* using these parameters in a request to rebuild.php.
*/
# $settings['rebuild_access'] = TRUE;
/** /**
* Base URL (optional). * Base URL (optional).
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment