Skip to content

Instantly share code, notes, and snippets.

@cgdangelo
cgdangelo / mage-scan.sh
Created Mar 8, 2012
Find insecure Magento websites
View mage-scan.sh
#!/bin/bash
if [ -e "$1" ]; then
dataset=$(cat $1)
elif [ ! -z $1 ]; then
dataset=$@
else
exit 1
fi
@cgdangelo
cgdangelo / mage-constraints.sql
Created Mar 23, 2012
Recreate foreign keys for a Magento installation, after you fire the idiot who deleted all of them.
View mage-constraints.sql
# one-liner for generating this: mysqldump --no-data -uroot magento1600 | nawk '{if(match($0, /CREATE TABLE `(.*)`/, matchesT)) { the_table = matchesT[1]; } if(match($0, /(CONSTRAINT .*),?/, matchesK) && the_table) { the_key = gensub(/,?$/, "", matchesK[1]); the_key = gensub(/^ */, "", the_key); print "ALTER TABLE `" the_table "` ADD", the_key ";"; }}'
ALTER TABLE `admin_rule` ADD CONSTRAINT `FK_ADMIN_RULE_ROLE_ID_ADMIN_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_rule` ADD CONSTRAINT `FK_API_RULE_ROLE_ID_API_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `api_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_session` ADD CONSTRAINT `FK_API_SESSION_USER_ID_API_USER_USER_ID` FOREIGN KEY (`user_id`) REFERENCES `api_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `catalog_category_entity_datetime` ADD CONSTRAINT `FK_CAT_CTGR_ENTT_DTIME_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id
@cgdangelo
cgdangelo / git-iclean.sh
Created Apr 4, 2012
Interactive git-clean
View git-iclean.sh
#!/bin/sh
GC_OPTS=$@
for item in `git clean $@ | grep -v git-iclean | grep "Would remove" | cut -d' ' -f 3`; do
rm -ir $item
done
@cgdangelo
cgdangelo / gist:2956737
Created Jun 19, 2012
Compare customized layout to default
View gist:2956737
#!/bin/sh
# Run from /docroot/app/design/[adminhtml|frontend|install]/[package]/[theme]
vimdiff ../../base/default/${1} ${1}
View gist:3132147
<?php
require 'app/Mage.php';
umask(0);
Mage::app();
$attribute = Mage::getModel('catalog/entity_attribute')->loadByCode(
Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId(),
'tiger_cost'
);
@cgdangelo
cgdangelo / gist:3219998
Created Jul 31, 2012
Interactively delete untracked files
View gist:3219998
for i in `git ls-files --other --exclude-standard`; do rm -ir $i; done
View output
<?php
class X_TigerEDI_Model_Observer_850 extends X_TigerEDI_Model_Observer
{
protected $_ediID = 850;
private $_ediFiles = array();
/**
@cgdangelo
cgdangelo / gist:3495542
Created Aug 28, 2012
Magento Rakefile with some basic, common tasks
View gist:3495542
current_path = File.dirname(__FILE__)
parent_path = File.dirname(current_path)
project = File.basename(current_path)
namespace :mage do
desc 'Clear the Magento cache.'
task :cc do
sh %{cd #{current_path} && rm -rf var/cache/*}
end
View gist:3498364
<?php
/* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
$tree = Mage::getResourceModel('catalog/category_tree');
/* 594 = 616, 597 = 856 */
$storeCategories = $this->getStoreCategories();
$storeCategories->delete($storeCategories->searchById(594));
$storeCategories->delete($storeCategories->searchById(597));
$node = $tree->loadNode(616);
@cgdangelo
cgdangelo / .gitignore
Created Oct 5, 2012
Magento .gitiginore
View .gitignore
var/*
media/*
pkginfo/*
config/*
app/etc/local.xml
includes/*
Capfile
.idea/*
.DS_Store
*.*~