This project is archived. Its data is
read-only
.
Changes
Page history
Update Drupal Debug Hints
authored
Dec 26, 2024
by
Tom Wiesing
Hide whitespace changes
Inline
Side-by-side
Drupal-Debug-Hints.md
View page @
e6aa1651
Because drupal frequently misbehaves, here is a list of useful snippets.
This isn't intended for end-users of the distillery, but just listed here so we don't have to keep searching for it.
# Export, Import and Edit/Delete Module Configs
The whole Drupal config can be exported with:
```
drush cex -y
```
This will export all config files to
`/web/sites/default/files/config_SOME_HASH/sync/`
.
Here you can edit/delete the configs that are causing problems.
After you're done you can import the config again with:
```
drush cim -y
```
# Enable Stack Traces
The DSOD usually only says
`The website encountered an unexpected error. `
When
`Reports > Recent Log Messages`
is inaccessible, you can enable full stack traces.
Run
`vim web/sites/default/settings.php`
and add:
```
php
$config
[
"system.logging"
][
"error_level"
]
=
"verbose"
;
```
Might have to ignore the readonly flag (with
`:w!`
).
# Clear APCu cahe to fix incorrect classloading
When classes are not found, even though they are definitely there.
Restart the system to clear the APCu cache, or disable APCu via:
`vim web/sites/default/settings.php`
and add:
```
php
$settings
[
'class_loader_auto_detect'
]
=
FALSE
;
```
Might have to ignore the readonly flag (with
`:w!`
).
# Manually deleting log messages
Sometimes the log page fails to load with a fatal error.
Delete the watchdog messages by hand:
```
drush watchdog:delete all
```
# Manually disabling a module
When doing manual migrations or upgrades, an error like the following can occur
```
(Currently using Missing or invalid modules The following modules are marked as installed in the core.extension
configuration, but they are missing:
```
To fix this, either re-install the module (using composer and friends) or run this code to disable it:
```
php
drush
eval
"function disable(
\$
modname) {
\$
module_data = \Drupal::config('core.extension')->get('module'); unset(
\$
module_data[
\$
modname]); \Drupal::configFactory()->getEditable('core.extension')->set('module',
\$
module_data)->save(); }; disable('name-of-module'); "
```
You might also have to delete some config files the module comes with if you want to reinstall it:
```
drush config-delete module_name.settings_name
```
# Remove Module Config
Sometimes
`update.php`
says:
```
Module my_already_removed_module has a schema in the key_value store, but is missing from your site.
Module update_test_0 has a schema in the key_value store, but is not installed.
```
As per
[
Drupal Doc
](
https://www.drupal.org/node/3137656
)
, to fix this without reinstalling, you can run:
```
drush php-eval "\Drupal::keyValue('system.schema')->delete('my_already_removed_module');"
drush php-eval "\Drupal::keyValue('system.schema')->delete('update_test_0');"
```
Alternatively, you can also install the module again, deactivate and uninstall it, and then remove the files.
# Fix Revision ID Field needs to be installed
```
php
drush
eval
"
\$
edum =
\\
Drupal::entityDefinitionUpdateManager();
\$
fs =
\\
Drupal::service('entity_field.manager')->getFieldStorageDefinitions('wisski_individual');
\$
edum->updateFieldableEntityType(
\\
Drupal::entityTypeManager()->getDefinition('wisski_individual'),
\$
fs);"
```
# Fix Field $FIELD needs to be uninstalled
```
php
drush
eval
"
\$
manager =
\\
Drupal::entityDefinitionUpdateManager();
\$
definition =
\$
manager->getFieldStorageDefinition('some_field', 'corresponding_bundle');
\$
manager->uninstallFieldStorageDefinition(
\$
definition);
```
# Factory SSH Forwarding
To portforward all services you can use the following ssh command:
```
ssh -L 3306:sql:3306 -L 7200:triplestore:7200 -L 8080:phpmyadmin:80 -p 2222 slug@wisski.data.fau.de
```
This forwards:
-
[
GraphDB on `localhost:7200`
](
http://localhost:7200
)
-
[
PhpMyAdmin on `localhost:8080`
](
http://localhost:8080/
)
You can also access raw sql, e.g.:
```
mysql --host=localhost --port=3306 --password --user=username
```
and load an sql file with
`source [filename]`
.
# Fix Behaim IDs when someone breaks them
```
DELETE { GRAPH <http://wwwdh.cs.fau.de/behaim/> { ?s ?p ?o } } WHERE {
GRAPH <http://wwwdh.cs.fau.de/behaim/> {
?s a <http://erlangen-crm.org/120111/E31_Document> .
?s ?p ?o
}
}
```
```
PREFIX owl: <http://www.w3.org/2002/07/owl#>
DELETE { GRAPH <http://wwwdh.cs.fau.de/behaim/> { ?s2 owl:sameAs ?s } } WHERE {
GRAPH <http://wwwdh.cs.fau.de/behaim/> {
?s a <http://erlangen-crm.org/120111/E31_Document> .
?s ?p ?o .
?s2 owl:sameAs ?s
}
}
```
```
PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT {
GRAPH <http://wwwdh.cs.fau.de/behaim/originatesFrom> {
?x owl:sameAs ?newid .
?newid owl:sameAs ?x
}
} WHERE {
GRAPH ?g {
# select old node ids
?x a <http://erlangen-crm.org/120111/E31_Document> .
?x <http://erlangen-crm.org/120111/P48_has_preferred_identifier> ?y .
?y a <http://erlangen-crm.org/120111/E42_Identifier> .
?y <http://erlangen-crm.org/120111/P3_has_note> ?id .
# create proper new URIS
BIND( uri(CONCAT("http://wisski.cs.fau.de/behaim/node/", str(?id))) as ?newid)
}
}
```
# Extract single database from sql backup
Source: https://stackoverflow.com/a/25975930
```
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' alldatabases.sql > output.sql
```
# Clearing all caches (including opcache)
```
drush cr
drush php:eval 'opcache_reset();'
Because drupal frequently misbehaves, here is a list of useful snippets.
This isn't intended for end-users of the distillery, but just listed here so we don't have to keep searching for it.
# Export, Import and Edit/Delete Module Configs
The whole Drupal config can be exported with:
```
drush cex -y
```
This will export all config files to
`/web/sites/default/files/config_SOME_HASH/sync/`
.
Here you can edit/delete the configs that are causing problems.
After you're done you can import the config again with:
```
drush cim -y
```
# Enable Stack Traces
The DSOD usually only says
`The website encountered an unexpected error. `
When
`Reports > Recent Log Messages`
is inaccessible, you can enable full stack traces.
Run
`vim web/sites/default/settings.php`
and add:
```
php
$config
[
"system.logging"
][
"error_level"
]
=
"verbose"
;
```
Might have to ignore the readonly flag (with
`:w!`
).
# Clear APCu cahe to fix incorrect classloading
When classes are not found, even though they are definitely there.
Restart the system to clear the APCu cache, or disable APCu via:
`vim web/sites/default/settings.php`
and add:
```
php
$settings
[
'class_loader_auto_detect'
]
=
FALSE
;
```
Might have to ignore the readonly flag (with
`:w!`
).
# Manually deleting log messages
Sometimes the log page fails to load with a fatal error.
Delete the watchdog messages by hand:
```
drush watchdog:delete all
```
# Manually disabling a module
When doing manual migrations or upgrades, an error like the following can occur
```
(Currently using Missing or invalid modules The following modules are marked as installed in the core.extension
configuration, but they are missing:
```
To fix this, either re-install the module (using composer and friends) or run this code to disable it:
```
php
drush
eval
"function disable(
\$
modname) {
\$
module_data = \Drupal::config('core.extension')->get('module'); unset(
\$
module_data[
\$
modname]); \Drupal::configFactory()->getEditable('core.extension')->set('module',
\$
module_data)->save(); }; disable('name-of-module'); "
```
You might also have to delete some config files the module comes with if you want to reinstall it:
```
drush config-delete module_name.settings_name
```
# Remove Module Config
Sometimes
`update.php`
says:
```
Module my_already_removed_module has a schema in the key_value store, but is missing from your site.
Module update_test_0 has a schema in the key_value store, but is not installed.
```
As per
[
Drupal Doc
](
https://www.drupal.org/node/3137656
)
, to fix this without reinstalling, you can run:
```
drush php-eval "\Drupal::keyValue('system.schema')->delete('my_already_removed_module');"
drush php-eval "\Drupal::keyValue('system.schema')->delete('update_test_0');"
```
Alternatively, you can also install the module again, deactivate and uninstall it, and then remove the files.
# Fix Mismatched entity and/or field definitions
1.
Install https://www.drupal.org/project/devel_entity_updates:
```
bash
composer require
'drupal/devel_entity_updates:^4.2'
```
NOTE: Version may have changed
2.
Enable it
```
drush install devel_entity_updates
```
3.
Run the entup command
```
drush entup
```
## Fix Revision ID Field needs to be installed
```
php
drush
eval
"
\$
edum =
\\
Drupal::entityDefinitionUpdateManager();
\$
fs =
\\
Drupal::service('entity_field.manager')->getFieldStorageDefinitions('wisski_individual');
\$
edum->updateFieldableEntityType(
\\
Drupal::entityTypeManager()->getDefinition('wisski_individual'),
\$
fs);"
```
# Fix Field $FIELD needs to be uninstalled
```
php
drush
eval
"
\$
manager =
\\
Drupal::entityDefinitionUpdateManager();
\$
definition =
\$
manager->getFieldStorageDefinition('some_field', 'corresponding_bundle');
\$
manager->uninstallFieldStorageDefinition(
\$
definition);
```
# Factory SSH Forwarding
To portforward all services you can use the following ssh command:
```
ssh -L 3306:sql:3306 -L 7200:triplestore:7200 -L 8080:phpmyadmin:80 -p 2222 slug@wisski.data.fau.de
```
This forwards:
-
[
GraphDB on `localhost:7200`
](
http://localhost:7200
)
-
[
PhpMyAdmin on `localhost:8080`
](
http://localhost:8080/
)
You can also access raw sql, e.g.:
```
mysql --host=localhost --port=3306 --password --user=username
```
and load an sql file with
`source [filename]`
.
# Fix Behaim IDs when someone breaks them
```
DELETE { GRAPH <http://wwwdh.cs.fau.de/behaim/> { ?s ?p ?o } } WHERE {
GRAPH <http://wwwdh.cs.fau.de/behaim/> {
?s a <http://erlangen-crm.org/120111/E31_Document> .
?s ?p ?o
}
}
```
```
PREFIX owl: <http://www.w3.org/2002/07/owl#>
DELETE { GRAPH <http://wwwdh.cs.fau.de/behaim/> { ?s2 owl:sameAs ?s } } WHERE {
GRAPH <http://wwwdh.cs.fau.de/behaim/> {
?s a <http://erlangen-crm.org/120111/E31_Document> .
?s ?p ?o .
?s2 owl:sameAs ?s
}
}
```
```
PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT {
GRAPH <http://wwwdh.cs.fau.de/behaim/originatesFrom> {
?x owl:sameAs ?newid .
?newid owl:sameAs ?x
}
} WHERE {
GRAPH ?g {
# select old node ids
?x a <http://erlangen-crm.org/120111/E31_Document> .
?x <http://erlangen-crm.org/120111/P48_has_preferred_identifier> ?y .
?y a <http://erlangen-crm.org/120111/E42_Identifier> .
?y <http://erlangen-crm.org/120111/P3_has_note> ?id .
# create proper new URIS
BIND( uri(CONCAT("http://wisski.cs.fau.de/behaim/node/", str(?id))) as ?newid)
}
}
```
# Extract single database from sql backup
Source: https://stackoverflow.com/a/25975930
```
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' alldatabases.sql > output.sql
```
# Clearing all caches (including opcache)
```
drush cr
drush php:eval 'opcache_reset();'
```
\ No newline at end of file