2

I can execute a shell script from a custom php script. I have no trouble including the abstract.php, log a string or calling let's say the product model. Playing around with including parameters from the php script to the shell script is no problem either.

But when it comes to calling a custom helper-function like this:

Mage::helper('customModuleName/helperName')->methodName()

and var_dump() the result (or whatever function you like) I get nothing. I've called the helper function a dozen times in other scripts. It seems that the helper function cannot be executed in a shell script. Whatever helper method for that matter. I tried to call other helpers too.

Is my deduction a valid one or do I miss the knowledge of execution a shell script? In other words: is it possible to execute a custom helper function in a shell script?

EDIT :

thanks in advance for all your replies!

here's my code

<?php

require_once 'abstract.php';

class Santee_Shell_Upload extends Mage_Shell_Abstract {

    public function run() {
        global $argv;
        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
        $path = $argv[1];

        $dir = Mage::getBaseDir() . "/shell/";
        MAGE::helper('updateproducts/runupdate')->unSetIndex();
        $objects = MAGE::helper('updateproducts/runupdate')->getAllObjects($path);

        MAGE::helper('updateproducts/runupdate')->startUpdate($objects);
        MAGE::helper('updateproducts/runupdate')->setIndex();
        $command = 'php -f ' . $dir . 'indexer.php reindexall';
        $result = shell_exec($command);
    }

    public function usageHelp() {
        return <<<USAGE
Usage:  php -f upload.php -- [options]
        php -f upload.php 


USAGE;
    }

}

$shell = new Santee_Shell_Upload();
$shell->run();
  • Could you post your code? There's no reason why a helper wouldn't work in a script that I can think of. – Laura Feb 24 '15 at 20:31
  • Calling a helper method from the shell is perfectly possible, depending on how Magento is bootstrapped you may get unexpected results. For example some functions will return different information from a frontend store than from the admin store, which is what most scripts are bootstrapped as. – Peter O'Callaghan Feb 24 '15 at 20:43
  • Could you post your config file as well as your helper function? Also, you are calling all of your helpers with MAGE in all caps. Are you on a windows server? Casing matters in windows. – Ryan Street Feb 25 '15 at 16:23
1

The answer is yes. You have the full availability of Magento's abstract factory when you run a shell script. My guess is there is a problem with your helper declaration or your module's config file.

What is the scope of your declaration of your helpers? Is it in the <global> node?

  • Hi Ryan, yes the helpers are declared as global – Thomas Coucke Feb 25 '15 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.