Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost van Veen joostvanveen

View GitHub Profile
View remove-table-prefixes.sql
-- STEP 1: Set @database, @old_prefix and @new_prefix
-- STEP 2: Execute the query
-- STEP 3: Copy the string that was genereated by the query
-- STEP 4: Run the generated query to rename all tables
-- STEP 5: Use you Party Gun to make it rain!
SET SESSION group_concat_max_len = 999999999;
SET @database = "databasename";
SET @old_prefix = "ma2_";
SET @new_prefix = "";
@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 / rsync.sh
Created Dec 13, 2017
Crude bash script to Rsync source folder to destination folder, only certain folders and files
View rsync.sh
#!/usr/bin/env bash
# Magento 2 Deployment Script
# Author: Joost van Veen
usage="$(basename "$0") [-h] source-directory destination-directory folders-to-sync files-to-sync
Rsync folders and files from one folder to another
where:
-h show this help text
@joostvanveen
joostvanveen / magento_2_unrequire_firstname_lastname_etc.sql
Created Nov 3, 2017
Set firstname, lastname, email, telephone as unrequired for Magento 2
View magento_2_unrequire_firstname_lastname_etc.sql
-- DEFAULT MAGENTO: REQUIRE FIRSTNAME, LASTNAME, EMAIL, TELEPHONE
UPDATE `ma2_eav_attribute` SET is_required = 1 WHERE attribute_code = 'firstname';
UPDATE `ma2_eav_attribute` SET is_required = 1 WHERE attribute_code = 'lastname';
UPDATE `ma2_eav_attribute` SET is_required = 1 WHERE attribute_code = 'email';
UPDATE `ma2_eav_attribute` SET is_required = 1 WHERE attribute_code = 'telephone';
-- DO NOT REQUIRE FIRSTNAME, LASTNAME, EMAIL, TELEPHONE
UPDATE `ma2_eav_attribute` SET is_required = 0 WHERE attribute_code = 'firstname';
UPDATE `ma2_eav_attribute` SET is_required = 0 WHERE attribute_code = 'lastname';
UPDATE `ma2_eav_attribute` SET is_required = 0 WHERE attribute_code = 'email';
@joostvanveen
joostvanveen / truncate_orders_from_magento_2.sql
Created Nov 3, 2017
Truncate all orders from Magento 2
View truncate_orders_from_magento_2.sql
SET FOREIGN_KEY_CHECKS = 0;
-- TRUNCATE ORDERS
TRUNCATE TABLE `PREFIX_gift_message`;
TRUNCATE TABLE `PREFIX_quote`;
TRUNCATE TABLE `PREFIX_quote_address`;
TRUNCATE TABLE `PREFIX_quote_address_item`;
TRUNCATE TABLE `PREFIX_quote_id_mask`;
TRUNCATE TABLE `PREFIX_quote_item`;
TRUNCATE TABLE `PREFIX_quote_item_option`;
@joostvanveen
joostvanveen / truncate_products_from_magento_2.sql
Created Nov 3, 2017
Truncate all products from Magento 2
View truncate_products_from_magento_2.sql
SET FOREIGN_KEY_CHECKS = 0;
-- truncate products
TRUNCATE TABLE `PREFIX_cataloginventory_stock_item`;
TRUNCATE TABLE `PREFIX_cataloginventory_stock_status`;
TRUNCATE TABLE `PREFIX_cataloginventory_stock_status_idx`;
TRUNCATE TABLE `PREFIX_cataloginventory_stock_status_tmp`;
TRUNCATE TABLE `PREFIX_catalog_category_product`;
TRUNCATE TABLE `PREFIX_catalog_category_product_index`;
TRUNCATE TABLE `PREFIX_catalog_category_product_index_tmp`;
@joostvanveen
joostvanveen / truncate_customers_magento_2.sql
Created Nov 3, 2017
Truncate all customers and their reviews from Magento 2
View truncate_customers_magento_2.sql
SET FOREIGN_KEY_CHECKS = 0;
-- TRUNCATE CUSTOMERS
TRUNCATE TABLE `PREFIX_customer_address_entity`;
TRUNCATE TABLE `PREFIX_customer_address_entity_datetime`;
TRUNCATE TABLE `PREFIX_customer_address_entity_decimal`;
TRUNCATE TABLE `PREFIX_customer_address_entity_int`;
TRUNCATE TABLE `PREFIX_customer_address_entity_text`;
TRUNCATE TABLE `PREFIX_customer_address_entity_varchar`;
TRUNCATE TABLE `PREFIX_customer_entity`;
@joostvanveen
joostvanveen / public.blacklist
Created Oct 19, 2017
Nginx configuration file for Hypernode to block unwanted bots
View public.blacklist
if ($http_user_agent ~ "PHPCrawl|bGenius|SemrushBot|Yandex|YandexBot|MegaIndex|spbot|BLEXBot|ltx71|Daum|SpotBot|DotBot|seoscanners|domaincrawler|CCBot|SeznamBot|SMTBot") {
return 403;
break;
}
@joostvanveen
joostvanveen / magento_2_delete_all_orders.sql
Created Sep 22, 2017
Delete all orders from Magento 2
View magento_2_delete_all_orders.sql
-- Delete all orders from Magento 2
SET FOREIGN_KEY_CHECKS=0;
# Clean order history
TRUNCATE TABLE PREFIX_sales_bestsellers_aggregated_daily;
TRUNCATE TABLE PREFIX_sales_bestsellers_aggregated_monthly;
TRUNCATE TABLE PREFIX_sales_bestsellers_aggregated_yearly;
# Clean order infos
@joostvanveen
joostvanveen / export_all_customers.sql
Created Sep 21, 2017
Export all customers from Magento 1.9.x - names & email addresses
View export_all_customers.sql
-- Export all customers from Magento - names & email addresses
select ce.entity_id, concat(cevf.value, ' ', cevl.value) fullname, ce.email
from customer_entity ce
inner join customer_entity_varchar cevf
on ce.entity_id = cevf.entity_id
inner join eav_attribute eaf
on eaf.attribute_id = cevf.attribute_id
inner join customer_entity_varchar cevl
on ce.entity_id = cevl.entity_id