Posted by dealancer on October 1, 2012 at 5:41pm
3 followers
Jump to:
| Project: | Entity API |
| Version: | 7.x-1.x-dev |
| Component: | Code - misc |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
If storing entities in $_SESSION we can get following error:
( ! ) Fatal error: Call to undefined function entity_get_info() in /var/www/my_site/sites/all/modules/contrib/entity/includes/entity.inc on line 55
Call Stack
# Time Memory Function Location
1 0.0000 328312 {main}( ) ../index.php:0
2 0.0004 388768 drupal_bootstrap( ) ../index.php:20
3 0.0049 997056 drupal_session_initialize( ) ../bootstrap.inc:2188
4 0.0049 997732 drupal_session_start( ) ../session.inc:251
5 0.0049 997820 session_start ( ) ../session.inc:287
6 0.0064 1273024 Entity->__wakeup( ) ../entity.inc:0
7 0.0064 1273024 Entity->setUp( ) ../entity.inc:300as we can see after calling session_start, php, tries to unserialize entity object, this automatically causes that __wakeup() is called and finally setUp( ) is called. setUp( ) has following code:
<?php
protected function setUp() {
$this->entityInfo = entity_get_info($this->entityType);
$this->idKey = $this->entityInfo['entity keys']['id'];
$this->nameKey = isset($this->entityInfo['entity keys']['name']) ? $this->entityInfo['entity keys']['name'] : $this->idKey;
$this->statusKey = empty($info['entity keys']['status']) ? 'status' : $info['entity keys']['status'];
}
?>Just because
<?php
public function __sleep() {
$vars = get_object_vars($this);
unset($vars['entityInfo'], $vars['idKey'], $vars['nameKey'], $vars['statusKey']);
// Also key the returned array with the variable names so the method may
// be easily overridden and customized.
return drupal_map_assoc(array_keys($vars));
}
?>Not sure if there is any way to fix it, but it would be nice to have this fixed.
Comments
#1
#2
I wound up serializing to get around this (it just happened to me over the weekend):
<?php$_SESSION['solr']['query'] = serialize($this->query);
?>
Didn't happen anymore. My purpose of storing an entity in session may be different than yours, though (saved Solr search params).
#3
well yeah, one of the solution is to stored serialized entities in the session and manually deserialize it.
#4
Yeah, was agreeing with you, I see what you're getting at. Wasn't sure if you knew/needed a quick workaround.