You are here

calendar_systems.install in Calendar Systems 7.2

Contains Calendar Systems installation hooks.

File

calendar_systems.install
View source
<?php

/**
 * @file
 * Contains Calendar Systems installation hooks.
 */

/**
 * @return array
 */
function _calendar_systems_variables() {
  return array(
    'calendar_systems_js_date_picker_core_text_date_fields' => '',
  );
}

/**
 * Implements hook_schema().
 */
function calendar_systems_schema() {
  $schema = array();
  $schema['calendar_systems'] = array(
    'description' => 'Stores calendar systems profiles.',
    'fields' => array(
      'language' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'calendar_system' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'type' => 'text',
        'size' => 'normal',
      ),
    ),
    'primary key' => array(
      'language',
    ),
  );
  return $schema;
}

/**
 * Implements hook_enable().
 */
function calendar_systems_enable() {
  drupal_set_message(t('Calendar systems has been successfully enabled. You might want to <a href="!link">configure its options</a>.', array(
    '!link' => url('admin/config/regional/calendar-systems'),
  )));
}

/**
 * Implements hook_requirements().
 */
function calendar_systems_requirements($phase) {
  require_once dirname(__FILE__) . '/calendar_systems.module';
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();
  if ($phase == 'runtime' || $phase == 'install') {
    $requirements['calendar_systems_patch'] = array(
      'title' => $t('Calendar Systems core patch'),
      'value' => $t('Core patch is not applied, please follow the instructions in <a href="!readme-link">README.txt</a> file.', array(
        '!readme-link' => url(drupal_get_path('module', 'calendar_systems') . '/README.txt', array(
          'language' => (object) array(
            'language' => FALSE,
          ),
        )),
      )),
      'description' => $t('Required core patch for calendar systems to fully work'),
      'severity' => REQUIREMENT_WARNING,
    );
    if (_calendar_systems_is_patch_applied(FALSE) === TRUE) {
      $requirements['calendar_systems_patch']['value'] = $t('Core patch is applied');
      $requirements['calendar_systems_patch']['severity'] = REQUIREMENT_OK;
    }
    elseif (_calendar_systems_is_patch_applied(FALSE) == 'outdated') {
      $requirements['calendar_systems_patch']['value'] = $t('Core patch is applied but it\'s outdated, please follow the instructions in <a href="!readme-link">README.txt</a> file.', array(
        '!readme-link' => url(drupal_get_path('module', 'calendar_systems') . '/README.txt'),
      ));
      $requirements['calendar_systems_patch']['severity'] = REQUIREMENT_ERROR;
    }
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function calendar_systems_install() {
  _calendar_systems_variables_set(_calendar_systems_variables());
}

/**
 * Implements hook_uninstall().
 */
function calendar_systems_uninstall() {
  _calendar_systems_variables_del(_calendar_systems_variables());
}

/**
 * @param $variables
 */
function _calendar_systems_variables_set($variables) {
  foreach ($variables as $key => $val) {
    variable_set($key, $val);
  }
}

/**
 * @param $variables
 */
function _calendar_systems_variables_del($variables) {
  $variables = array_keys($variables);
  foreach ($variables as $variable) {
    variable_del($variable);
  }
}