You are here

function _comment_resource_update in Services 6.3

Same name and namespace in other branches
  1. 7.3 resources/comment_resource.inc \_comment_resource_update()

Updates a comment and returns the cid.

Parameters

$cid: Unique identifier for this comment.

$comment: An object as would be returned from comment_load().

Return value

Unique identifier for the comment (cid) or FALSE if there was a problem.

1 string reference to '_comment_resource_update'
_comment_resource_definition in resources/comment_resource.inc
@file Will define the comments resource for dealing with node comments

File

resources/comment_resource.inc, line 293
Will define the comments resource for dealing with node comments

Code

function _comment_resource_update($cid, $comment) {

  // Adds backwards compatability with regression fixed in #1083242
  $comment = _services_arg_value($comment, 'data');
  $comment['cid'] = $cid;
  $old_comment = (array) _comment_load($cid);
  if (empty($old_comment)) {
    return services_error(t('Comment @cid not found', array(
      '@cid' => $comment['cid'],
    )), 404);
  }

  // Setup form_state.
  $form_state = array();
  $form_state['values'] = $comment;
  $form_state['values']['op'] = variable_get('services_comment_save_button_resource_update', t('Save'));
  $form_state['comment'] = $old_comment;
  drupal_execute('comment_form', $form_state, $old_comment);
  if ($errors = form_get_errors()) {
    return services_error(implode(" ", $errors), 406, array(
      'form_errors' => $errors,
    ));
  }
  return $cid;
}