I would appreciate help on this, I'm having trouble bringing these two together.
I am basically familiar with the mysql upgrade process in magento.
In a folder's
etc/config.xml
file you update the version<Mycompany_Myextension> <version>0.1.4</version><!-- update from 0.1.3 --> ..
Write a file called `mysql4-upgrade-0.1.3-0.1.4.php
in that file have something like this:
$installer = $this;
$installer->run("Some SQL query here");
I want to run that outside of the Magento App, however...
So I have created a bootstrap file in /shell, but how do I instantiate $installer? My bootstrap.php file is outside the same instantiation path as the mysql upgrade file.
Just for full docs, here is the shell file code (I have noted "throws fatal error" where the problem is):
<?php
/*
* COMPANY-9047
* @author: me
* @date: 2016-04-29
* Used to run a MySQL upgrade script outside of Magento
*/
require_once 'abstract.php';
class Company_Shell_Genericscript extends Mage_Shell_Abstract
{
protected $_argname = array();
public function __construct() {
parent::__construct();
// Time limit to infinity
set_time_limit(0);
// Get command line argument named "argname"
// Accepts multiple values (comma separated)
if($this->getArg('argname')) {
$this->_argname = array_merge(
$this->_argname,
array_map(
'trim',
explode(',', $this->getArg('argname'))
)
);
}
}
protected function _getConnection($type = 'core_read'){
if ($this->blnUseMyEnvironment != false){
return Mage::getSingleton('core/resource')->getConnection($type);
}
if (!$objConnection = Mage::getConfig()->getNode('global/resources/replica/connection') ) {
Mage::throwException('Replica connection info is missing.');
}
try {
$arrConnection = $objConnection->asArray();
$objReplicaDb = new Zend_Db_Adapter_Pdo_Mysql(
array(
'host' => $arrConnection['host'],
'username' => $arrConnection['username'],
'password' => $arrConnection['password'],
'dbname' => $arrConnection['dbname']
)
);
return $objReplicaDb;
}catch(Exception $e){
echo $e->getMessage().", in ".__FILE__." on line ".$e->getLine()."\n\n";
}
}
// Shell script point of entry
public function run() {
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$this->startSetup(); //throws fatal error
exit('end');
}
// Usage instructions
public function usageHelp()
{
return <<<USAGE
Usage: php -f scriptname.php -- [options]
--argname <argvalue> Argument description
help This help
USAGE;
}
}
// Instantiate
$shell = new Company_Shell_Genericscript();
// Initiate script
$shell->run();