forked from backdrop-contrib/coder_upgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coder_upgrade.install
102 lines (94 loc) · 4.19 KB
/
coder_upgrade.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?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)) {
backdrop_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)) {
backdrop_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)) {
backdrop_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 {
backdrop_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);
}
/**
* 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;
}