Last active
January 6, 2022 09:32
-
-
Save pounard/be581b7745d670faaf95594a8e6a0cbd to your computer and use it in GitHub Desktop.
Drupal panic script (complete)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
function panic_bootstrap_database($site_host = null, $incomming_host = null) { | |
$_SERVER['REMOTE_ADDR'] = $incomming_host ? $incomming_host : '127.0.0.1'; | |
$_SERVER['HTTP_HOST'] = $site_host ? $site_host : '127.0.0.1'; | |
$_SERVER['SCRIPT_NAME'] = '/index.php'; | |
define('DRUPAL_ROOT', __DIR__ . '/../html'); | |
chdir(DRUPAL_ROOT); | |
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; | |
require_once DRUPAL_ROOT . '/includes/database/database.inc'; | |
require_once DRUPAL_ROOT . '/includes/cache.inc'; | |
require_once DRUPAL_ROOT . '/includes/file.inc'; | |
require_once DRUPAL_ROOT . '/includes/module.inc'; | |
require_once DRUPAL_ROOT . '/includes/registry.inc'; | |
drupal_environment_initialize(); | |
drupal_settings_initialize(); | |
echo "working in ", conf_path(), "\n"; | |
// restore_error_handler(); | |
// restore_exception_handler(); | |
_drupal_bootstrap_database(); | |
} | |
function panic_clear() { | |
echo "forcefully clear some caches before anything\n"; | |
db_query("DELETE FROM {cache_bootstrap}"); | |
db_query("DELETE FROM {cache}"); | |
echo "drupal_static_reset()\n"; | |
drupal_static_reset(); | |
} | |
function panic_registry() { | |
echo "cache system enable attempt\n"; | |
if (!empty($conf['cache_backends'])) { | |
foreach ($conf['cache_backends'] as $include) { | |
echo "requiring ", $include, "\n"; | |
require_once DRUPAL_ROOT . '/' . $include; | |
} | |
} | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); | |
panic_clear(); | |
echo "system_rebuild_module_data()\n"; | |
require_once DRUPAL_ROOT . '/includes/common.inc'; | |
require_once DRUPAL_ROOT . '/modules/system/system.module'; | |
drupal_static_reset('system_rebuild_module_data'); | |
_system_rebuild_module_data(); | |
system_rebuild_module_data(); | |
echo "_registry_update()\n"; | |
db_query("DELETE FROM {registry_file}"); | |
db_query("DELETE FROM {registry}"); | |
_registry_update(); | |
echo "forcefully clear some caches\n"; | |
db_query("DELETE FROM {cache_bootstrap}"); | |
db_query("DELETE FROM {cache}"); | |
echo "all done\n"; | |
} | |
panic_bootstrap_database(isset($argv[1]) ? $argv[1] : null, isset($argv[2]) ? $argv[2] : null); | |
if (basename($argv[0]) === basename(__FILE__)) { | |
panic_registry(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment