Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@erikhansen
erikhansen / composer_private_repos.sh
Created November 7, 2018 17:47 — forked from mttjohnson/composer_private_repos.sh
Composer Notes and Private Repositories
# List the composer home directory
# Typically /Users/<user>/.composer or /home/<user>/.composer or C:\Users\<user>\AppData\Roaming\Composer
echo $COMPOSER_HOME
# List files in the composer home
ls -la $COMPOSER_HOME
# View auth.json in composer home used when no local ./auth.json exists in the directory executed from
cat $COMPOSER_HOME/auth.json
@erikhansen
erikhansen / mysql_size_info.sql
Created June 21, 2018 15:58 — forked from mttjohnson/mysql_size_info.sql
MySQL data usage queries
/* find the largest tables on the server */
SELECT CONCAT(table_schema, '.', table_name) 'db.table',
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
@erikhansen
erikhansen / command.sh
Created May 22, 2018 00:39
File count, grouped by hour modified
find . -printf '%TY-%Tm-%Td %TH\n' | sort | uniq -c
@erikhansen
erikhansen / 1_find_crons_that_ran_more_than_once.sql
Last active May 16, 2018 16:53
Magento 2 - Find CRON jobs that ran more than once at a given second
SET SESSION group_concat_max_len = 1000000;
SELECT job_code, count(job_code) AS how_many_times_did_job_run_more_than_once, SUM(count) AS total_number_of_times_job_ran, GROUP_CONCAT(executed_at_group) AS executed_at FROM (
SELECT cron_schedule.*, GROUP_CONCAT(cron_schedule.executed_at) AS executed_at_group, count(job_code) AS count FROM cron_schedule WHERE executed_at IS NOT NULL GROUP BY job_code, executed_at HAVING count(job_code) > 1 ORDER BY executed_at DESC
) AS duplicate_crons
GROUP BY job_code
ORDER BY count(job_code) DESC;
Index: Model/SalesRule/Calculator.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- Model/SalesRule/Calculator.php (date 1513354238000)
+++ Model/SalesRule/Calculator.php (date 1513354238000)
@@ -45,6 +45,17 @@
break;
@erikhansen
erikhansen / show-detailed-error-when-duplicate-url-key.patch
Created June 9, 2017 17:53
Patch to see what is causing the "URL key for specified store already exists" error when saving entities in Magento 2. This patch should only be temporarily applied and needs to be applied to the vendor/magento/module-url-rewrite directory.
From 3523dd79d949f93e31fc675b190f17baf66f36c3 Mon Sep 17 00:00:00 2001
From: Erik Hansen <[email protected]>
Date: Wed, 1 Feb 2017 13:20:02 -0600
Subject: [PATCH] Edit the 'URL key for specified store already exists' message
---
Model/Storage/AbstractStorage.php | 5 ++++-
Model/Storage/DbStorage.php | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
@erikhansen
erikhansen / generate_sanitize_queries.sql
Last active October 24, 2019 19:22
Sanitize customer emails from Magento database. UPDATE: Use this instead: https://github.com/elgentos/masquerade
/*
Run the following query to get a set of queries that will purge all tables of email addresses. The queries that are output from
this should be manually reviewed to remove queries for any unnecessary tables and can then be run manually or via a Magerun "db:query"
to include it as a part of a scripted cloning process.
IMPORTANT: Make sure to update the @db_name variable
What the resulting query will do:
-- Replace the emails in Magento with dummy emails (unless email is one of the whitelisted domains) in order to prevent emails erroneously being sent to customers.
-- Make all emails with @example.com and use and MD5 of the original domain of the email as the tag for the email. This is important in case we have two emails with the
-- same "local part" but different "domain part". For example, [email protected] would become [email protected]
@erikhansen
erikhansen / 1_product_queries.sql
Last active March 10, 2025 20:33
Magento 2 - Remove duplicate store view-specific product and category data
/*
* IMPORTANT: The queries below are written for Magento Enterprise. If you're going to run them on Magento Community, you need
* to replace all instances of ".row_id" with ".entity_id". See this for context: http://magento.stackexchange.com/questions/139740/magento-2-schema-changes-for-ee-catalog-staging
*
* When importing products in Magento 2, if you specify store view codes in the store_view_code column, product data will be set at
* both the global scope as well as the specific store view scope. This is not ideal because now you have duplicate
* data at two different scopes that shouldn't actually be duplicated. The scripts below clean up this data by finding
* data set at specific store view scopes and if it's an exact match to the data set at the global store view, then it
* deletes the data set at the specific store view scope.
*
@erikhansen
erikhansen / braintree_settlement.sh
Created November 29, 2016 23:29 — forked from mttjohnson/braintree_settlement.sh
Braintree manual transaction settlement
# Setup local directory with braintree example and libraries
git clone [email protected]:braintree/braintree_php_example.git
cd braintree_php_example
composer install
# Create and define configuration options
echo '
BT_ENVIRONMENT=sandbox
BT_MERCHANT_ID=xxxxxxxxxxxx
BT_PUBLIC_KEY=xxxxxxxxxxxx
@erikhansen
erikhansen / web56_env.php
Last active November 15, 2016 16:20
dev-web56 Gist - The purpose of this Gist is to provide a template Magento 2 env.php file to use within the davidalger/devenv environment. See usage instructions below: https://gist.github.com/erikhansen/cfa278a80a6684bb7aa8d79ebcbf2f63#gistcomment-1922462
<?php
return array (
'backend' =>
array (
'frontName' => 'backend',
),
'crypt' =>
array (
'key' => '<KEY>',
),