You are here

background_process.install in Background Process 8

This is the installation file for the Background Process module.

File

background_process.install
View source
<?php

/**
 * @file
 * This is the installation file for the Background Process module.
 */

/**
 * Implements of hook enable.
 */
function background_process_enable() {
  $_SESSION['background_process_determine_default_service_host'] = TRUE;
}

/**
 * Implements of hook schema.
 */
function background_process_schema() {
  $schema = [];
  $schema['background_process'] = [
    'fields' => [
      'handle' => [
        'type' => 'varchar_ascii',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'callback' => [
        'type' => 'text',
        'not null' => FALSE,
      ],
      'args' => [
        'type' => 'blob',
        'size' => 'big',
        'not null' => FALSE,
      ],
      'uid' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'token' => [
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ],
      'service_host' => [
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ],
      'start_stamp' => [
        'type' => 'varchar',
        'length' => '18',
        'not null' => FALSE,
      ],
      'exec_status' => [
        'type' => 'int',
        'size' => 'normal',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'handle',
    ],
  ];
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function background_process_uninstall() {

  // Removing process variables.
  $config = \Drupal::getContainer()
    ->get('config.factory')
    ->getEditable('background_process.settings');
  $config
    ->delete();
}

/**
 * Implements hook_requirements().
 */
function background_process_requirements($phase) {
  $response = [];
  $t = 't';
  switch ($phase) {
    case 'install':
      return $response;
    case 'runtime':
      $response['title'] = 'Background Process';
      $response['value'] = $t('OK');
      $response['severity'] = REQUIREMENT_OK;
      if (ini_get('safe_mode')) {
        $desc = $t('Safe mode enabled. Background Process is unable to control maximum execution time for background processes. This may cause background processes to end prematurely.');
        if ($response['severity'] < REQUIREMENT_WARNING) {
          $response['severity'] = REQUIREMENT_WARNING;
          $response['value'] = $t('Safe mode enabled');
          $response['description'] = $desc;
        }
        else {
          $response['description'] .= '<br/>' . $desc;
        }
      }
      $result = [];
      $result['background_process'] = $response;
      return $result;
  }
}

/**
 * Add status column to background_process table.
 */
function background_process_update_7101() {
  if (!db_field_exists('background_process', 'status')) {
    db_add_field('background_process', 'status', [
      'type' => 'int',
      'size' => 'normal',
      'not null' => TRUE,
      'default' => 0,
    ]);
  }
}

/**
 * Implements to Change start column from double to numeric.
 */
function background_process_update_7104() {
  if (db_field_exists('background_process', 'start')) {
    db_change_field('background_process', 'start', 'start', [
      'type' => 'numeric',
      'precision' => '16',
      'scale' => '6',
      'not null' => FALSE,
    ]);
  }
}

/**
 * Implements to Re-determine default service host.
 */
function background_process_update_7105() {
  $_SESSION['background_process_determine_default_service_host'] = TRUE;
}

/**
 * Implements to Change schema to SQL 99 compliance.
 */
function background_process_update_7106() {
  if (db_field_exists('background_process', 'start')) {
    db_change_field('background_process', 'start', 'start_stamp', [
      'type' => 'varchar',
      'length' => '18',
      'not null' => FALSE,
    ]);
  }
  if (db_field_exists('background_process', 'status')) {
    db_change_field('background_process', 'status', 'exec_status', [
      'type' => 'int',
      'size' => 'normal',
      'not null' => TRUE,
      'default' => 0,
    ]);
  }
}

/**
 * Implements to Increase size of args column.
 */
function background_process_update_7107() {
  if (db_field_exists('background_process', 'args')) {
    db_change_field('background_process', 'args', 'args', [
      'type' => 'blob',
      'size' => 'big',
      'not null' => FALSE,
    ]);
  }
}

Functions

Namesort descending Description
background_process_enable Implements of hook enable.
background_process_requirements Implements hook_requirements().
background_process_schema Implements of hook schema.
background_process_uninstall Implements hook_uninstall().
background_process_update_7101 Add status column to background_process table.
background_process_update_7104 Implements to Change start column from double to numeric.
background_process_update_7105 Implements to Re-determine default service host.
background_process_update_7106 Implements to Change schema to SQL 99 compliance.
background_process_update_7107 Implements to Increase size of args column.