Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@erikhansen
erikhansen / README.md
Last active February 28, 2023 13:59
Patch Magento 2 extension that must be installed in app/code

See also this alternative approach: https://gist.github.com/cmtickle/8900629447429126ffd7ff84e56ec780#to-patch-code-in-appcode

If you need to patch an M2 extension that isn't available to be installed via Composer, and you're concerned about losing edits directly to files in app/code/<Vendor> directory, you can install and then patch the extension locally using these steps:

  1. Copy the extension into an arbitrary folder location like app/code/packages/VendorName/ModuleName (this assumes this module has a composer.json file with the package name of vendorname/module-modulename)

  2. Run this command to add your custom package location to the composer repositories list:

    composer config repositories.vendorname/module-modulename path app/packages/VendorName/ModuleName
    
  3. Require the extension:

@erikhansen
erikhansen / flush_apcu_cache.rake
Created December 13, 2019 00:04
Rake file to cache apcu cache upon each deployment. Used in conjunction with https://github.com/davidalger/capistrano-magento2#usage
# Clear APCU (unsure if this is necessary, but playing it on the safe side)
after "deploy:published", "cachetool:apcu:clear" do
on release_roles :all do
within release_path do
execute :cachetool, 'apcu:cache:info'
execute :cachetool, 'apcu:cache:clear'
end
end
end
@erikhansen
erikhansen / issue.md
Last active March 26, 2024 14:53
Amasty M2 Full Page Cache Warmer Issue - Submitted this issue to Amasty on 2019-12-11

I have a client using this extension, and we recently discovered a big performance issue.

Description: The query generated by the \Amasty\Fpc\Model\ResourceModel\Activity::matchUrl method runs a query on a table that is missing an index.

Here is a screenshot showing the slow query:

Slow query in New Relic

Once the client added a MySQL index for the table, the slow query went away:

@erikhansen
erikhansen / _README.md
Last active April 29, 2021 08:22
Patch for `INSERT INTO search_tmp_` search issue: https://github.com/magento/magento2/issues/15545
@erikhansen
erikhansen / _readme.md
Last active April 17, 2023 11:42
Crawl Magento 1 / Magento 2 site for pricing

Overview

This basic script crawls a Magento 1 or Magento 2 website and logs the prices, SKUs, and product urls to a CSV file. This script was put togther for a company that had consent from the website(s) being scraped. Please use responsibility.

This script uses https://scrapy.org/

This script was tested on macOS Mojave, but it should run on any *NIX system.

You can tweak the body.css code to match the specific CSS selectors on the site you're crawling. See this documentation. When you're testing this script, refer to the command above the def parse_item line to learn how to run the code for only a single product.

@erikhansen
erikhansen / README.md
Last active October 17, 2019 22:55
Kraken Ink Template Readme

Kraken ExtensionName Extension

Description

Give a brief description of the extension here.

Usage Instructions

  • List any usage and deployment instructions
  • Consider including any preference overrides that may conflict with other extension

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@erikhansen
erikhansen / createUsefulAssetManifest.js
Last active June 25, 2019 14:44 — forked from mdecorte/createUsefulAssetManifest.js
Script to create a useful asset-manifest file for CRA-3 that only contains paths to assets needed on page load
const fs = require('fs');
const path = require('path');
const assetManifestPath = path.join(__dirname, 'build/asset-manifest.json');
let assetManifest = fs.readFileSync(assetManifestPath);
assetManifest = JSON.parse(assetManifest)['files'];
const indexFilePath = path.join(__dirname, 'build/index.html');
const BUILD_PATH = path.join(__dirname, 'build/useful-asset-manifest.json');
// Filter paths that exists in the create-react-app generated `build/asset-manifest.json` and use the path from that file because that can contain the "homepage" prefix from package.json.
# Magento 2 Sandbox Snippet - You can copy and paste into any shell in a Magento root directory
# Extended: https://docs.classyllama.net/disciplines/engineering/magento/sandbox-file-m2
set +H # disable history expansion
PHP_CODE=$(cat <<'PHP_CODE'
<?php
header('Content-type: text/plain');
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
@erikhansen
erikhansen / capistrano_deployment.md
Created March 15, 2019 15:56
Capistrano Deployment From Start to Finish

Prerequisites

  • Have SSH access to the target server(s) using PKA (public key authentication)
  • Either your public key or a deploy key on the target server(s) has been added to the source repository as a deploy key
  • The system you are running deployments from has Ruby 2.2 or later installed (RHEL/CentOS users may reference this gist as a means of meeting this requirement)

Setting Up the Deployment Toolchain

  1. Install bundler (http://bundler.io/):