Skip to content

Instantly share code, notes, and snippets.

@ProcessEight
Last active April 4, 2022 13:22
Show Gist options
  • Save ProcessEight/dde29614edc8430277eb221f2ee0f534 to your computer and use it in GitHub Desktop.
Save ProcessEight/dde29614edc8430277eb221f2ee0f534 to your computer and use it in GitHub Desktop.
Magento 1 Cheatsheet: Common Magento 1 tasks

Magento Cheatsheet (For Magento 1)

Database operations

Download Sonassi database helper

wget sys.sonassi.com/mage-dbdump.sh && chmod +x ./mage-dbdump.sh

Download Magerun

wget https://files.magerun.net/n98-magerun.phar && chmod +x ./n98-magerun.phar

Update MySQL triggers (useful when importing EE databases)

sudo perl -pi -e 's/`old_user`@`172.16.0.%`/`new_user`@`localhost`/g' *.sql

Fix error ERROR 1031 (HY000) at line 3095: Table storage engine for '...' doesn't have this option

sed -i 's/ROW_FORMAT=FIXED//g' magento-db-dump.sql

Full details: https://magento.stackexchange.com/questions/94325/how-to-fix-mysql-error-1031

Set base URLs, cookie domains, etc

select * from core_config_data where path in ('web/unsecure/base_url', 'web/secure/base_url');

update m_core_config_data set value = 'http://graphics-direct.local/' where path in ('web/unsecure/base_url', 'web/secure/base_url');

update core_config_data set value = 'http://ribble.local/' where config_id IN (1439,1440);

select * from core_config_data WHERE path = 'web/cookie/cookie_domain';

update core_config_data set value = 'two-wests-elliott.d.vortexcommerce.com' where path = 'web/cookie/cookie_domain';

select * from core_config_data where path like '%base_%_url%';

update core_config_data set value = '{{unsecure_base_url}}skin/' where config_id in (73,77); 
update core_config_data set value = '{{unsecure_base_url}}media/' where config_id in (74,78); 
update core_config_data set value = '{{unsecure_base_url}}js/' where config_id in (75,79);

Logging

Magento logging

<?php
	Mage::log([__METHOD__, __LINE__, __FILE__, '' => ], Zend_Log::DEBUG, 'sla.log', true);
	Mage::log($name, Zend_Log::DEBUG, 'events.log', true);

	$handles = Mage::getSingleton('core/layout')->getUpdate()->getHandles();
	Mage::log([__METHOD__, __LINE__, __FILE__, 'handles' => $handles], Zend_Log::DEBUG, 'handles.log', true);

	Mage::log([__METHOD__, __LINE__, __FILE__,
                   'fieldset' => $fieldset,
                   'aspect' => $aspect,
                   is_object($source) ? get_class($source) : 'source' => $source->getData(),
                   is_object($target) ? get_class($target) : 'target' => $target->getData(),
        ], Zend_Log::DEBUG, 'sla-4683.log', true);

        Mage::log([__METHOD__, __LINE__, __FILE__,
                   $eventName,
                   'fieldset' => $fieldset,
                   'aspect' => $aspect,
                   is_object($source) ? get_class($source) : 'source' => $source->getData(),
                   is_object($target) ? get_class($target) : 'target' => $target->getData(),
        ], Zend_Log::DEBUG, 'sla-4683.log', true);


?>
  • MySQL useful commands
# Setup new db:

# To export to file (schema only)
mysqldump --no-data mydb > mydb.sql

# To export to file (data only)
mysqldump --no-create-info --skip-triggers mydb > mydb.sql

# To export only specific tables
mysqldump mydb table1[ table2 tableN] > mydb.sql

# Check db name first:
head <dump>.sql

# Create database
mysql -e 'CREATE DATABASE mydb';

# Import SQL dump
mysql mydb < <dump>.sql

# Don't dump schema
--no-create-info 

# Don't dump triggers
--skip-triggers 

# Don't dump specified table
--ignore-table=mydb.table1

Setup notes

Don't forget to add a new hostname to the hosts file

Permissions

Remember to chmod the following directories:

chmod -R 777 var/ media/ app/etc/

(app/etc/ is only necessary if using the installer)

Commands

Unlock account:

update admin_user set failures_num=null,first_failure=null,lock_expires=null where user_id = 16;

Fix homepage 404 issue:

select * from enterprise_url_rewrite WHERE request_path = ''

Enable debug logs:

update core_config_data set value = 1 where path = 'dev/log/active';

Enable template hints and block names:

update core_config_data set value = 1 where path in('dev/debug/template_hints', 'dev/debug/template_hints_blocks');

Re-index from command line:

// Show available indexers
# php indexer.php info

// Show index statuses
# php indexer.php status

// Reindex all indexes
# php indexer.php reindexall

Search for all instances of class names called directly (excluding class names starting with Varien or Zend, which have to be loaded directly):

= new (?![Varien_|Zend_|PEAR])[A-Za-z]{1,}_[A-Za-z]{1,}_[A-Za-z]{1,}

Matches '= new Mage_Sales_Model' in:

$order = new Mage_Sales_Model_Order($something);

but ignores:

$uploader = new Varien_File_Uploader($name);
$client = new Zend_Http_Client();

Search for all instances of the shorthand echo statement (<?= ...)

<\?=

If you ever get the 'ERR (3): Warning: Illegal string offset 'value' in /app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php on line 111' error when switching config scopes, insert this on line 111:

} elseif (isset($v['value'])) {
    if ($v['value']==$defText) {
        $defTextArr[] = $v['label'];
        break;
    }
}

Debug from the command line in Xdebug

Just export the XDEBUG_CONFIG variable:

export XDEBUG_CONFIG="idekey=PHPSTORM"

Remember to enable Xdebug first:

/var/www/html/magento2-deployment/dev/enable-xdebug-php70.sh && export XDEBUG_CONFIG="idekey=PHPSTORM"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment