Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Created September 16, 2014 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molotovbliss/01f8fb992f05466890a6 to your computer and use it in GitHub Desktop.
Save molotovbliss/01f8fb992f05466890a6 to your computer and use it in GitHub Desktop.
shell/tools.php Shell Development Template
<?php
/*
* General shell template used in development
*/
require_once 'abstract.php';
// Generic PHP development settings
umask(0);
ob_implicit_flush(true);
ini_set('display_errors', 1);
set_time_limit(0);
class Mage_Shell_Tools extends Mage_Shell_Abstract {
/**
* Run script
*
*/
public function run()
{
$file = $this->getArg('file');
$command = $this->getArg('command');
// Start of main entry point (code here)
}
/**
* Set all indexes to manual mode for faster updates
*/
public function disableIndexes()
{
$pCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($pCollection as $process) {
$process->setMode(Mage_Index_Model_Process::MODE_MANUAL)->save();
}
}
/**
* Set all indexes back to realtime
*/
public function enableIndexes()
{
$pCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($pCollection as $process) {
$process->setMode(Mage_Index_Model_Process::MODE_REAL_TIME)->save();
}
}
/**
* Get Read DB connection for direct SQL queries
*/
public function getReadDbConnection() {
return Mage::getSingleton('core/resource')->getConnection('core_read');
}
/**
* Get Write DB connection for direct SQL queries
*/
public function getWriteDbConnection() {
return Mage::getSingleton('core/resource')->getConnection('core_write');
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f tools.php -- [options]
php -f tools.php -- command -- file var/importexport/file.csv
help This help
--file <file> location of csv file to be used
USAGE;
}
}
$shell = new Mage_Shell_Tools();
$shell->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment