You are here

coder_upgrade.install in Coder 7.2

Same filename and directory in other branches
  1. 7 coder_upgrade/coder_upgrade.install

File

coder_upgrade/coder_upgrade.install
View source
<?php

/**
 * @file
 * Install, uninstall, and update functions for the Coder Upgrade module.
 *
 * Copyright 2008-11 by Jim Berry ("solotandem", http://drupal.org/user/240748)
 */
module_load_include('inc', 'coder_upgrade', 'coder_upgrade');

/**
 * Implements hook_install().
 */
function coder_upgrade_install() {

  // Create the top-level module directory.
  // Because the core function is now recursive, we could start with the
  // subdirectories. However, this code is clean and allows for one else block.
  $dir = coder_upgrade_directory_path('base', FALSE);
  if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {

    // Create the old module directory.
    $dir = coder_upgrade_directory_path('old', FALSE);
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
      drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory searched by Coder Upgrade for modules to be converted.', array(
        '%directory' => $dir,
      )), 'error');
    }

    // Create the new module directory.
    $dir = coder_upgrade_directory_path('new', FALSE);
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
      drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory to which Coder Upgrade writes converted module code.', array(
        '%directory' => $dir,
      )), 'error');
    }

    // Create the patch directory.
    $dir = coder_upgrade_directory_path('patch', FALSE);
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
      drupal_set_message(st('The files directory at %directory can not be written to. This is the default directory to which Coder Upgrade writes patch files.', array(
        '%directory' => $dir,
      )), 'error');
    }
  }
  else {
    drupal_set_message(st('Your files directory at %directory can not be written to. Coder Upgrade places converted module code in subdirectories of this directory.', array(
      '%directory' => $dir,
    )), 'error');
  }

  // Create a core theme information cache.
  module_load_include('inc', 'coder_upgrade', 'includes/settings');
  $form_state = array();
  coder_upgrade_create_theme_cache_submit(array(), $form_state);
}

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

  // Remove the module input and output directories.
  $dir = coder_upgrade_directory_path('base', FALSE);
  coder_upgrade_clean_directory($dir, TRUE);

  // Remove items from {variables} table.
  variable_del('coder_upgrade_dir');
  variable_del('coder_upgrade_dir_old');
  variable_del('coder_upgrade_dir_new');
  variable_del('coder_upgrade_dir_patch');
  variable_del('coder_upgrade_upgrade_core');
  variable_del('coder_upgrade_replace_files');
  variable_del('coder_upgrade_preserve_array_format');
  variable_del('coder_upgrade_enable_debug_output');
  variable_del('coder_upgrade_enable_parser_debug_output');
  variable_del('coder_upgrade_use_separate_process');
}

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

  // Ensure translations don't break at install time.
  $t = get_t();
  $requirements = array();

  // Test writeability to files directory.
  if ($phase == 'install') {
    if (module_exists('deadwood')) {
      $requirements['coder_upgrade_modules'] = array(
        'title' => $t('Deadwood module'),
        'description' => $t('The Deadwood module must be uninstalled before the Coder Upgrade module can be installed.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    $dir = coder_upgrade_directory_path('', FALSE);
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
      $requirements['coder_upgrade_files'] = array(
        'title' => $t('Files directory'),
        'description' => $t('Your files directory at %directory can not be written to. Coder Upgrade places converted module code and other files in subdirectories of this directory.', array(
          '%directory' => $dir,
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  else {

    // @todo Check all of the subdirectories.
    $dir = coder_upgrade_directory_path('new', FALSE);
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
      $requirements['coder_upgrade_files'] = array(
        'title' => $t('Coder Upgrade directory'),
        'description' => $t('Your files directory at %directory can not be written to. Coder Upgrade places converted module code in subdirectories of this directory.', array(
          '%directory' => $dir,
        )),
        'severity' => REQUIREMENT_ERROR,
        'value' => $t('Not writeable (%dir)', array(
          '%dir' => $dir,
        )),
      );
    }
    else {
      $requirements['coder_upgrade_files'] = array(
        'title' => $t('Coder Upgrade directory'),
        'value' => $t('Writeable (%dir)', array(
          '%dir' => $dir,
        )),
      );
    }
  }
  return $requirements;
}