function coder_upgrade_convert_dir in Coder 7.2
Same name and namespace in other branches
- 7 coder_upgrade/includes/main.inc \coder_upgrade_convert_dir()
Converts files in a directory.
Parameters
array $upgrades: Array of upgrade sets to apply.
array $extensions: Array of file types to convert based on extension.
array $item: Array of a directory containing the files to convert.
boolean $recursive: Indicates whether to recurse the subdirectories of $item.
1 call to coder_upgrade_convert_dir()
- coder_upgrade_start in coder_upgrade/
includes/ main.inc - Prepares conversion environment and starts conversion loop.
File
- coder_upgrade/
includes/ main.inc, line 188 - Manages application of conversion routines, logging, and patch file creation.
Code
function coder_upgrade_convert_dir($upgrades, $extensions, $item, $recursive = TRUE) {
global $_coder_upgrade_filename;
// Not used by this module, but other modules may find it useful.
static $ignore = array(
/*'.', '..', '.bzr', '.git', '.svn',*/
'CVS',
);
global $_coder_upgrade_module_name, $_coder_upgrade_replace_files;
$dirname = $item['old_dir'];
$new_dirname = $item['new_dir'];
// Create an output directory we can write to.
if (!is_dir($new_dirname)) {
mkdir($new_dirname);
chmod($new_dirname, 0757);
}
else {
coder_upgrade_clean_directory($new_dirname);
}
if (!in_array($dirname, $ignore)) {
coder_upgrade_log_print("\n*************************");
coder_upgrade_log_print('Converting the directory => ' . $dirname);
coder_upgrade_log_print("*************************");
}
// Determine module name.
coder_upgrade_module_name($dirname, $item);
$_coder_upgrade_module_name = $item['module'] ? $item['module'] : $_coder_upgrade_module_name;
// Loop on files.
$filenames = scandir($dirname . '/');
foreach ($filenames as $filename) {
$_coder_upgrade_filename = $dirname . '/' . $filename;
if (is_dir($dirname . '/' . $filename)) {
if (substr(basename($filename), 0, 1) == '.' || in_array(basename($filename), $ignore)) {
// Ignore all hidden directories and CVS directory.
continue;
}
$new_filename = $filename;
// Handle D6 conversion item #79.
if ($filename == 'po') {
$new_filename = 'translations';
}
if ($recursive) {
// TODO Fix this!!!
$new_item = array(
'name' => $item['name'],
'old_dir' => $dirname . '/' . $filename,
'new_dir' => $new_dirname . '/' . $filename,
);
coder_upgrade_convert_dir($upgrades, $extensions, $new_item, $recursive);
// Reset the module name.
$_coder_upgrade_module_name = $item['module'];
}
}
elseif (in_array($extension = pathinfo($filename, PATHINFO_EXTENSION), array_keys($extensions))) {
copy($dirname . '/' . $filename, $new_dirname . '/' . $filename);
if ($extension == 'php' && substr($filename, -8) == '.tpl.php') {
// Exclude template files.
continue;
}
coder_upgrade_log_print("\n*************************");
coder_upgrade_log_print('Converting the file => ' . $filename);
coder_upgrade_log_print("*************************");
coder_upgrade_convert_file($dirname . '/' . $filename, $new_dirname . '/' . $filename, $_coder_upgrade_replace_files);
}
elseif (in_array($extension, array(
'inc',
'install',
'module',
'php',
'profile',
'test',
'theme',
'upgrade',
))) {
copy($dirname . '/' . $filename, $new_dirname . '/' . $filename);
// Check for a class declaration for use in the info file.
coder_upgrade_class_check($new_dirname . '/' . $filename);
}
else {
copy($dirname . '/' . $filename, $new_dirname . '/' . $filename);
}
}
}