You are here

protected function FeedsNodeProcessor::entitySaveAccess in Feeds 7.2

Check that the user has permission to save a node.

Overrides FeedsProcessor::entitySaveAccess

File

plugins/FeedsNodeProcessor.inc, line 107
Class definition of FeedsNodeProcessor.

Class

FeedsNodeProcessor
Creates nodes from feed items.

Code

protected function entitySaveAccess($entity) {

  // The check will be skipped for anonymous nodes.
  if ($this->config['authorize'] && !empty($entity->uid)) {
    $author = user_load($entity->uid);

    // If the uid was mapped directly, rather than by email or username, it
    // could be invalid.
    if (!$author) {
      throw new FeedsAccessException(t('User %uid is not a valid user.', array(
        '%uid' => $entity->uid,
      )));
    }
    if (empty($entity->nid) || !empty($entity->is_new)) {
      $op = 'create';
      $access = node_access($op, $entity->type, $author);
    }
    else {
      $op = 'update';
      $access = node_access($op, $entity, $author);
    }
    if (!$access) {
      $message = t('The user %name is not authorized to %op content of type %content_type. To import this item, either the user "@name" (author of the item) must be given the permission to @op content of type @content_type, or the option "Authorize" on the Node processor settings must be turned off.', array(
        '%name' => $author->name,
        '%op' => $op,
        '%content_type' => $entity->type,
        '@name' => $author->name,
        '@op' => $op,
        '@content_type' => $entity->type,
      ));
      throw new FeedsAccessException($message);
    }
  }
}