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:300
as 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:
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
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
Comment #1
dealancer commentedComment #2
kevinquillen commentedI wound up serializing to get around this (it just happened to me over the weekend):
Didn't happen anymore. My purpose of storing an entity in session may be different than yours, though (saved Solr search params).
Comment #3
dealancer commentedwell yeah, one of the solution is to stored serialized entities in the session and manually deserialize it.
Comment #4
kevinquillen commentedYeah, was agreeing with you, I see what you're getting at. Wasn't sure if you knew/needed a quick workaround.
Comment #5
valthebaldI don't think there is an easy way to fix this, that will not affect performance.
Wakeup happens when Drupal is not bootstrapped yet, so it's impossible to use entity_get_property_info() or even drupal_get_path()