Drupal Dump

Drupal Snippets, Hacks and more....

490 posts since 2011

Run composer without "Discard changes" question

You want to keep composer quite and just do its job? Then either set that to your composer.json config with

composer config --global discard-changes true

Which will add that config to your config.json and everbody will have this setting or you can just make this one liner to keep it shut.

Checking all crontabs on server

To get all crontabs from users on your system write this one liner

for user in $(getent passwd | cut -f1 -d: ); do echo $user; crontab -u $user -l; done

to check other crons you need to see what is in for example 

ls -la /etc/cron.daily


How to login to drupal over postman or CLI (Authorization: Basic)

To login to drupal and POST/PATCH some endpoint over JSON:API you need to login first, this is simple over postman, just go to Authorization TAB, select Basic Auth and fill in your user/pass and this will be automatically added to your header. You could also make it manually adding header with calculated base64 username:password, which you can get with CLI and

JSON:API disable caching locally

To disable caching while testing your JSON:API endpoints you should put this into your settings.php

$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

but for this to work, you need to define this service null, which should be added as

Get list of all installed modules and their dependencies

You probably don't need this but for debugging purposes i checked system.install file and saw how dependencies are checked on drupal updates.
So to get full list of modules and its info run

$files = \Drupal::service('extension.list.module')->getList();

to get theme info go

How to find hook_update_N, current N value

To find it via drush, run this command 

drush php:eval "echo drupal_get_installed_schema_version('modul_name');"

also if you want to look it up with some DB admin tool, look under table `key_value`,  `system.schema` collection row, with a `name` of your module and you will get value of last run update.

Dumping and exporting DB with drush and piping to ZIP

If you want to import DB that is in ZIP format with one line

gunzip -c my_db.sql.gz | drush sqlc

to dump DB to ZIP file write this

drush sql-dump --gzip --result-file=my_db.sql

you will end up with my_db.sql.gz file.