Skip to content

Instantly share code, notes, and snippets.

View twfahey1's full-sized avatar

Tyler Fahey twfahey1

View GitHub Profile
@twfahey1
twfahey1 / watch-backups.sh
Last active April 23, 2020 21:17
Run a backup with terminus, and check on the progress, for long running backups on Pantheon
#!/bin/bash
# Run this as ./watch-backup <site>.<env>, for the site & env to use.
do_backup() {
terminus backup:create $1 > /dev/null 2>&1
}
get_latest_backup_url() {
str=$(terminus backup:info $1 --field=URL)
@twfahey1
twfahey1 / run.sh
Created February 12, 2020 22:04
Create a WP User with admin privileges (similar to drush uli)
wp user create tyler [email protected] --role=administrator
@twfahey1
twfahey1 / some_module.install
Created February 5, 2020 18:53
Install hook to update database with entity definitions - Drupal 8
<?php
/**
* Update 8001 - Create foobar entity.
*/
function aws_bucket_fs_update_8001() {
//check if the table exists first. If not, then create the entity.
if(!db_table_exists('foobar')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()
@twfahey1
twfahey1 / settings.php
Last active February 7, 2020 01:17
Override Pressflow settings for Drupal 7 on Pantheon, override temporary file path, database, add a prefix, and more.
<?php
/**
* On Pantheon, the way Pressflow settings are injected in Drupal 7, it becomes impossible to
* override the temp directory, as well as some other settings. The workaround demonstrated here
* should allow for overriding Pressflow settings on Pantheon.
*/
if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
// Pressflow will override whatever we set here unless we override Pressflow first.
@twfahey1
twfahey1 / wp-config.php
Created January 17, 2020 15:53
Enforce https only for certain URLs in Wordpress wp-config
$urls_that_should_be_http = [
'/zonedata/manifest.txt',
'/zonedata/tzone_npanxx.unl',
'/zonedata/new_tzones.full.unl',
'/zonedata/tzone_tollfree.unl',
'/zonedata/tzrules.unl',
'/hello-world/',
];
@twfahey1
twfahey1 / puppeteer-script.js
Created January 9, 2020 02:04
Dump contents of page in puppeteer - node JS
let bodyHTML = await page.evaluate(() => document.body.innerHTML);
console.log(bodyHTML);
@twfahey1
twfahey1 / README.md
Last active December 17, 2019 18:41
Check table size in mb
In this example using the bookstore database, 
we’re combining the DATA_LENGTH and INDEX_LENGTH as bytes, 
then dividing it by 1024 twice to convert into kilobytes and then megabytes.
@twfahey1
twfahey1 / terminus-multidev-delete-all.sh
Created November 18, 2019 22:54
Terminus multidev delete all
# This script removes all multidevs for a given environment.
# Pass the site as the first argument.
# E.g. ./terminus-multidev-delete-all.sh my-pantheon-site
SITE=$1
MULTIDEVS=$(terminus multidev:list $SITE --field=Name)
for ENV in $MULTIDEVS
do
@twfahey1
twfahey1 / function.php
Last active November 18, 2019 16:03
Wordpress - Manipulate headers programmatically in plugin / theme
function add_header_auth( $headers ) {
if ( ! is_admin() ) {
$headers['X-Frame-Options'] = 'SAMEORIGIN';
}
return $headers;
}
add_filter( 'wp_headers', 'add_header_auth' );
@twfahey1
twfahey1 / run-testbot.sh
Created October 11, 2019 00:40
Run a Drupal 8 PHPUnit test via TestBot method
php core/scripts/run-tests.sh PHPUnit --dburl mysql://root:[email protected]:3306/mysitedatabase --url https://mysite.local/ --module mymodule