You are here

function globallink_settings_export_batch_finished in GlobalLink Connect for Drupal 7.7

Handles Export csv batch process finished.

1 string reference to 'globallink_settings_export_batch_finished'
export_csv_button_submit in ./globallink_settings.inc
Export csv batch set.

File

./globallink_settings.inc, line 962

Code

function globallink_settings_export_batch_finished($success, $results, $operations) {
  if ($success) {
    $publicPath = variable_get('file_public_path', conf_path() . '/files/');
    $rootPath = realpath($publicPath . 'export');
    $folderName = $publicPath . 'export_' . date('m-d-Y_hia') . '.zip';
    $zip = new ZipArchive();
    $zip
      ->open($folderName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY);
    foreach ($files as $name => $file) {
      if (!$file
        ->isDir()) {
        $filePath = $file
          ->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);
        $zip
          ->addFile($filePath, $relativePath);
      }
    }
    $zip
      ->close();
    $download_link = l(t('click here to download the file'), $folderName);
    $output = '<p>' . t('please !download_link.', array(
      '!download_link' => $download_link,
    )) . '</p>';
    drupal_set_message($output);
  }
  else {
    $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($message, 'error');
  }
}