You are here

facebook_tracking_pixel.install in Facebook Tracking Pixel 7

Same filename and directory in other branches
  1. 8 facebook_tracking_pixel.install

Install, update, and uninstall functions for the Facebook Tracking Pixel module.

@author Brady Owens <info@fastglass.net>

File

facebook_tracking_pixel.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Facebook Tracking Pixel
 *   module.
 *
 * @author Brady Owens <info@fastglass.net>
 */

/**
 * Implements hook_schema().
 */
function facebook_tracking_pixel_schema() {
  $schema['facebook_tracking_pixel_events_path'] = [
    'description' => t('Facebook Tracking Pixel Events'),
    'fields' => [
      'event_id' => [
        'description' => 'The event id.',
        'type' => 'serial',
        'not null' => TRUE,
      ],
      'event_uid' => [
        'type' => 'varchar',
        'length' => 200,
        'description' => 'Unique ID number for the tracking item',
        'disp-width' => '25',
      ],
      'event_name' => [
        'type' => 'varchar',
        'length' => 200,
        'description' => 'Human readable name for the item',
        'disp-width' => '10',
      ],
      'event_path' => [
        'description' => 'The event path.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => FALSE,
      ],
      'event_path_system' => [
        'description' => 'The resolved system path.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => FALSE,
      ],
      'event_type' => [
        'description' => 'The event type as a serialized array of types.',
        'type' => 'varchar',
        'length' => 1000,
        'default' => '',
        'not null' => FALSE,
      ],
      'event_js_file' => [
        'description' => 'The file path to the written JS file.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => FALSE,
      ],
      'event_base_code_id' => [
        'description' => 'Base code ID number.',
        'type' => 'int',
        'length' => 11,
        'not null' > FALSE,
      ],
      'event_enable' => [
        'description' => 'If a code is enabled.',
        'type' => 'int',
        'length' => 2,
        'default' => 1,
        'not null' > FALSE,
      ],
      'weight' => [
        'description' => 'The sortable weight for this item',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'event_id',
    ],
  ];
  $schema['facebook_tracking_pixel_base_codes'] = [
    'description' => t('Facebook Tracking Pixel Events'),
    'fields' => [
      'base_code_id' => [
        'description' => 'Base Code ID.',
        'type' => 'serial',
        'not null' => TRUE,
      ],
      'base_code_name' => [
        'description' => 'Base Code Name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ],
      'base_code_fbid' => [
        'description' => 'Base Code ID.',
        'type' => 'varchar',
        'length' => 200,
        'not null' => TRUE,
      ],
      'base_code_global' => [
        'description' => 'If a code is used globally.',
        'type' => 'int',
        'length' => 2,
        'not null' > FALSE,
      ],
      'weight' => [
        'description' => 'The sortable weight for this item.',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'base_code_id',
    ],
  ];
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function facebook_tracking_pixel_uninstall() {
  $path = variable_get('facebook_tracking_pixel_path', 'public://facebook_tracking_pixel');
  file_unmanaged_delete_recursive($path);
  db_drop_table('facebook_tracking_pixel_events_path');
  db_drop_table('facebook_tracking_pixel_base_codes');

  // Delete all variables via an SQL query.
  $prefix = 'facebook_tracking_pixel';
  $result = db_select('variable', 'v')
    ->fields('v')
    ->condition('name', db_like($prefix) . '%', 'LIKE')
    ->execute()
    ->fetchAll();
  foreach ($result as $item) {
    db_delete('variable')
      ->condition('name', $item->name)
      ->execute();
  }
}

/**
 * Implements hook_requirements.
 */
function facebook_requirements($phase) {
  if ($phase === 'install') {
    $t = get_t();

    // Check the version of PHP and set errors if less than 5.4.
    $version = explode('.', PHP_VERSION);
    if ($version[0] == 5 && $version[1] < 4) {
      $requirements['facebook_tracking_pixel_phpversion']['title'] = $t('Incompatible PHP Version');
      $requirements['facebook_tracking_pixel_phpversion']['value'] = $t('The Facebook Tracking Pixel module requires a minimum of PHP 5.4');
      $requirements['facebook_tracking_pixel_phpversion']['severity'] = REQUIREMENT_ERROR;
    }
  }
}

Functions

Namesort descending Description
facebook_requirements Implements hook_requirements.
facebook_tracking_pixel_schema Implements hook_schema().
facebook_tracking_pixel_uninstall Implements hook_uninstall().