Skip to content

Instantly share code, notes, and snippets.

View peterjaap's full-sized avatar

Peter Jaap Blaakmeer peterjaap

  • elgentos ecommerce solutions / Blaakmeer Webdevelopment
  • Groningen, the Netherlands
View GitHub Profile
@peterjaap
peterjaap / magento-local-env-settings.sh
Last active July 1, 2020 11:55
Magento local env settings
# Magento
php bin/magento config:set dev/css/minify_files 0 --lock-env
php bin/magento config:set dev/css/merge_css_files 0 --lock-env
php bin/magento config:set dev/js/merge_files 0 --lock-env
php bin/magento config:set dev/js/enable_js_bundling 0 --lock-env
php bin/magento config:set dev/js/minify_files 0 --lock-env
php bin/magento config:set dev/template/minify_html 0 --lock-env
php bin/magento config:set dev/static/sign 0 --lock-env
php bin/magento config:set sales_email/general/async_sending 0 --lock-env
php bin/magento config:set payment/checkmo/active 1 --lock-env
@peterjaap
peterjaap / varnishlog-examples.sh
Created June 24, 2020 09:40 — forked from cupracer/varnishlog-examples.sh
varnishlog examples (version 4.x)
# filter by request host header
varnishlog -q 'ReqHeader ~ "Host: example.com"'
# filter by request url
varnishlog -q 'ReqURL ~ "^/some/path/"'
# filter by client ip (behind reverse proxy)
varnishlog -q 'ReqHeader ~ "X-Real-IP: .*123.123.123.123"'
# filter by request host header and show request url and referrer header
location /media/customer/ { deny all; }
location /media/import/ { deny all; }
location /magento_version { deny all; }
location /static {
expires max;
# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version {
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
location ~ ^/google(.*).html {
alias /data/web/google-verification-files/google$1.html;
}
@peterjaap
peterjaap / checkTables.php
Last active November 9, 2022 07:46
Quick & dirty script to check for existence of Magento (2) table names in codebase
<?php
$tables = shell_exec('magerun2 db:query "SHOW TABLES"');
$tables = array_filter(explode(PHP_EOL, $tables), function ($table) {
if (empty($table)) return false;
if (substr($table, -3) === '_cl') return false;
if (substr($table, -8) === '_replica') return false;
if (stripos($table, '_flat_') !== false) return false;
if (stripos($table, '_fulltext_') !== false) return false;
if (stripos($table, 'sequence_') !== false) return false;
return true;
@peterjaap
peterjaap / checkDutchWords.php
Created June 2, 2020 12:21
Quick & dirty PHP script to find hard-coded Dutch words in a PHP / PHTML codebase (such as Magento)
<?php
if (!file_exists('dutch.txt')) {
shell_exec('wget -O dutch.txt https://github.com/OpenTaal/opentaal-wordlist/blob/master/wordlist.txt?raw=true');
}
$dict = explode("\n", file_get_contents('dutch.txt'));
$blacklisted = ['echo', 'var', 'reviews', 'rating', 'all', 'item', 'int', 'details', 'helper', 'label', 'configurator', 'display', 'var', 'id', 'show', 'a', 'br', 'preview', 'as', 'index', 'content', 'import', 'h', 'am', 'the', 'filter', 'type', 'Google', 'source', 'file', 'x', 'y', 'field', 'html'];
$dict = array_diff($dict, $blacklisted);
@peterjaap
peterjaap / Optimize.php
Created May 1, 2020 12:39
PNG Image optimizer example console command - Virtual Magento Meetup 30-04-2020
<?php declare(strict_types=1);
namespace VirtualMeetup\ImageOptimization\Console\Command;
use Graze\ParallelProcess\Event\RunEvent;
use Graze\ParallelProcess\PriorityPool;
use Graze\ParallelProcess\RunInterface;
use Magento\Framework\Filesystem\DirectoryList;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
@peterjaap
peterjaap / Crawler.php
Last active February 3, 2022 21:23
Sitemap Crawler coded during live session at Virtual Magento Meetup 30-04-2020
<?php declare(strict_types=1);
namespace VirtualMeetup\SitemapCrawler\Console\Command;
use Graze\ParallelProcess\Event\RunEvent;
use Graze\ParallelProcess\PriorityPool;
use Graze\ParallelProcess\RunInterface;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\HTTP\Client\Curl;
@peterjaap
peterjaap / DB_CLEANUP_WITH_QUOTE_TABLE.php
Last active April 13, 2020 20:46
Updated Magento 2 cleanup script for sensitive data in wishlist_item_option, quote_item_option AND order_item_option (not in original script). Also added try/catch block for unserializable data. See for more info https://support.magento.com/hc/en-us/articles/360040209352 and https://magento.com/security/hot-fix-available-cve-2019-8118
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Bootstrap;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Query\Generator;
use Magento\Framework\DB\Select\QueryModifierFactory;
@peterjaap
peterjaap / generate-magento-2-php-client.sh
Last active December 5, 2019 22:04
Generate PHP client with Swagger for Magento 2 including private endpoints (make sure you have the Swagger modules installed & enabled)
#!/bin/bash
SHOP_URL=https://yourshop.url
ADMIN_USERNAME=yourusername
ADMIN_PASSWORD=yourpassword
BEARER=$(curl -XPOST -H 'Content-Type: application/json' ${SHOP_URL}/index.php/rest/V1/integration/admin/token -d '{ "username": "${ADMIN_USERNAME}", "password": "${ADMIN_PASSWORD}" }')
curl -XGET -H "Authorization: Bearer ${BEARER}" ${SHOP_URL}/rest/default/schema?services=all | tee swagger.json
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/swagger.json -l php -o /local/