Skip to content

Instantly share code, notes, and snippets.

View SamJUK's full-sized avatar

Sam James SamJUK

View GitHub Profile
@SamJUK
SamJUK / bookmarklet.js
Created October 29, 2023 09:17
Magento 2 Software Requirements Table Highlighter
javascript:(function() {const samjuk_css_table = 'samjuk-table';const samjuk_css_table_highlight = 'samjuk_css_table_highlight';document.head.insertAdjacentHTML("beforeend", ` <style> .${samjuk_css_table} th { cursor: pointer !important; } .${samjuk_css_table_highlight} { background: #fff0af !important; font-weight: bold !important; } </style>`);document.querySelectorAll('sp-tab[label="Commerce on-premises"], sp-tab[label="Commerce on Cloud"]').forEach(tab => { const panel = tab.parentElement.querySelector('#' + tab.getAttribute('aria-controls')); if (panel === null) { return false; } const table = panel.querySelector('table'); if (table === null) { return false; } table.classList.add(samjuk_css_table); const headers = table.querySelector('thead'); if (headers === null) { return false; } headers.addEventListener('click', (event) => { let version = event.target; Array.from(table.querySelectorAll(`.${samjuk_css_table_highlight}`)).forEach(highlight => { highlight.classList.remove(samjuk_css_table_highlight); })
@SamJUK
SamJUK / z_db_schema_diff.php
Last active June 9, 2023 18:58
Show DB Schema Difference
<?php
#
# Lists the differences between the currently installed Schema and that parsed from db_schema.xml
#
use Magento\Framework\App\Bootstrap, Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
require __DIR__ . '/app/bootstrap.php';
error_reporting(E_ALL & ~E_NOTICE);
<?php
/**
* Crontab: 0 *\/3 * * * /usr/bin/php /var/www/htdocs/z_missing_invoice_cron.php --commit | mail -s "MagentoStore: Stale Invoice Grid Refresh" email@domain.co.uk
**/
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
error_reporting(E_ALL & ~E_NOTICE);
.PHONY: assert_magento_owner deploy css critical cache developer production
.DEFAULT_GOAL := help
#
# Variables
#
EXECUTER=$(shell whoami)
MAGE_OWNER=$(shell stat -c '%U' bin/magento)
#
@SamJUK
SamJUK / nginx-config.py
Created January 31, 2022 23:55
Nginx Config Helper
#!/usr/bin/env python3
#
# This script creates one big nginx config, squashing any includes into a single output.
#
import re
import glob
import nginxfmt
import argparse
@SamJUK
SamJUK / z_uncancel.php
Created December 8, 2021 14:55
Uncancel Magento Orders
<?php
use Magento\Sales\Model\Order;
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
@SamJUK
SamJUK / misc.sh
Last active November 30, 2021 16:12
Fetch and count all Magento reports (fatal error) exception messages from stack traces.
// Fetch and count all Magento reports (fatal error) exception messages from stack traces.
find /var/www/vhosts/prod.site.com/htdocs/var/report -type f -exec python -m json.tool {} \; | grep -i '"0":' | awk -F\" '{print $4}' | sort | uniq -c | sort -h
// Delete reports over 30 days old
find /var/www/vhosts/prod.site.com/htdocs/var/report -mindepth 1 -maxdepth 1 -type f -mtime +30 -delete
#!/usr/bin/env sh
#
# Monitor the disk space and send an email to $ADMIN,
# If the free space is less than the $ALERT threshold (default 90%).
#
# @Author: Sam James <sam@sdj.pw>
# @Requirements: Mail, Awk, Grep, df,
#
# ============= #
# CONFIGUARTION #
@SamJUK
SamJUK / z_reservations.php
Created November 10, 2021 16:11
[BBL] Magento 2. Remove any reservations assigned to a complete,closed,canceled order.
<?php
/**
* Handle removing any inventory reservation entries in Magento 2's Multi Source Inventory (MSI) system
* that belong to a order in final state (def: closed,canceled,complete).
*
* @maintainer: Sam James <sam@sdj.pw>
*/
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
@SamJUK
SamJUK / main.sql
Created June 21, 2021 15:34
Restore a cancelled Magento 2 order to processing.
-- ---------------------------------
-- Restore a Magento 2 order from
-- a canceled state to processing.
-- ---------------------------------
START TRANSACTION;
SET @IID = '000028692';
SET @OID = (SELECT entity_id FROM sales_order WHERE increment_id = @IID LIMIT 1);