You are here

public static function ExportUser::finishedCallback in Open Social 8

Same name and namespace in other branches
  1. 8.2 modules/social_features/social_user_export/src/ExportUser.php \Drupal\social_user_export\ExportUser::finishedCallback()
  2. 8.3 modules/social_features/social_user_export/src/ExportUser.php \Drupal\social_user_export\ExportUser::finishedCallback()
  3. 8.4 modules/social_features/social_user_export/src/ExportUser.php \Drupal\social_user_export\ExportUser::finishedCallback()

Callback when batch is complete.

Parameters

bool $success: Boolean to indicate success of the batch.

array $results: The results.

array $operations: Operations that the batch performed.

File

modules/social_features/social_user_export/src/ExportUser.php, line 159

Class

ExportUser
Class ExportUser.

Namespace

Drupal\social_user_export

Code

public static function finishedCallback($success, array $results, array $operations) {
  if ($success && !empty($results['file_path'])) {
    $data = @file_get_contents($results['file_path']);
    $name = basename($results['file_path']);
    $path = 'private://csv';
    if (file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS) && file_save_data($data, $path . '/' . $name)) {
      $url = Url::fromUri(file_create_url($path . '/' . $name));
      $link = Link::fromTextAndUrl(t('Download file'), $url);
      drupal_set_message(t('Export is complete. @link', [
        '@link' => $link
          ->toString(),
      ]));
    }
    else {
      drupal_set_message(t('When saving the file an error occurred'), 'error');
    }
  }
  else {
    drupal_set_message(t('An error occurred', 'error'));
  }
}