function cis_connector_entity_presave

cis7 cis_connector.module cis_connector_entity_presave($entity, $type)
cle7 cis_connector.module cis_connector_entity_presave($entity, $type)
elmsmedia7 cis_connector.module cis_connector_entity_presave($entity, $type)
icor7 cis_connector.module cis_connector_entity_presave($entity, $type)
meedjum_blog7 cis_connector.module cis_connector_entity_presave($entity, $type)
mooc7 cis_connector.module cis_connector_entity_presave($entity, $type)

Implements hook_entity_presave().

@todo review this concept as it may be making too many assumptions about how entity save works when distributed across systems.

File

sites/all/modules/elmsln_contrib/cis_connector/cis_connector.module, line 990
CIS Connector, library to build an ELMS learning network.

Code

function cis_connector_entity_presave($entity, $type) {
  // only run this when it's our form deployed remotely
  $info = entity_get_info($type);
  // ensure we have bundle keys at least after loading info
  if (isset($info['bundle keys']['bundle']) && isset($entity->{$info['bundle keys']['bundle']})) {
    $rem = _cis_connector_remote_entities($type, $entity->{$info['bundle keys']['bundle']});
    // @todo this appears to be a glitch in RestWS
    // How could an item be submitted as annonymous if the user isn't?

    // don't allow annonymous submissions from outside system
    // this applies at the moment for service account based items
    // this is the only role able to post in this manner
    // but we verify this anyway based on role
    if (count($rem) > 0 && $entity->uid == 0 && in_array('SERVICE ACCOUNT', $GLOBALS['user']->roles)) {
      $entity->uid = $GLOBALS['user']->uid;
    }
    // if we have at least 1 match, add the settings, otherwise never runs
    foreach ($rem as $key => $item) {
      // make sure this isn't the current bucket we are working in
      if (!in_array(variable_get('install_profile', ''), $item['buckets'])) {
        // prepare the item for shipment
        $data = _cis_connection_prepare_entity($entity);
        // execute call
        foreach ($item['buckets'] as $bucket) {
          // post the formatted object to the other address
          $instance = '';
          $settings = _cis_connector_build_registry($bucket);
          if ($settings['instance']) {
            $instance = str_replace('/', '', base_path()) . '/';
          }
          $return = _cis_connection_object(NULL, $type, NULL, 'POST', $data, $bucket, $instance, FALSE, '', $item['options']);
          // if non-blocking this won't have anything it can do but still..
          drupal_alter('cis_remote_entities_insert', $return, $bucket);
        }
        // our save mode told us to remove the current one
        if ($item['save'] == CIS_CONNECTOR_ENTITY_REMOTE_ONLY) {
          // try to wipe the entity and hope it doesn't cause an issue
          $entity = NULL;
          // @todo May need to issue drupal_goto to truly
          // hijack the operation. look into running this hook
          // last to avoid possible issues with other projects
        }
      }
    }
  }
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.