Skip to content

Instantly share code, notes, and snippets.

View mglaman's full-sized avatar

Matt Glaman mglaman

View GitHub Profile
@mglaman
mglaman / wp_posts-migrate.sql
Last active November 27, 2025 13:05
Migrating WordPress websites, changing guid for posts so attachments and routes have proper URL.
UPDATE wp_posts SET guid =
REPLACE(
guid,
"localhost/example",
"example.com"
),
post_content =
REPLACE(
post_content,
"localhost/example",
@mglaman
mglaman / phpstan.neon
Last active December 3, 2024 14:23
PHPStan configuration for Drupal 7 – https://youtu.be/9HYwq5jq4Sk
parameters:
level: 0
excludePaths:
- '*.api.php'
- '*.database.php'
scanFiles:
- web/authorize.php
- web/cron.php
- web/index.php
- web/update.php
@mglaman
mglaman / drush-loop.php
Created July 7, 2019 02:28
ReactPHP Drupal Tasks
<?php declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
function run_command(string $command): void {
$loop = React\EventLoop\Factory::create();
$process = new React\ChildProcess\Process($command);
$process->start($loop);
$process->on('exit', function ($exitCode) use ($command) {
// Trigger alerts that the command finished.
@mglaman
mglaman / woocommerce-products.sql
Last active August 7, 2023 13:52
MySQL query for wooCommerce to export products.
SELECT product.ID as product_id, product.post_title as product_name, replace(product.post_content, '"', "'") as product_content, product_sku.meta_value as product_sku, product_price.meta_value as product_price, product_weight.meta_value as product_weight
FROM wp_posts as product
LEFT JOIN wp_postmeta as product_sku ON product.ID = product_sku.post_ID
LEFT JOIN wp_postmeta as product_price ON product.ID = product_price.post_ID
LEFT JOIN wp_postmeta as product_weight ON product.ID = product_weight.post_ID
WHERE (product.post_type = 'product' OR product.post_type = 'product_variation') AND product_sku.meta_key = '_sku' AND product_price.meta_key = '_price' AND product_weight.meta_key = '_weight'
ORDER BY product_id ASC
@mglaman
mglaman / TrimMiddleware.php
Created January 10, 2023 15:23
TrimMiddleware for Drupal
<?php
declare(strict_types=1);
namespace Drupal\mymodule\StackMiddleware;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@mglaman
mglaman / phpunit.xml
Last active June 15, 2023 13:38
My Drupal project phpunit.xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit bootstrap="web/core/tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
<?php
use PHPUnit\Framework\TestCase;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use PHPUnit\TextUI\XmlConfiguration\Loader;
use PHPUnit\TextUI\XmlConfiguration\PhpHandler;
if (!defined('STDOUT')) {
// php://stdout does not obey output buffering. Any output would break
// unserialization of child process results in the parent process.
@mglaman
mglaman / helm.yaml
Created January 4, 2023 21:35
ChaptGPT generated Helm chart
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.deployment.name }}
labels:
app: {{ .Values.deployment.name }}
spec:
replicas: {{ .Values.deployment.replicas }}
selector:
matchLabels:
@mglaman
mglaman / bootstrap.php
Created December 24, 2021 19:52
in memory bootstrapped Drupal
<?php declare(strict_types=1);
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
return;
}
$autoloader = require __DIR__ . '/vendor/autoload.php';
@mglaman
mglaman / foo
Created September 16, 2021 03:05
This post links my 3Box profile to my Github account! Web3 social profiles by 3Box.
✅ did:3:bafyreihndmp3jzb3gm7oqw2vcoqnsv3hmt5redjre24o55btt5a4pwg3ka ✅
Create your profile today to start building social connection and trust online at https://3Box.io/