Skip to content

Instantly share code, notes, and snippets.

View froboy's full-sized avatar

Avi Schwab froboy

View GitHub Profile
@froboy
froboy / upwd.sh
Created September 9, 2022 18:48
Bash script to bulk reset Drupal user passwords using drush
#!/usr/bin/env bash
set -e
set -x
# Space separated list of usernames
users=(user1 user2 user3@example.com)
for user in ${users[@]}; do
password=$(echo $RANDOM | md5sum | head -c 20);
# use fin, ddev or whatever your tool's prefix to drush and set an alias if necessary
@froboy
froboy / tests.md
Last active September 26, 2022 15:57
Testing DDEV performance

MacBook Pro (14-inch, 2021), macOS 12.3, M1Pro, 16GB, Docker Desktop 4.6.0

Started with D9 Quickstart

Almost all tests took longer on first run. I ran the tests 4 times and dropped the first.

ddev

Test script: time ( ddev drush si demo_umami -y && ddev drush cr && ddev drush uli )

@froboy
froboy / admin
Created February 1, 2022 21:57
Docksal command for resetting the user 1 username and password
#!/usr/bin/env bash
set -e
echo "Resetting uid=1 to 'admin' and setting password to admin. (Shhhhh!)"
fin drush sql-query "UPDATE users_field_data SET name='admin' WHERE uid=1"
fin drush upwd admin admin
echo "Your login is ready: https://${VIRTUAL_HOST}/user/login admin:admin."
@froboy
froboy / docksal-date-change.sh
Last active March 13, 2020 22:05
Changing dates on your docksal-powered VM to test date-dependent functionality.
###
# For docksal via VirtualBox:
###
# Check the date in the VM
fin vm ssh date
# Check the date in the CLI container
fin exec date
@froboy
froboy / custom_module.install
Created October 30, 2018 21:05
Switch from standard to config_installer with an existing db on Drupal 8, via https://www.drupal.org/project/drupal/issues/2677722
<?php
/**
* @file
* Install file for the Custom Module module.
*/
/**
* Ensure site is using 'config_installer' profile.
*/
function custom_module_update_8001(&$sandbox) {
@froboy
froboy / killOverlay
Created May 17, 2018 18:45
This is a bookmarklet to kill the overlay (which was standard, but horrible, practice in Drupal 7) with fire. See https://en.wikipedia.org/wiki/Bookmarklet#Installation
javascript:(function(){ hash=location.hash; pos=hash.indexOf('overlay=')+8; if(hash.length>0) location=location.protocol+'//'+location.hostname + ':' + location.port +'/'+location.hash.substring(pos); })()
@froboy
froboy / Drupal.org Case Study Template.md
Last active December 18, 2017 22:59
Drupal.org Case Study Template

A template for preparing your project to be entered as a Drupal.org case study, since it's useful to prepare these things before filling the form. Updated 12/18/2017. Synced to GitHub with StackEdit and manually posted to Google Docs

Project Name *

Metadata

Project logo

Used if featured on home page. Allowed file types: png gif jpg jpeg. Images must be larger than 200x200 pixels.

@froboy
froboy / sites.php
Created November 15, 2017 15:34
If you have a Drupal multisite with predictable hostnames, use this to keep your sites.php lean.
<?php
$sites['somecustomsitename.com'] = 'somecustomsite.com';
if (strpos($_SERVER['HTTP_HOST'], "-ra") != FALSE) // somesite-ra.com
{
$sites[$_SERVER['HTTP_HOST']] = // Cut out -ra and rewrite to somesite.com
str_replace("-ra", "", $_SERVER['HTTP_HOST']);
}
@froboy
froboy / nucular-option.sh
Last active May 19, 2022 19:15
Sometimes composer (in your Drupal 8 environment) gets grupmy... when that happens, it's time to go nucular.
######
# This script intentionally deletes a lot of things that could be important!!!!!
# Please be sure you have a backup before you go nucular!!!!!
#####
# Depending on where your web root is...
rm -rf vendor/ && rm -rf web/core && rm -rf web/modules/contrib/ && rm -rf composer.lock
# or
rm -rf vendor/ && rm -rf docroot/core && rm -rf docroot/modules/contrib/ && rm -rf composer.lock
@froboy
froboy / vbo-snippet.php
Created April 19, 2017 20:08
Drupal (7) VBO snippet - Turn on pathauto & Remove redirects
// This script can be run via Views Bulk Operations in the "Execute arbitrary PHP code" op
// This is, obviously, at your own risk. I'd take a db backup first.
// Force "Generate alias automatically" to be TRUE, then save the node.
$entity->path['pathauto'] = TRUE;
node_save($entity);
// Remove any stray redirects so that there's one true URL
$deleted = db_delete('redirect')
->condition('redirect', 'node/' . $entity->nid)
->execute();