Skip to content

Instantly share code, notes, and snippets.

View adamzero1's full-sized avatar

Adam adamzero1

View GitHub Profile
@adamzero1
adamzero1 / DisallowPrintRSniff.php
Created August 2, 2023 07:57
Custom code sniff to check second argument passed to print_r
<?php
namespace PHP_CodeSniffer\Standards\Mdoq\Sniffs\Functions;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
class DisallowPrintRSniff implements Sniff
{
public const METHOD_NAME = 'print_r';
@adamzero1
adamzero1 / README.md
Last active January 8, 2023 19:11
Get more descriptive error when DOM validation fails in Magento

Get a more debugable error message when DOM validation fails in Magento.

Original Error Message

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'arguments': This element is not expected.
Line: 1471
@adamzero1
adamzero1 / magento_cron_job_run_times.sql
Created August 9, 2022 12:25
Report on average,min and max run time (in seconds) of all completed jobs in Magento 2
select job_code,
avg(timestampdiff(second, executed_at, finished_at)) as average_run_time,
min(timestampdiff(second, executed_at, finished_at)) as min_run_time,
max(timestampdiff(second, executed_at, finished_at)) as max_run_time
from cron_schedule where executed_at is not null and finished_at is not null group by job_code order by max(timestampdiff(second, executed_at, finished_at)) desc;
@adamzero1
adamzero1 / analyse_magento_var_directory.php
Created May 12, 2022 11:00
Analyse Magento var directory
<?php
use Magento\Setup\Module\I18n\Parser\Parser;
if(!is_file('bin/magento')){
echo 'Unable to find "bin/magento", this needs to be ran from the root of the project.'.PHP_EOL;
return 1;
}
define('REPORT_WIDTH', 200);
@adamzero1
adamzero1 / README.md
Last active March 9, 2022 20:27
Magento MySQL Santized Backup

Run sanitized backup

curl https://gist.githubusercontent.com/adamzero1/90e577229cbfb5907822b50daa7baf37/raw/85aa792ea563418fb9da2dee1fba1fa7669e7bd1/backup.sh | bash
@adamzero1
adamzero1 / README.md
Last active February 23, 2022 10:26
Fix broken Magento2 install

Description

Sometimes when running composer install for Magento 2 depending on your current directory structure the Magento composer plugin does not extract/copy the files out of vendor. Which leaves you with a broken installation.

How to run

curl -s https://gist.githubusercontent.com/adamzero1/0eb6d3e14078676a3ba589d77ba67b3d/raw/6ed67290b6eca7211942d1363ab6115eefd590a6/fix | bash
@adamzero1
adamzero1 / show_store_label_for_attribute_option_by_option_code.sql
Last active January 10, 2022 08:46
Show store label for attribute option, by option_code
select ea.attribute_code,
ea.frontend_label,
oc.option_id,
oc.attribute_id,
oc.option_code,
eaov.value_id,
eaov.store_id,
eaov.value from option_code as oc
left join eav_attribute_option_value as eaov on oc.option_id = eaov.option_id
left join eav_attribute as ea on oc.attribute_id = ea.attribute_id
@adamzero1
adamzero1 / evaluate_redis_size.php
Last active September 15, 2021 15:23
Magento 2 Redis Key Sizes
<?php
require realpath(__DIR__) . '/app/bootstrap.php';
class RedisCustom extends Credis_Client {
private static function _prepare_command($args)
{
return sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array('self', '_map'), $args), CRLF), CRLF);
}
@adamzero1
adamzero1 / export_out_of_memory_issue.patch
Last active March 16, 2021 13:45
Export Out Of Memory
--- Model/Export/Product.php 2021-03-16 13:35:33.809000000 +0000
+++ Model/Export/Product.php 2021-03-16 13:36:09.819832268 +0000
@@ -949,8 +949,9 @@
$productIds = array_keys($rawData);
$stockItemRows = $this->prepareCatalogInventory($productIds);
+ $entityCollection = clone $this->_getEntityCollection();
$this->rowCustomizer->prepareData(
- $this->_prepareEntityCollection($this->_entityCollectionFactory->create()),
+ $entityCollection,
@adamzero1
adamzero1 / Magento 2 Environment Variable.md
Created February 12, 2021 11:19
A description of the environment variables for Magento 2

MAGE_RUN_TYPE

  • Possible Values: store,website (string)
  • Version Constraints: 2.* CE, 2.* EE The scope the current request should be running as

MAGE_RUN_CODE

  • Possible Values: (string)
  • Version Constraints: 2.* CE, 2.* EE Website/Store (depending on MAGE_RUN_TYPE) code for the current request You can use admin for admin.