Newer
Older
<?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');
/**
Jim Berry
committed
* Implements hook_install().
*/
function coder_upgrade_install() {
// Create the top-level module directory.
Jim Berry
committed
// Because the core function is now recursive, we could start with the
// subdirectories. However, this code is clean and allows for one else block.
Jim Berry
committed
$dir = coder_upgrade_directory_path('base', FALSE);
Jim Berry
committed
if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
// Create the old and new module directories.
Jim Berry
committed
$dir = coder_upgrade_directory_path('old', FALSE);
Jim Berry
committed
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
Jim Berry
committed
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');
Jim Berry
committed
$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');
Jim Berry
committed
}
// Create the patch directory.
Jim Berry
committed
$dir = coder_upgrade_directory_path('patch', FALSE);
Jim Berry
committed
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
Jim Berry
committed
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 {
Jim Berry
committed
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.
$form_state = array();
coder_upgrade_create_theme_cache_submit(array(), $form_state);
}
/**
Jim Berry
committed
* Implements hook_uninstall().
*/
function coder_upgrade_uninstall() {
// Remove the module input and output directories.
Jim Berry
committed
$dir = coder_upgrade_directory_path('old', FALSE);
coder_upgrade_clean_directory($dir, TRUE);
Jim Berry
committed
$dir = coder_upgrade_directory_path('new', FALSE);
coder_upgrade_clean_directory($dir, TRUE);
Jim Berry
committed
$dir = coder_upgrade_directory_path('patch', FALSE);
Jim Berry
committed
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');
Jim Berry
committed
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');
}
/**
Jim Berry
committed
* 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')) {
Jim Berry
committed
$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
);
}
Jim Berry
committed
$dir = coder_upgrade_directory_path('', FALSE);
Jim Berry
committed
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
Jim Berry
committed
$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 in subdirectories of this directory.', array('%directory' => $dir)),
'severity' => REQUIREMENT_ERROR
);
}
}
else {
Jim Berry
committed
$dir = coder_upgrade_directory_path('new', FALSE);
Jim Berry
committed
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
Jim Berry
committed
$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 {
Jim Berry
committed
$requirements['coder_upgrade_files'] = array(
'title' => $t('Coder Upgrade directory'),
'value' => $t('Writeable (%dir)', array('%dir' => $dir))