php - Magento shell command fatal error: Class "Mage" not found -


when run command within /shell/ directory:

php -f regularpromos.php 

why receive error?

php fatal error: class 'mage' not found in /var/www/vhosts/yoohoo/httpdocs/shell/regularpromos.php on line 28 

this regularpromos.php:

<?php  require_once 'abstract.php';  class mage_shell_regularpromos extends mage_shell_abstract {          //day of week repeat promotion     protected $day;      //id of promotion     protected $promoid;      //rule process object     protected $rule;       public function mage_shell_regularpromos($promoid, $day)     {         $this->day = $day;         $this->promoid = $promoid;         $this->rule = mage::getmodel('salesrule/rule');     }       public function run()     {         date_default_timezone_set('america/new_york');         $nextweek = date('y-m-d', strtotime('next '. $this->day));         $rule = $rule->load($this->promoid);         $rule->setfromdate($nextweek)                 ->settodate($nextweek)                 ->save();     } }  $shell = new mage_shell_regularpromos(7, 'monday'); $shell->run();  ?> 

per threads find on issue:

  • i've tried running compiler on/off/cleared/compiled, same error message

  • i've cleared cache via admin panel , manually deleting in /var/cache/.

  • apc not show in phpinfo(), shouldn't issue either.

i can run compiler.php fine, assume i've made mistake in php above.

i'm running magento 1.7 ce, php 5.3.3

you've extended base abstract class incorrectly. if @ abstract constructor

#file: shell/abstract.php public function __construct() {     if ($this->_includemage) {         require_once $this->_getrootpath() . 'app' . directory_separator . 'mage.php';         mage::app($this->_appcode, $this->_apptype);     }      $this->_applyphpvariables();     $this->_parseargs();     $this->_construct();     $this->_validate();     $this->_showhelp(); } 

you can see shell scripts require in mage application class. class has redefined constructor using older php syntax

public function mage_shell_regularpromos($promoid, $day) {     $this->day = $day;     $this->promoid = $promoid;     $this->rule = mage::getmodel('salesrule/rule'); } 

but you've not called parent constructor. means mage class isn't required, , other important initialization doesn't happen. i'd redefine constructor method such uses newer __construct syntax, , call parent constructor

public function __construct($promoid, $day) {     parent::__construct();     $this->day = $day;     $this->promoid = $promoid;     $this->rule = mage::getmodel('salesrule/rule'); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -