You are here

calendar_systems.install in Calendar Systems 6.2

Implementation of Calendar Systems requirements and un/installation hooks.

File

calendar_systems.install
View source
<?php

/**
 * @file
 * Implementation of Calendar Systems requirements and un/installation hooks.
 */

/**
 * Implements hook_requirements().
 */
function calendar_systems_requirements($phase) {

  // Include patch helpers.
  module_load_include('patch.inc', 'calendar_systems');

  // Return the requirements array.
  return _calendar_systems_patches_requirements();
}

/**
 * Implements hook_install().
 *
 * Introduces all optional and required patch arrays to the patch_manager.module.
 */
function calendar_systems_install() {
  if (module_exists('patch_manager')) {

    // Include patch helpers.
    module_load_include('patch.inc', 'calendar_systems');
    $t = get_t();

    // Introduce module patches to patch_manager.module.
    if (_calendar_systems_patches_pm_insert()) {

      // Set the proper message.
      $message = $t('Calendar Systems patch has been successfully copied to files directory, Also <em>introduced</em> to <a href ="!patch_manager">Patch Manager</a>.', array(
        '!patch_manager' => url('admin/build/patch'),
      ));

      // And notify the user based on environement situation.
      if (_calendar_systems_patches_applied()) {
        drupal_set_message($message . ' ' . $t('Anyway you need not to re-apply the patch.'));
      }
      else {
        drupal_set_message($message . ' ' . $t('But it is <u>not yet applied</u>.'), 'warning');
      }
    }
    else {
      drupal_set_message($t('You have <a href="!patch_manager">Patch Manger</a> installed but we could not copy the Calendar Systems required patches to files directory. Please check permissions and reinstall the module.', array(
        '!patch_manager' => url('admin/build/patch'),
      )), 'warning');
    }
  }
}

/**
 * Implements hook_uninstall().
 *
 * Removes all available calendars settings from the variables table,
 * also deleted all patch_manager.module nodes introduced by the Calendar Systems.
 */
function calendar_systems_uninstall() {

  // Module API is not available at this point. Using
  // db_query() and LIKE is un-encouraged. So, load the API.
  drupal_load('module', 'calendar_systems');

  // Remove all calendars settings.
  $calendars = calendar_systems_calendars();
  foreach ($calendars as $identifer => $info) {
    variable_del('calendar_systems_settings_' . $identifier);
  }

  // Also wipe system's default calendar settings.
  variable_del('calendar_systems_default_calendar');

  // Include patch helpers.
  module_load_include('patch.inc', 'calendar_systems');

  // Say bye to patch_manager.module.
  _calendar_systems_patches_pm_delete();

  // Remind about those patches, if they're still applied.
  if (_calendar_systems_patches_applied()) {
    drupal_set_message(t('Since you just uninstalled the Calendar Systems, you might also want to reverse the applied patch(es).'));
  }
}

/**
 * Implements hook_enable().
 *
 * Checks environments and sets appropriate messages.
 */
function calendar_systems_enable() {

  // Note user that the target files should be writable by the webserver.
  $notice = t('Also notice that you need to make <em>patch target files</em> writable for webserver (0646) or you cannot patch them via the web interface of these modules.');

  // Warn that the module is not usable till the she apply required patches correctly.
  $warning = t('Even though the <a href="!link">Calendar Systems</a> module is now enabled, it is useless till you properly apply all required patches.', array(
    '!link' => url('admin/settings/date-time/calendars'),
  ));

  // Include patch helpers.
  module_load_include('patch.inc', 'calendar_systems');

  // Check if the required patches are applied and set the corresponding message.
  if (_calendar_systems_patches_applied()) {
    drupal_set_message(t('<a href="!link">Calendar Systems</a> is now successfully installed and running.', array(
      '!link' => url('admin/settings/date-time/calendars'),
    )));
  }
  else {
    drupal_set_message($warning, 'warning');
    drupal_set_message($notice, 'warning');
  }
}