You are here

protected function LogProcessor::entitySaveAccess in Log entity 7

Check that the user has permission to save a log.

File

includes/feeds/plugins/LogProcessor.inc, line 71
Class definition of LogProcessor.

Class

LogProcessor
Creates logs from feed items.

Code

protected function entitySaveAccess($entity) {

  // The check will be skipped for anonymous logs.
  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) {
      $message = 'User %uid is not a valid user.';
      throw new FeedsAccessException(t($message, array(
        '%uid' => $entity->uid,
      )));
    }
    if (empty($entity->id) || !empty($entity->is_new)) {
      $op = 'create';
      $access = log_access($op, $entity->type, $author);
    }
    else {
      $op = 'update';
      $access = log_access($op, $entity, $author);
    }
    if (!$access) {
      $message = t('The user %name is not authorized to %op logs of type %content_type. To import this item, either the user "@name" (author of the item) must be given the permission to @op logs of type @content_type, or the option "Authorize" on the log 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);
    }
  }
}