Skip to content

Instantly share code, notes, and snippets.

Peter Jaap Blaakmeer peterjaap

View GitHub Profile
@peterjaap
peterjaap / magento-local-env-settings.sh
Last active Jul 1, 2020
Magento local env settings
View magento-local-env-settings.sh
# 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 Jun 24, 2020 — forked from cupracer/varnishlog-examples.sh
varnishlog examples (version 4.x)
View varnishlog-examples.sh
# 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
View public.static
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;
View server.googleverification
location ~ ^/google(.*).html {
alias /data/web/google-verification-files/google$1.html;
}
@peterjaap
peterjaap / checkTables.php
Last active Jun 4, 2020
Quick & dirty script to check for existence of Magento (2) table names in codebase
View checkTables.php
<?php
$dbHost = '';
$dbUser = '';
$dbName = '';
$tables = shell_exec('mysql -h ' . $dbHost . ' -u ' . $dbUser . ' -B ' . $dbName . ' -e "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;
@peterjaap
peterjaap / checkDutchWords.php
Created Jun 2, 2020
Quick & dirty PHP script to find hard-coded Dutch words in a PHP / PHTML codebase (such as Magento)
View checkDutchWords.php
<?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
PNG Image optimizer example console command - Virtual Magento Meetup 30-04-2020
View Optimize.php
<?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 May 4, 2020
Sitemap Crawler coded during live session at Virtual Magento Meetup 30-04-2020
View Crawler.php
<?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 Apr 13, 2020
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
View DB_CLEANUP_WITH_QUOTE_TABLE.php
<?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 Dec 5, 2019
Generate PHP client with Swagger for Magento 2 including private endpoints (make sure you have the Swagger modules installed & enabled)
View generate-magento-2-php-client.sh
#!/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/
You can’t perform that action at this time.