Skip to content

Instantly share code, notes, and snippets.

@killpond
killpond / commands.md
Last active August 13, 2018 11:24
Useful Magento 2 commands when doing development

A list of useful Magento 2 commands to help with development

Maximise the session life time value

php bin/magento config:set admin/security/session_lifetime 31536000

Create admin account

#!/bin/bash
#
# summarize daily performance data
cd /var/log/sa
# ------------
# memory usage
# ------------
echo
<?php
$ch = curl_init('https://www.howsmyssl.com/a/check');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data);
echo $json->tls_version;
@killpond
killpond / create_patch.php
Created July 25, 2017 09:05
Create an upgrade patch (Including binary additions/deleations) for Magento
<?php
function display_usage() {
echo <<< EOF
Usage : create_patch.php [-f|--from] [-t|--to]
-f : From Magento version (e.g. ce_1.9.0.1)
-t : To Magento version (e.g. ee_1.14.1.0)
--from : alias of -f
--to : alias of -t
@killpond
killpond / log_parse.php
Created April 3, 2017 15:42
Parse Magento log files and return a combined count of each error.
<?php
// Parse error log file
echo '------------------------------- exception.log -------------------------------';
$lines = file('exception.log');
$error = '';
$errors = array();
$errors_count = array();
foreach ($lines as $line_num => $line) {
$line = trim($line);
sudo apt install intltool libtool network-manager-dev libnm-util-dev libnm-glib-dev libnm-glib-vpn-dev libnm-gtk-dev libnm-dev libnma-dev ppp-dev libdbus-glib-1-dev libsecret-1-dev libgtk-3-dev libglib2.0-dev xl2tpd strongswan
git clone https://github.com/nm-l2tp/network-manager-l2tp.git
cd network-manager-l2tp
autoreconf -fi
intltoolize
./configure --disable-static --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib/x86_64-linux-gnu --libexecdir=/usr/lib/NetworkManager --localstatedir=/var --with-pppd-plugin-dir=/usr/lib/pppd/2.4.7
make
@killpond
killpond / gist:bccc517344dee659ea99
Created June 5, 2015 13:45
Check magento session file usage
# Find all the session files older then 3 days then display the number of files.
find /path/to/your/website/root/var/session -name 'sess_*' -type f -mtime +3 | wc -l
# Same as above, but display them in "less", browse with PageUP / PageDown.
find /path/to/your/website/root/var/session -name 'sess_*' -type f -mtime +3 | less
# Delete all the files older then 3 days.
find /path/to/your/website/root/var/session -name 'sess_*' -type f -mtime +3 -exec rm {} \;
@killpond
killpond / table_size.sql
Created June 5, 2015 13:05
Find size of tables in a database
-- Replace "DATABASE" with the database you want information on
SELECT
table_name AS 'Tables',
round(((data_length + index_length) / 1024 / 1024),
2) 'Size in MB'
FROM
information_schema.TABLES
WHERE
table_schema = 'DATABASE'
@killpond
killpond / gist:9000853
Created February 14, 2014 13:21
Switch with continue may not do as expected when used in for()
<?php
for ($i = 0; $i < 10; $i++) {
switch($i) {
case 4 :
case 5 :
echo 'HIT PRE CONTINUE'.PHP_EOL;
if ($i == 5) {
continue; // Expected this to skip the for loop, skips to the break instead.
}
echo 'HIT POST CONTINUE'.PHP_EOL;
@killpond
killpond / TBT_Rewards_1_13_0_0_fix.patch
Created June 3, 2013 13:39
When upgrading Magento to 1.13.0.0 the TBT_Rewards caused me some issues since I was upgrading from an older version of the module. Latest version of the module that this patch is valid against http://www.sweettoothrewards.com/downloads/magento/tbtrewards-latest.tar.gz In version 1.1.1 of the module a "rules_hash" column is added to the "catalog…
diff -rupN TBT3/app/code/community/TBT/Rewards/Model/Observer/Catalog/Product/Flat/Update/Product.php TBT2/app/code/community/TBT/Rewards/Model/Observer/Catalog/Product/Flat/Update/Product.php
--- TBT3/app/code/community/TBT/Rewards/Model/Observer/Catalog/Product/Flat/Update/Product.php 2013-04-16 19:20:50.000000000 +0100
+++ TBT2/app/code/community/TBT/Rewards/Model/Observer/Catalog/Product/Flat/Update/Product.php 2013-06-03 13:30:13.783568896 +0100
@@ -97,11 +97,13 @@ class TBT_Rewards_Model_Observer_Catalog
$product = $event->getProduct();
}
- if ( $product ) {
+ if ( is_numeric($product) ) {
+ $target_product_id = $product;