Skip to content

Instantly share code, notes, and snippets.

View drobinson's full-sized avatar

David Robinson drobinson

View GitHub Profile
#!/bin/bash
if [ ! -d $1/var ] ; then echo "Invalid directory $1/var"; exit 1; fi
SHMFOLDERS=( "full_page_cache" "cache" "session" )
for i in "${SHMFOLDERS[@]}" ; do
if [ ! -d $1/var/$i ] ; then echo "Invalid directory $1/var/$i"; exit 1; fi
if [ -d /dev/shm/$i ] ; then echo "Directory /dev/shm/$i already exists"; exit 1; fi
mv $1/var/$i /dev/shm/$i
ln -s /dev/shm/$i $1/var/$i
@drobinson
drobinson / diff_shortstat.sh
Last active August 29, 2015 14:22
Condensed Line Change Report Between Branches (good for looking at cleanup branch stats)
git diff --shortstat <master_branch> <cleanup_branch>
# 93 files changed, 838 insertions(+), 7592 deletions(-)
# Combine this with rev-list to limit reporting to a time period
git diff --shortstat $(git rev-list -n1 --before="1 day ago" <cleanup_branch>)
# 7 files changed, 7 insertions(+), 368 deletions(-)
@drobinson
drobinson / diff-filter.md
Created July 13, 2015 21:20
Filter git diff by change type

--diff-filter=[ACDMRTUXB*]

Select only files that are

  • A Added
  • C Copied
  • D Deleted
  • M Modified
  • R Renamed
  • T have their type (mode) changed
--- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php
+++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php
@@ -114,7 +114,7 @@ class Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection extends Mage_Co
*/
public function setIdFilter($optionId)
{
- return $this->addFieldToFilter('option_id', array('in' => $optionId));
+ return $this->addFieldToFilter('main_table.option_id', array('in' => $optionId));
}
@drobinson
drobinson / install_xdebug_2-2-1.sh
Last active December 14, 2015 19:29
Install xdebug 2.2.1 (which allows for breakpoints to be set in symlinked files)
wget http://xdebug.org/files/xdebug-2.2.1.tgz
tar -xzvf xdebug-2.2.1.tgz
cd xdebug-2.2.1
phpize
./configure --enable-xdebug
sudo make
sudo make install
sudo service apache2 restart
@drobinson
drobinson / getModuleDir.php
Created March 12, 2013 18:22
Get path to a module component, good for getting the path to a controller when rewriting
Mage::getModuleDir(‘controllers’, ‘Packagename_Modulename’);
@drobinson
drobinson / salesrulebugfix.diff
Created May 14, 2013 21:38
Fixes salesrule times_used data update bug introduced in Magento CE 1.8 and EE 1.13 Salesrules with zero sum discount amounts (such as salesrules created for free shipping) will not have their times_used data updated.
Index: app/code/core/Mage/SalesRule/Model/Observer.php
===================================================================
--- app/code/core/Mage/SalesRule/Model/Observer.php (revision 146067)
+++ app/code/core/Mage/SalesRule/Model/Observer.php (working copy)
@@ -90,7 +90,6 @@
$customerId = $order->getCustomerId();
// use each rule (and apply to customer, if applicable)
- if ($order->getDiscountAmount() != 0) {
foreach ($ruleIds as $ruleId) {
@drobinson
drobinson / git_rm_untracked.sh
Created August 13, 2013 18:40
Remove all untracked changes from the current directory - good for package-based installs that have a lot of untracked changes (that you don't need for what you're working on) for some reason or another.
$ git clean -fdn
# -f force (because Obi-Wan says so)
# -d also removes directories
# -n dry run (ALWAYS do this first)
# You can also specify a path, but to be safe I always just cd to where I want to destroy changes
@drobinson
drobinson / rm_svn_tracking.sh
Created September 6, 2013 16:53
Recursively remove all .svn directories under the current directory
rm -rf `find . -type d -name .svn`
@drobinson
drobinson / product_list_block_fix.diff
Last active December 23, 2015 20:19
Fixes problem with loading a product list block while there is a "product" entity set on the registry
Index: app/code/core/Mage/Catalog/Block/Product/List.php
===================================================================
--- app/code/core/Mage/Catalog/Block/Product/List.php
+++ app/code/core/Mage/Catalog/Block/Product/List.php
@@ -71,7 +71,7 @@
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
- $this->setCategoryId(current($categories->getIterator()));
+ $this->setCategoryId(current($categories->getIterator())->getId());