You are here

fillpdf.install in FillPDF 7.2

Install

File

fillpdf.install
View source
<?php

/**
 * @file
 * Install
 */

/**
 * Implements hook_schema().
 */
function fillpdf_schema() {
  $schema = array();
  $schema['fillpdf_forms'] = array(
    'fields' => array(
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 512,
        'not null' => TRUE,
      ),
      'default_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'url' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'destination_path' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'replacements' => array(
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
      'destination_redirect' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'admin_title' => array(
        'type' => 'varchar',
        'length' => 512,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'fid',
    ),
  );
  $schema['fillpdf_fields'] = array(
    'fields' => array(
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'pdf_key' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'prefix' => array(
        'type' => 'varchar',
        'length' => 4096,
        'not null' => FALSE,
      ),
      'value' => array(
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE,
      ),
      'suffix' => array(
        'type' => 'varchar',
        'length' => 4096,
        'not null' => FALSE,
      ),
      'replacements' => array(
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'fid',
      'pdf_key',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function fillpdf_install() {
  _fillpdf_add_publish_completed_orders_permission();
}
function _fillpdf_add_publish_completed_orders_permission() {

  // Allow anyone to fill Completed orders by default, subject to having other
  // required permissions such as view own orders. Only do this once, ever.
  if (module_exists('uc_order') && module_exists('user') && !variable_get('fillpdf_uc_order_initialized', FALSE)) {
    $order_statuses = uc_order_status_list();
    $completed_status = NULL;
    foreach ($order_statuses as $order_status) {
      if ($order_status['id'] == 'completed') {
        $completed_status = $order_status['id'];
      }
    }
    if ($completed_status) {
      $roles = user_roles();
      foreach ($roles as $rid => $title) {
        user_role_grant_permissions($rid, array(
          "publish {$completed_status} order data",
        ));
      }
      variable_set('fillpdf_uc_order_initialized', TRUE);
      $fillpdf_permissions = fillpdf_permission();
      drupal_set_message("FillPDF has automatically given all the roles the {$fillpdf_permissions[<span class="php-string">"publish {$completed_status} order data"</span>][<span class="php-string">'title'</span>]} permission. You can disable this from the Permissions page. This is the only time FillPDF will do this automatically.");
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function fillpdf_uninstall() {
  variable_del('fillpdf_uc_order_initialized');
}

/**
 * Implements hook_update_N().
 */

/**
 * Add field to store destination path for saving PDFs as files.
 */
function fillpdf_update_7001() {
  if (!db_field_exists('fillpdf_forms', 'destination_path')) {
    db_add_field('fillpdf_forms', 'destination_path', array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => FALSE,
    ));
  }
}

/**
 * Add fields to store token replacements.
 */
function fillpdf_update_7002() {
  if (!db_field_exists('fillpdf_forms', 'replacements')) {
    db_add_field('fillpdf_forms', 'replacements', array(
      'type' => 'text',
      'size' => 'normal',
      'not null' => FALSE,
    ));
  }
  if (!db_field_exists('fillpdf_fields', 'replacements')) {
    db_add_field('fillpdf_fields', 'replacements', array(
      'type' => 'text',
      'size' => 'normal',
      'not null' => FALSE,
    ));
  }
}

/**
 * Convert legacy configuration variables to new fillpdf_service variable and delete.
 */
function fillpdf_update_7003() {
  $default = FALSE;
  global $conf;
  foreach (array(
    'fillpdf_remote_service',
    'fillpdf_local_service',
    'fillpdf_local_php',
  ) as $variable_name) {
    if (isset($conf[$variable_name])) {
      if ($conf[$variable_name]) {
        $default = $variable_name;
      }
      variable_del($variable_name);
    }
  }
  if ($default) {
    $variable_name_map = array(
      'fillpdf_local_php' => 'pdftk',
      'fillpdf_local_service' => 'local',
      'fillpdf_remote_service' => 'remote',
    );
    variable_set('fillpdf_service', $variable_name_map[$default]);
  }
}

/**
 * Add field to store default NID.
 */
function fillpdf_update_7004() {
  if (!db_field_exists('fillpdf_forms', 'default_nid')) {
    db_add_field('fillpdf_forms', 'default_nid', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => FALSE,
    ));
  }
}

/**
 * Add database field to hold "Redirect to saved file" setting.
 */
function fillpdf_update_7005() {
  if (!db_field_exists('fillpdf_forms', 'destination_redirect')) {
    db_add_field('fillpdf_forms', 'destination_redirect', array(
      'type' => 'int',
      'size' => 'tiny',
      'unsigned' => TRUE,
      'not null' => FALSE,
    ));
  }
}

/**
 * Add database fields for prefix and suffix.
 */
function fillpdf_update_7006() {
  $schema = drupal_get_schema_unprocessed('fillpdf', 'fillpdf_fields');
  if (!db_field_exists('fillpdf_fields', 'prefix')) {
    db_add_field('fillpdf_fields', 'prefix', $schema['fields']['prefix']);
  }
  if (!db_field_exists('fillpdf_fields', 'suffix')) {
    db_add_field('fillpdf_fields', 'suffix', $schema['fields']['suffix']);
  }
}

/**
 * Add administrative title; make title longer.
 */
function fillpdf_update_7101() {
  $schema = drupal_get_schema_unprocessed('fillpdf', 'fillpdf_forms');
  if (!db_field_exists('fillpdf_forms', 'admin_title')) {
    db_add_field('fillpdf_forms', 'admin_title', $schema['fields']['admin_title']);
  }
  db_change_field('fillpdf_forms', 'title', 'title', $schema['fields']['title']);
}

/**
 * Let all roles use completed order data to fill PDFs by default,
 * assuming they otherwise are allowed.
 */
function fillpdf_update_7201() {
  _fillpdf_add_publish_completed_orders_permission();
}

Functions

Namesort descending Description
fillpdf_install Implements hook_install().
fillpdf_schema Implements hook_schema().
fillpdf_uninstall Implements hook_uninstall().
fillpdf_update_7001 Add field to store destination path for saving PDFs as files.
fillpdf_update_7002 Add fields to store token replacements.
fillpdf_update_7003 Convert legacy configuration variables to new fillpdf_service variable and delete.
fillpdf_update_7004 Add field to store default NID.
fillpdf_update_7005 Add database field to hold "Redirect to saved file" setting.
fillpdf_update_7006 Add database fields for prefix and suffix.
fillpdf_update_7101 Add administrative title; make title longer.
fillpdf_update_7201 Let all roles use completed order data to fill PDFs by default, assuming they otherwise are allowed.
_fillpdf_add_publish_completed_orders_permission