Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost van Veen joostvanveen

View GitHub Profile
@joostvanveen
joostvanveen / delete_customers_and_orders_from_magento.sql
Last active Sep 16, 2021
Delete all customers and orders from Magento 1*
View delete_customers_and_orders_from_magento.sql
--
-- This query delelets all customers and orders from your
-- Magento 1.* install. Handy, if you have a bloated
-- Magento database and you need to do a bit
-- of cleaning up for use on a local machine.
--
-- Replace PREFIX_ with your current Magento table prefix.
--
-- USE AT OWN RISK. ALWAY BACKUP YOUR DATABASE FIRST.
--
@joostvanveen
joostvanveen / linux_find_size_modified_date_and_remove_files.sh
Last active Jul 4, 2021
Linux commands to find all files modified older than a certain date or time, remove, find largest files or folder in a human readable way.
View linux_find_size_modified_date_and_remove_files.sh
## NOTE: when finding file by time, use one of the following flags:
# ctime : the time a file was changed, in hours. On most systems this timestamp cannot be altered by any user, so it is fairly reliable
# atime : the time a file was last accessed, in hours. This is also set by the system.
# mtime : the modified time of a file, in hours. This can be set by any user. So if you are looking for mailcious files, never use this flag.
# cmin : same as mtime, but in minutes.
# amin : same as atime, but in minutes.
# mmin : same as mtime, but in minutes.
# Find all files in current directory changed more than 8 hours ago (480 minutes)
find $PWD -mindepth 1 -type f -cmin +480
@joostvanveen
joostvanveen / .htaccess
Last active Jul 2, 2021
.htaccess Security
View .htaccess
######################################################################
## Word to the wise ##
## It is best to keep your htaccess files as clean as possible ##
## and set as many specs in your Apache config as you can. ##
## Htaccess slows down Apache. ##
## Review the entire file before use, especially the TODO sections. ##
######################################################################
Options -MultiViews
Options +FollowSymLinks
@joostvanveen
joostvanveen / du.sh
Last active Jun 20, 2021
Get folder sizes on command line, including --max-depth, sorted by folder size desc
View du.sh
# Get available disk space
df -h
# Get the top 10 biggest folders in the current directory
du -h --max-depth=1 | sort -rh | head -10
# Get the top 10 biggest folders in the current directory and their first child directories
du -h --max-depth=2 | sort -rh | head -10
# Get sizes of all folders in the current directory
@joostvanveen
joostvanveen / search_for_malicious_php_code.sh
Created Oct 26, 2020
Search directory for PHP files containing malicious code
View search_for_malicious_php_code.sh
## eval() is used to executed shell commands through PHP
grep -ri "eval(" $PWD --include *.php
## exec() is used to executed shell commands through PHP
grep -ri "exec(" $PWD --include *.php
## Malicious code is often obfuscated through base64 encoding
grep -ri "base64" $PWD --include *.php
## Malicious code is often obfuscated through gzip
@joostvanveen
joostvanveen / .htaccess
Last active Apr 22, 2021
Force SSL in .htaccess
View .htaccess
# Force SSL, but only for a certain domain
# At the same time, redirect http non-www ad www to https://www
# Replace example\.com and example.com with your domain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
@joostvanveen
joostvanveen / Reindex catalogrule prices in Magento 2.sh
Created Nov 13, 2020
Reindex catalogrule prices in Magento 2
View Reindex catalogrule prices in Magento 2.sh
## Reindex catalogrule prices in Magento 2
## Navigate to Magento root, e.g.:
cd ~/magento2
## Reindex the catalogrule prices
php bin/magento indexer:reindex catalogrule_product
## For this indexer to correctely index the new productprices, the
## catalogrules need to be indexed first. This usually happens
@joostvanveen
joostvanveen / Magento 2 chcek for orders with more than one shipment or invoice.sql
Created Nov 13, 2020
Magento 2 chcek for orders with more than one shipment or invoice
View Magento 2 chcek for orders with more than one shipment or invoice.sql
-- Orders with more than one shipment
SELECT orders.increment_id AS ordernummer, orders.created_at, count(*) as `Aantal verzendingen` FROM sales_shipment as shipments
LEFT JOIN sales_order AS orders ON orders.entity_id = shipments.order_id
GROUP BY shipments.order_id
HAVING `Aantal verzendingen` > 1
ORDER BY orders.created_at;
-- Orders with more than 1 invoice
SELECT orders.increment_id AS ordernummer, orders.created_at, count(*) as `Aantal facturen` FROM sales_invoice as invoices
LEFT JOIN sales_order AS orders ON orders.entity_id = invoices.order_id
@joostvanveen
joostvanveen / check_prefixes_and_autoincrements_for_magento_2_orders.sql
Created Oct 13, 2020
Find incorrect prefixes for order and invoice settings in Magebto 2. Sometimes, after using the data migration tool, Magento uses the wrong prefixes. This usually becomes unnoticed at first and can quickly become a disaster, leading to duplicate order numbers. Magento uses tables to work out which prefixes to use on which store, and also to work…
View check_prefixes_and_autoincrements_for_magento_2_orders.sql
-- Get all stores where orders, invoices, etc use the wrong prefix
-- E.g. the '2' in order number '200002345'
SELECT store_id, prefix, entity_type, sequence_table FROM sales_sequence_meta
JOIN sales_sequence_profile ON sales_sequence_profile.meta_id = sales_sequence_meta.meta_id
WHERE prefix <> store_id
ORDER BY store_id;
-- Get all stores that use the wrong prefix autoincrement table for orders, invoices, etc.
-- E.g. the '2345' in order number '200002345'
@joostvanveen
joostvanveen / delete_files_continaing_a_string.sh
Last active Jul 27, 2020
Delete log files containing a certain string. Handy to clean up Magento reports after committing a fix.
View delete_files_continaing_a_string.sh
# Delete log files containing a certain string.
# Handy to clean up Magento reports after committing a fix.
find var/report/* -exec grep -q 'A non-numeric value encountered' '{}' \; -delete
# If you ant to chcek first:
find var/report/* -exec grep -q 'A non-numeric value encountered' '{}' \; -find