Skip to content

Instantly share code, notes, and snippets.

@code-poel
code-poel / magento.json
Last active April 27, 2024 11:35
lnav Magento 1 Log Format
#! /usr/bin/env lnav -i
{
"magento_log" : {
"title" : "Magento Log Format",
"description" : "Log format used in Magento 1.",
"url" : "https://gist.github.com/chrisvanderpoel/e19dcab8ce69bc9806a3",
"regex" : {
"basic" : {
"pattern" : "^(?<timestamp>[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}\\T[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}\\+[0-9]{2}\\:[0-9]{2})\\s(?<level>\\w+)\\s(?<component>\\(\\w+\\))\\:\\s(?<body>.*)$"
}
@code-poel
code-poel / laravel_table_schema.php
Last active November 13, 2023 13:29
Get schema metadata on Laravel tables or columns...
<?php
// https://stackoverflow.com/questions/18562684/how-to-get-database-field-type-in-laravel/18563159#18563159
/* @var $schema \Doctrine\DBAL\Schema\AbstractSchemaManager */
$schema = DB::getDoctrineSchemaManager();
$columns = $schema->listTableColumns('cities');
dd($columns);
/*
@code-poel
code-poel / Veep_Patches_Model_PageCache_Observer_Index.php
Created July 14, 2016 14:21
Fixes a Magento Enterprise performance bug related to the enterprise_index_refresh cron and Enterprise PageCache.
<?php
/**
* This core over-ride is the result of a BUG in the Enterprise method of
* clearing it's PageCache. During the Mview reindexing process, a changelog
* of IDs is determined. This array contains entity IDs that have been updated
* since the last reindex and contains many duplicates. When passed to
* the PageCache methods to clear the cache, this array of IDs is not de-duped
* which can result in hundreds of thousands of needless queries when bulk
* updates are made.
@code-poel
code-poel / AttributeUpdate.php
Created March 16, 2016 21:27
How to update attributes in bulk.
<?php
// http://magento.stackexchange.com/questions/43917/fastest-way-to-update-an-attribute-in-all-products
$product->setData('something', true);
$product->getResource()->saveAttribute($product, 'something');
// OR
\Mage_Catalog_Model_Resource_Product_Action::updateAttributes
@code-poel
code-poel / Bypass.php
Created March 4, 2016 15:38
Bypass the Magento Flat Catalog Settings
<?php
// Notice this is NOT SAVING the setting...
Mage::app()->getStore()->setConfig(Mage_Catalog_Helper_Product_Flat::XML_PATH_USE_PRODUCT_FLAT, '0');
// Build your collection here...
@code-poel
code-poel / Mview.php
Created January 22, 2016 16:58
Check if an Mview index is up-to-date
<?php
// Check if an Mview index is up-to-date
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sub = $connection->select()->from(['cl' => $table], ['version_id'])->order('version_id DESC')->limit(1);
$select = $connection->select()
->from(['m' => 'enterprise_mview_metadata'], ['version_id', 'latest_id' => $sub, 'status'])
->where('changelog_name = ?', $table)
->limit(1);
$status = $connection->fetchRow($select);
@code-poel
code-poel / FindTables.sql
Created August 7, 2013 20:25
Find tables with columns.
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ( 'column' ) AND TABLE_SCHEMA='database_name';
@code-poel
code-poel / Blocks.php
Last active December 20, 2015 12:29
Nested SPL objects with recursion.
<?php
class Layout extends \ArrayIterator
{
}
class Block extends \ArrayIterator
{
protected $_alias;
@code-poel
code-poel / OuterIteratorMethods.php
Created August 1, 2013 12:08
Reusable block for Spl work.
<?php
public function getInnerIterator()
{
return $this->_children;
}
public function current()
{
return $this->getInnerIterator()->current();
}
@code-poel
code-poel / OuterIteratorMethods.php
Created August 1, 2013 12:08
Reusable block for Spl work.
<?php
public function getInnerIterator()
{
return $this->_children;
}
public function current()
{
return $this->getInnerIterator()->current();
}