You are here

function entity_share_ui_share_node_finished in Entity Share 7

When the batch is finished, treat success and errors.

Parameters

int $success: HTTP success or not of the operations.

array $results: Results of the operations.

array $operations: The operations remaining.

1 string reference to 'entity_share_ui_share_node_finished'
entity_share_ui_share_action_form_submit in modules/entity_share_ui/modules/entity_share_ui_client/entity_share_ui_client.share.admin.inc
Action when the form is submitted.

File

modules/entity_share_ui/modules/entity_share_ui_client/entity_share_ui_client.share.admin.inc, line 327
Entity Share UI Client Admin Share file.

Code

function entity_share_ui_share_node_finished($success, array $results, array $operations) {

  // HTTP success.
  if ($success) {
    $message = 'Sharing process completed ' . (!empty($results['errors']) ? 'with errors' : 'successfully');

    // Treatment success.
    if (!empty($results['success'])) {
      $node_str = format_plural(count($results['success']['nodes']), '1 node', '@count nodes');
      $endpoint_str = format_plural(count($results['success']['endpoints']), '1 endpoint', '@count endpoints');
      $message .= ' (' . $node_str . ' processed on ' . $endpoint_str . ')';
      $message .= theme('item_list', array(
        'items' => $results['success']['items'],
      ));
      drupal_set_message(filter_xss($message));
    }

    // Errors treatment.
    if (!empty($results['errors'])) {
      $node_str = format_plural(count($results['errors']['nodes']), '1 node error', '@count nodes errors');
      $endpoint_str = format_plural(count($results['errors']['endpoints']), '1 endpoint', '@count endpoints');
      $message .= ' (' . $node_str . ' on ' . $endpoint_str . ')';
      $message .= theme('item_list', array(
        'items' => $results['errors']['items'],
      ));
      drupal_set_message(filter_xss($message), 'error');
    }
  }
  else {

    // A general error occurred (exception, fatal error...)
    // $operations contains the operations that remained unprocessed.
    $error_operation = reset($operations);
    $message = t('An error occurred while processing %error_operation with arguments: @arguments', array(
      '%error_operation' => $error_operation[0],
      '@arguments' => print_r($error_operation[1], TRUE),
    ));
    drupal_set_message(filter_xss($message), 'error');
  }
}