Cleaning the log tables and rebuilding indexes with shell scripts

magento shells scripts usage

Based on the same idea as my “cache clearing script” (but 10x better), Magento now includes some handy scripts to clean the log tables, to compile source files and to rebuild indexes. For people with very large databases (10k+ products) this is sometimes the only way to actually accomplish something without running out of memory or exceeding execution time limits. The scripts are located in the /shell folder. These scripts are made to be run manually by logging on the server with SSH or they may also be setup to be executed periodically as a cron job.

Below, is a little preview of the possible operations

Usage: php -f log.php -- [options]
php -f log.php -- clean --days 1
clean                Clean Logs
--days <days>  Save log, days. (Minimum 1 day, if defined - ignoring system value)
status               Display statistics per log tables
help                 This help
Usage: php -f indexer.php -- [options]
--status <indexer>         Show Indexer(s) Status
--mode <indexer>           Show Indexer(s) Index Mode
--mode-realtime <indexer>  Set index mode type "Update on Save"
--mode-manual <indexer>    Set index mode type "Manual Update"
--reindex <indexer>        Reindex Data
info                       Show allowed indexers
reindexall                 Reindex Data by all indexers
help                       This help
<indexer> Comma separated indexer codes or value "all" for all indexers
Usage:  php -f compiler.php -- [options]
state         Show Compilation State
compile       Run Compilation Process
clear         Disable Compiler include path and Remove compiled files
enable        Enable Compiler include path
disable       Disable Compiler include path
help          This help

Updating Magento code to be compatible with PHP 5.3

Even tough PHP 5.3 has been out for quite a while, there is still lots of old code out there that will not run correctly when moved from 5.2 to 5.3. In my case I had to move a 2 year old Magento website to a new server and ran into problems as the default version of PHP on the new server was setup as PHP 5.3. Altough PHP 5.3 is a “minor” version, there is quite a few “deprecated” core functions and severak little things that just dont work the same anymore. So in this post I will explain specifically what functions I had to update and a couple of examples of how I did it in each case.

Continue reading “Updating Magento code to be compatible with PHP 5.3”

Magento Notice: Undefined index: 0

Today I got this mysterious error message after moving a Magento website to a new server.

Magento Notice: Undefined index: 0  in .../htdocs/app/code/core/Mage/Core/Model/Mysql4/Config.php on line 92

Turns out this was due to a faulty import of the database. Apparently there are a few tables where using an id of 0 in the auto_increment column has a particular meaning and is intended. When restoring the MySQL dump through Navicat it replaced id values of 0 in auto_increment columns with new auto-incremented ids instead of 0 which broke Magento.

To fix this I simply dropped the whole database and reimported the dump using the official MySQL command line client (mysql -u username -p db_name < scrip.sql) and everything worked fine.

Netbeans Preparing Commit

If you ever tried to SVN commit a big project using Netbeans (Magento?) you have most likely seen that “Preparing Commit” message doing seemingly absolutely nothing for several minutes. Apparently the commit takes forever because Netbeans is scanning the entire projet to localize any changes done by external applications before committing. This is not really an issue in 99% of my usual work days thus I had to find a way to disable this.

Seems that adding


To he netbeans configuration file will disable the automatic scan during the commit preparation phase. If for whatever reason  you end up changing a file outside Netbeans (external text editor, adding new pictures…) you cam simply go to the “Files” tab and right-click your projet and hit “Refresh Folder” to let it scan everything.

See for information on how to change the netbeans configuration file.