Skip to content

Instantly share code, notes, and snippets.

@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 / 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>.*)$"
}
ini_set('error_reporting', E_ERROR);
register_shutdown_function("fatal_handler");
function fatal_handler() {
$error = error_get_last();
echo("<pre>");
print_r($error);
}
@code-poel
code-poel / composer.json
Last active September 12, 2015 05:50 — forked from spekkionu/composer.json
Standalone validation using laravel validation component
{
"name": "spakkionu/validate",
"description": "Validation Test",
"require": {
"illuminate/validation": "~4.2.9"
},
"license": "MIT",
"authors": [
{
"name": "Jonathan Bernardi",
@code-poel
code-poel / gist:ade9a020b977ae1813a6
Created September 9, 2015 18:40
Regular expression to validate an HTML ID.
^[a-zA-Z][\w:.-]*$
@code-poel
code-poel / json_decode.php
Created August 25, 2015 11:32
Guzzle's method for "validating" JSON
<?php
/**
* Wrapper for JSON decode that implements error detection with helpful error
* messages.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted into
* associative arrays.
* @param int $depth User specified recursion depth.
@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);
/*