You are here

function gathercontent_update_finished in GatherContent 7.3

Same name and namespace in other branches
  1. 8.3 gathercontent.module \gathercontent_update_finished()
  2. 8.4 gathercontent.module \gathercontent_update_finished()

Finished callback.

@inheritdoc

1 string reference to 'gathercontent_update_finished'
gathercontent_views_vbo_update in ./gathercontent.module
Submit callback for `views_bulk_operations_confirm_form`.

File

./gathercontent.module, line 1248

Code

function gathercontent_update_finished($success, $results, $operations) {
  if ($success) {

    // Select all items with uuid.
    $query = new EntityFieldQuery();
    $result = $query
      ->entityCondition('entity_type', 'gathercontent_operation_item')
      ->propertyCondition('operation_uuid', $results['uuid'])
      ->execute();
    if (isset($result['gathercontent_operation_item'])) {
      $operation_items = entity_load('gathercontent_operation_item', array_keys($result['gathercontent_operation_item']));
      $success_counter = 0;
      $nids = array(
        'success' => array(),
        'failed' => array(),
      );
      foreach ($operation_items as $operation_item) {
        if ($operation_item->status === 'Success') {
          $success_counter++;
          $nids['success'][] = array(
            'nid' => $operation_item->nid,
            'gathercontent_id' => $operation_item->gathercontent_id,
          );
        }
        else {
          $nids['failed'][] = array(
            'nid' => $operation_item->nid,
            'gathercontent_id' => $operation_item->gathercontent_id,
          );
        }
      }
      $unsuccessful = count($result['gathercontent_operation_item']) - $success_counter;
      drupal_set_message(format_plural($success_counter, '1 item was updated successfully.', '@count items were updated successfully.'));
      if ($unsuccessful > 0) {
        drupal_set_message(format_plural($unsuccessful, '1 item was not updated. Check errors below.', '@count items were not updated. Check errors below.'), 'error');
      }
      module_invoke_all('gathercontent_post_import', $nids['success'], $nids['failed'], $results['uuid']);
    }
    drupal_goto('admin/content/update/result/' . $results['uuid']);
  }
  else {
    $error_operation = reset($operations);
    drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array(
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    )), 'error');
  }
}