You are here

protected function GdprTasksSarWorker::initialise in General Data Protection Regulation 7

Initialise our request.

Parameters

\GDPRTask $task: The task.

1 call to GdprTasksSarWorker::initialise()
GdprTasksSarWorker::processItem in modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php
Process the SARs request.

File

modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php, line 35

Class

GdprTasksSarWorker
Queue worker callback for processing SARs requests.

Code

protected function initialise(\GDPRTask $task) {
  $field_info = field_info_field('gdpr_tasks_sar_export');
  $directory = $field_info['settings']['uri_scheme'] . '://gdpr_sars';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

  // Get a suitable namespace for gathering our files.
  do {

    // Generate a UUID.
    $uuid = ctools_uuid_generate();

    // Check neither the file exists nor the directory.
    if (file_exists("{$directory}/{$uuid}.zip") || file_exists("{$directory}/{$uuid}/")) {
      continue;
    }

    // Generate the zip file to reserve our namespace.
    $file = file_save_data('', "{$directory}/{$uuid}.zip", FILE_EXISTS_ERROR);
  } while (!$file);

  // Prepare the directory for our sub-files.
  $content_directory = "{$directory}/{$uuid}";
  file_prepare_directory($content_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

  // Store the file against the task.
  $task->gdpr_tasks_sar_export[LANGUAGE_NONE][0] = array(
    'fid' => $file->fid,
    'display' => TRUE,
  );
  $task->status = 'building';
  $task
    ->save();

  // Start the build process.
  $this
    ->build($task);
}