I am trying to create an entity with entity_metadata_wrapper from within hook_boot. I know everyone will say "use hook_init" but for performance reasons, I'm going w/ hook_boot :) .
I have a couple modules loaded like so:
require_once DRUPAL_ROOT . '/includes/common.inc';
drupal_load('module', 'entity');
drupal_load('module', 'field');
This is what I have:
$entity = entity_create('myentity', array('type' => 'click'));
$ew = entity_metadata_wrapper('myentity',$entity);
$ew->field_myentity_url_reference->set($row->rid);
$ew->save();
The above works fine if run normally (like from form_alter or something), but not from hook_boot.
I am getting the following errors:
Warning: class_implements(): object or string expected in entity_create() (line 367 of /data/disk/host/distro/005/drupal-7.18.1-dev/sites/mysite.com/modules/entity/entity.module).
Warning: in_array() expects parameter 2 to be array, boolean given in entity_create() (line 367 of /data/disk/host/distro/005/drupal-7.18.1-dev/sites/mysite.com/modules/entity/entity.module).
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set() (line 122 of /data/disk/host/distro/005/drupal-7.18.1-dev/sites/mysite.com/modules/entity/includes/entity.wrapper.inc).
Anyone know what else I need to drupal_load to get this to work?
EDIT - Figure out how to do this:
I used the background process module: http://drupal.org/project/background_process. I added the code below to hook_boot:
//load the required modules needed to do background_process
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/path.inc';
drupal_load('module', 'background_process');
drupal_load('module', 'progress');
background_process_start('shurly_create_click_log', $row);// drupal_load('module', 'entity');
Then I put the entity code in a new function:
function shurly_create_click_log ($row){
$entity = entity_create('linkpin', array('type' => 'click'));
$ew = entity_metadata_wrapper('linkpin',$entity);
$ew->field_linkpin_url_reference->set($row->rid);
$ew->save();
}
Basically, the shurly_create_click_log function gets ran at full bootstrap in the background, so it doesn't slow down my pageload/redirect from hook_boot.