Just finished migrating a Magento website to a new server. Using the following steps:
-Backup the database in the backend
-Import the database on new server
-Copy all files from old server to new server
-Set correct file permissions
-Update /app/etc/local.xml
-Update secure and unsecure base_url in database
-Remove cache and session files
The website itself works fine, but it seems to give a fatal error on the order button now (see screenshot of source)
This is the block of code the error refers to:
/**
* Product type instance factory
*
* #param Mage_Catalog_Model_Product $product
* #param bool $singleton
* #return Mage_Catalog_Model_Product_Type_Abstract
*/
public static function factory($product, $singleton = false)
{
$types = self::getTypes();
$typeId = $product->getTypeId();
if (!empty($types[$typeId]['model'])) {
$typeModelName = $types[$typeId]['model'];
} else {
$typeModelName = self::DEFAULT_TYPE_MODEL;
$typeId = self::DEFAULT_TYPE;
}
if ($singleton === true) {
$typeModel = Mage::getSingleton($typeModelName);
}
else {
$typeModel = Mage::getModel($typeModelName);
$typeModel->setProduct($product);
}
$typeModel->setConfig($types[$typeId]); /**this is line 80**/
return $typeModel;
}
I also tried to make a fresh install and copy the needed files, but that did not work either.
This is my first time working with Magento, and searching online for a solution did not bring up anything useful to me. Could anyone point me to the right direction?
Related
I need help to understand how i can make inotify work with PHP.
I have a main file where i call a instance of a inotify class i created.
This works for 30 seconds and then php throws a timeout error. In that time window it can in fact print information from new files and deleted ones. It kinda works but...
My questions for you guys are:
how can i make it persistent and stable. I mean i can set timeout requests for unlimited time but that doesn't seem to be a good practice. How to deal with this?
It's supposed to work like this? I call the function and the php
hangs in that loop until a new change happens?
My index.php
$teste = new Inotify_service();
$teste->add_watch('files');
class Inotify_service
{
private $instance;
private $watch_id;
public function __construct()
{
$this->instance = inotify_init();
stream_set_blocking($this->instance, 0); # this is needed so inotify_read while operate in non blocking mode
}
/**
* [add_watch Adds a new watch or modify an existing watch for the file or directory specified in pathname]
* #param [string] $pathname [description]
*/
public function add_watch($pathname)
{
$this->watch_id = inotify_add_watch($this->instance, $pathname, IN_CREATE | IN_DELETE);
while(true){
// read events
$events = inotify_read($this->instance);
// if the event is happening within our 'Files directory'
if ($events[0]['wd'] === $this->watch_id){
// a file was created
if($events[0]['mask'] === IN_CREATE){
printf("Created file: %s in Files directory\n", $events[0]['name']);
// a file was deleted
} else if ($events[0]['mask'] === IN_DELETE){
printf("Deleted file: %s in Files directory\n", $events[0]['name']);
}
}
}
// stop watching our directories
inotify_rm_watch($this->instance, $this->watch_id);
// close our inotify instance
fclose($this->instance);
}
I want to put my module in Prestashop market place, and make it standard everyone can use it. This plugin needs to know the admin directory name dynamically to do its service.
I have searched on the Internet a lot of times, but I didn't find a solution to this issue.
You can use _PS_ADMIN_DIR_ witch is set in [your_admin_dir]/index.php:
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', getcwd());
}
This constant is only set when you're on an admin context. Your FrontOffice doesn't have knowledge of this directory and should not for obvious security reason.
There's also a getAdminLink method in class Link:
/**
* Use controller name to create a link
*
* #param string $controller
* #param bool $with_token include or not the token in the url
* #return string url
*/
public function getAdminLink($controller, $with_token = true)
{
$id_lang = Context::getContext()->language->id;
$params = $with_token ? array('token' => Tools::getAdminTokenLite($controller)) : array();
return Dispatcher::getInstance()->createUrl($controller, $id_lang, $params, false);
}
Example:
// Here we create a link to the dashboard without token
$this->context->link->getAdminLink(Tab::getClassNameById(1), false)
I'm scraping data from an API. The problem is that I'm querying the data too often for each pageload, so I'd like to store the data on the server after the first query. This should be fine according to the TOS.
On example.com/page:
<?php include 'example.com/data'; ?>
On example.com/data:
<?php include 'api.com/include'; ?>
So I am including a page from my server, and that page is including the api data from the external server.
Question 1: How can I tell example.com/data to WRITE or save the information from api.com/include as a file on the server such as example.com/data1.php ?
Question 2: How can I tell example.com/page to php include example.com/data1.php, and if it's a 404 (doesn't exist) to include example.com/data instead?
With both questions 1 and 2 answered I can query the api once, store the data as a file, and if that file exists use the data from that page rather than have to query the api each time the page is loaded.
If you know of a better way of doing this I'd be grateful to learn it. Though it is important that I include from example.com/data from example.com/page rather than directly from api.com/include because example.com/data has the correct code handlers to properly interpret and filter the information from api/include.
If you can answer either of the two questions it would be a great starting ground for me solving the other problem.
Thank you!
You should use a class to decouple this behaviour. Something like this:
<?php
class ReadApiFromDomainDotCom
{
const TTL = 3600; // File is fresh for 3600 sec
const FILE_NAME = 'whatever.txt';
const API_ADDRESS = "http://api.whatever.com";
/**
* #return string
*/
public function get()
{
if ($this->isCacheValid()) {
return file_get_contents(self::FILE_NAME);
}
return $this->readApi();
}
/**
* #return bool
*/
private function isCacheValid()
{
if (!file_exists(self::FILE_NAME)) {
return false;
}
if ($this->isExpired()) {
return false;
}
return true;
}
/**
* #return bool
*/
private function isExpired()
{
return time() - filemtime(self::FILE_NAME) > self::TTL;
}
/**
* #return string
*/
private function readApi()
{
$data = file_get_contents(self::API_ADDRESS);
file_put_contents(self::FILE_NAME, $data);
return $data;
}
}
Then it will be easy as:
$apiReader = new ReadApiFromDomainDotCom();
$data $apiReader->get();
Haven't tested this code so you will have to fiddle with it a bit. Add namespace, paths and so on.
Server running RHEL 7 and PHP 5.4.16. When I try to open /phpMyAdmin in my browser, I'm given the error:
Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php on line 242
Call Stack
# Time Memory Function Location
1 0.0008 348000 {main}( ) ../index.php:0
2 0.0018 503144 require_once( '/usr/share/phpMyAdmin/libraries/common.inc.php' ) ../index.php:12
3 0.0252 4224464 PMA_Config->__construct( ) ../common.inc.php:304
4 0.0252 4224712 PMA_Config->load( ) ../Config.class.php:100
5 0.0265 4309888 PMA_Config->checkConfigSource( ) ../Config.class.php:849
6 0.0265 4311088 PMA_fatalError( ) ../Config.class.php:1169
I believe I've installed all required libraries and that apache has the proper permissions for the session.save_path directory, which were the issues previous times that this question had been asked. See: Call to undefined function __() error - phpMyAdmin
Can someone give me a hint based on that call stack?
Here are the functions from the lines that the stack trace references, with the relevant line written in the left margin:
core.lib.php at line 242:
/**
* displays the given error message on phpMyAdmin error page in foreign language,
* ends script execution and closes session
*
* loads language file if not loaded already
*
* #param string $error_message the error message or named error message
* #param string|array $message_args arguments applied to $error_message
* #param boolean $delete_session whether to delete session cookie
*
* #return void
*/
function PMA_fatalError(
$error_message, $message_args = null, $delete_session = true
) {
/* Use format string if applicable */
if (is_string($message_args)) {
$error_message = sprintf($error_message, $message_args);
} elseif (is_array($message_args)) {
$error_message = vsprintf($error_message, $message_args);
}
if ($GLOBALS['is_ajax_request']) {
$response = PMA_Response::getInstance();
$response->isSuccess(false);
$response->addJSON('message', PMA_Message::error($error_message));
} else {
$error_message = strtr($error_message, array('<br />' => '[br]'));
/* Load gettext for fatal errors */
if (!function_exists('__')) {
// It is possible that PMA_fatalError() is called before including
// vendor_config.php which defines GETTEXT_INC. See bug #4557
if (defined(GETTEXT_INC)) {
include_once GETTEXT_INC;
} else {
include_once './libraries/php-gettext/gettext.inc';
}
}
// these variables are used in the included file libraries/error.inc.php
242 $error_header = __('Error');
$lang = $GLOBALS['available_languages'][$GLOBALS['lang']][1];
$dir = $GLOBALS['text_dir'];
// on fatal errors it cannot hurt to always delete the current session
if ($delete_session
&& isset($GLOBALS['session_name'])
&& isset($_COOKIE[$GLOBALS['session_name']])
) {
$GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
}
// Displays the error message
include './libraries/error.inc.php';
}
if (! defined('TESTSUITE')) {
exit;
}
}
common.inc.php at line 304:
304 $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
if (!defined('PMA_MINIMUM_COMMON')) {
$GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
}
Config.class.php at line 100:
/**
* constructor
*
* #param string $source source to read config from
*/
function __construct($source = null)
{
$this->settings = array();
// functions need to refresh in case of config file changed goes in
// PMA_Config::load()
100 $this->load($source);
// other settings, independent from config file, comes in
$this->checkSystem();
$this->isHttps();
$this->base_settings = $this->settings;
}
Config.class.php at line 849:
/**
* loads configuration from $source, usually the config file
* should be called on object creation
*
* #param string $source config file
*
* #return bool
*/
function load($source = null)
{
$this->loadDefaults();
if (null !== $source) {
$this->setSource($source);
}
/**
* We check and set the font size at this point, to make the font size
* selector work also for users without a config.inc.php
*/
$this->checkFontsize();
if (! $this->checkConfigSource()) {
849 return false;
}
Config.class.php at line 1169:
/**
* check config source
*
* #return boolean whether source is valid or not
*/
function checkConfigSource()
{
if (! $this->getSource()) {
// no configuration file set at all
return false;
}
if (! file_exists($this->getSource())) {
$this->source_mtime = 0;
return false;
}
if (! is_readable($this->getSource())) {
// manually check if file is readable
// might be bug #3059806 Supporting running from CIFS/Samba shares
$contents = false;
$handle = #fopen($this->getSource(), 'r');
if ($handle !== false) {
$contents = #fread($handle, 1); // reading 1 byte is enough to test
#fclose($handle);
}
if ($contents === false) {
$this->source_mtime = 0;
PMA_fatalError(
sprintf(
function_exists('__')
? __('Existing configuration file (%s) is not readable.')
: 'Existing configuration file (%s) is not readable.',
$this->getSource()
)
1169 );
return false;
}
}
return true;
}
The problem was the wrong permissions for the /etc/phpMyAdmin directory. The web server user, apache, had proper permissions for the session.save_path directory, but apache couldn't read from my config.inc.php file. Changing the owner of /etc/phpMyAdmin to the apache user and changing the permissions to 755 solved the problem.
Looking at the checkConfigSource() function in Config.class.php led me to believe that if the problem was with accessing the configuration file then I would have received the error 'Existing configuration file (%s) is not readable.' instead of Call to undefined function __() Does anyone know why that wasn't the case?
This was a pretty basic problem/solution, but unless someone suggests otherwise I think I'll leave it up since this exact problem/solution isn't addressed in other discussions of the Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php error when trying to start phpMyAdmin after installation.
Had the same Error message from phpMyAdmin ::
FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php on line 245" while reading response header from upstream, client:
Solution that worked on my Fedora 22 server x86_64 using nginx :
changing the owner and the group identifier from root:apache on the file /var/lib/php/session
to root:nginx
using the command sudo chown -Rfv root:nginx /var/lib/php/session.
If phpmyadmin was working fine and then suddenly stops working for no reason with a bizarre and useless error message, you might try deleting your php sessions.
rm -rf /var/lib/php/sessions/*
The exact location may very depending on OS and version, and this will delete all active sessions, not just yours, but it can fix some "suddenly stopped working" issues when you haven't changed anything and it was working fine before.
For me it was different issue. I had given 777 permissions to phpMyAdmin forlder. When I changed it to 755, it worked fine.
Hope this will help someone.
Error "The connection was reset" File:
/usr/share/phpmyadmin/libraries/common.inc.php
search:
$GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);<br>
replace with:
$GLOBALS['PMA_Config'] = new PMA_Config();
I moved our existing Magento site to my hosting account for development work but when I try to access anywhere on the backend of the site other than the admin dashboard I get the following error:
Fatal error: Class 'Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element' not found in /magento/app/code/core/Mage/Core/Model/Layout.php on line 491
In the database core_config_data table I've changed the web/unsecure/base_url and web/secure/base_url to match the new domain name.
In the .htaccess file I've changed the RewriteBase / to use the new folder path.
The error I'm getting refers to line 491 in the Layout.php file which is the 4th if clause of the below function:
/**
* Create block object instance based on block type
*
* #param string $block
* #param array $attributes
* #return Mage_Core_Block_Abstract
*/
protected function _getBlockInstance($block, array $attributes=array())
{
if (is_string($block)) {
if (strpos($block, '/')!==false) {
if (!$block = Mage::getConfig()->getBlockClassName($block)) {
Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));
}
}
if (class_exists($block, false) || mageFindClassFile($block)) {
$block = new $block($attributes);
}
}
if (!$block instanceof Mage_Core_Block_Abstract) {
Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));
}
return $block;
}
#waldek_c comment above really helped me solve this but i thought I put an answer up myself to complete the question in case anyone else ran into something similar.
The error message itself was pointing me to the issue.
Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element was the path to the file causing the issue. As it turned out the file did not upload correctly when I was uploading the site.