You are here

function gdpr_tasks_install in General Data Protection Regulation 7

Implements hook_schema().

File

modules/gdpr_tasks/gdpr_tasks.install, line 159
Install file for the GDPR Tasks module.

Code

function gdpr_tasks_install() {
  $t = get_t();

  // Add an export field to sar task.
  if (!field_info_field('gdpr_tasks_sar_export')) {
    $field = array(
      'field_name' => 'gdpr_tasks_sar_export',
      'type' => 'file',
      'locked' => TRUE,
      'settings' => array(
        'display_field' => FALSE,
        'uri_scheme' => 'private',
      ),
      'cardinality' => 1,
    );
    field_create_field($field);
  }
  if (!field_info_instance('gdpr_task', 'gdpr_tasks_sar_export', 'gdpr_sar')) {
    $instance = array(
      'label' => $t('Data Export'),
      'field_name' => 'gdpr_tasks_sar_export',
      'entity_type' => 'gdpr_task',
      'bundle' => 'gdpr_sar',
      'required' => FALSE,
      'widget' => array(
        'type' => 'file_generic',
      ),
      'settings' => array(
        'file_display' => 'gdpr-exports',
        'file_extensions' => 'zip',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }

  // Add an export field to sar task.
  if (!field_info_field('gdpr_tasks_sar_export_parts')) {
    $field = array(
      'field_name' => 'gdpr_tasks_sar_export_parts',
      'type' => 'file',
      'locked' => TRUE,
      'settings' => array(
        'display_field' => FALSE,
        'uri_scheme' => 'private',
      ),
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }
  if (!field_info_instance('gdpr_task', 'gdpr_tasks_sar_export_parts', 'gdpr_sar')) {
    $instance = array(
      'label' => $t('Data Export'),
      'field_name' => 'gdpr_tasks_sar_export_parts',
      'entity_type' => 'gdpr_task',
      'bundle' => 'gdpr_sar',
      'required' => FALSE,
      'widget' => array(
        'type' => 'file_generic',
      ),
      'settings' => array(
        'file_display' => 'gdpr-exports',
        'file_extensions' => 'csv',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }

  // Add an export field to sar task.
  if (!field_info_field('gdpr_tasks_sar_export_assets')) {
    $field = array(
      'field_name' => 'gdpr_tasks_sar_export_assets',
      'type' => 'file',
      'locked' => TRUE,
      'settings' => array(
        'display_field' => FALSE,
        'uri_scheme' => 'private',
      ),
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }
  if (!field_info_instance('gdpr_task', 'gdpr_tasks_sar_export_assets', 'gdpr_sar')) {
    $instance = array(
      'label' => $t('Data Export'),
      'field_name' => 'gdpr_tasks_sar_export_assets',
      'entity_type' => 'gdpr_task',
      'bundle' => 'gdpr_sar',
      'required' => FALSE,
      'widget' => array(
        'type' => 'file_generic',
      ),
      'settings' => array(
        'file_display' => 'gdpr-exports',
        'file_extensions' => '',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }

  // Add an manual data override field to sar task.
  if (!field_info_field('gdpr_tasks_manual_data')) {
    $field = array(
      'field_name' => 'gdpr_tasks_manual_data',
      'type' => 'text_long',
      'locked' => TRUE,
      'cardinality' => 1,
    );
    field_create_field($field);
  }
  if (!field_info_instance('gdpr_task', 'gdpr_tasks_manual_data', 'gdpr_sar')) {
    $instance = array(
      'label' => $t('Data Override'),
      'field_name' => 'gdpr_tasks_manual_data',
      'entity_type' => 'gdpr_task',
      'bundle' => 'gdpr_sar',
      'required' => FALSE,
      'widget' => array(
        'type' => 'text_textarea',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }

  // Add an manual data override field to sar task.
  if (!field_info_field('gdpr_tasks_removal_log')) {
    $field = array(
      'field_name' => 'gdpr_tasks_removal_log',
      'type' => 'text_long',
      'locked' => TRUE,
      'cardinality' => 1,
    );
    field_create_field($field);
  }
  if (!field_info_instance('gdpr_task', 'gdpr_tasks_removal_log', 'gdpr_remove')) {
    $instance = array(
      'label' => $t('Removal Log'),
      'field_name' => 'gdpr_tasks_removal_log',
      'entity_type' => 'gdpr_task',
      'bundle' => 'gdpr_remove',
      'required' => FALSE,
      'widget' => array(
        'type' => 'text_textarea',
      ),
      'display' => array(
        'default' => array(
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }

  // Add a notes field to all tasks.
  if (!field_info_field('gdpr_tasks_notes')) {
    $field = array(
      'field_name' => 'gdpr_tasks_notes',
      'type' => 'text_long',
      'locked' => TRUE,
      'cardinality' => 1,
    );
    field_create_field($field);
  }
  foreach (array(
    'gdpr_remove',
    'gdpr_sar',
  ) as $bundle) {
    if (!field_info_instance('gdpr_task', 'gdpr_tasks_notes', $bundle)) {
      $instance = array(
        'label' => $t('Notes'),
        'field_name' => 'gdpr_tasks_notes',
        'entity_type' => 'gdpr_task',
        'bundle' => $bundle,
        'required' => FALSE,
        'widget' => array(
          'type' => 'text_textarea',
        ),
        'display' => array(
          'default' => array(
            'type' => 'hidden',
          ),
        ),
      );
      field_create_instance($instance);
    }
  }

  // Set default email values.
  // @todo Make email content more useful.
  $default_emails = array(
    'task_requested_self' => array(
      'enabled' => FALSE,
      'subject' => $t('Request submitted'),
      'body' => array(
        'value' => $t('A task has been requested.'),
        'format' => NULL,
      ),
    ),
    'task_requested_other' => array(
      'enabled' => FALSE,
    ),
    'task_processed' => array(
      'enabled' => FALSE,
      'subject' => $t('Request complete'),
      'body' => array(
        'value' => $t('Your requested task has been completed.'),
        'format' => NULL,
      ),
    ),
  );
  variable_set('gdpr_tasks_emails', $default_emails);
}