You are here

function coder_upgrade_convert_file in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/includes/main.inc \coder_upgrade_convert_file()

Converts a file.

Parameters

string $oldname: The original name of the file to convert.

string $filename: The new name of the file to convert.

boolean $_coder_upgrade_replace_files: Indicates whether to replace the original files.

1 call to coder_upgrade_convert_file()
coder_upgrade_convert_dir in coder_upgrade/includes/main.inc
Converts files in a directory.

File

coder_upgrade/includes/main.inc, line 273
Manages application of conversion routines, logging, and patch file creation.

Code

function coder_upgrade_convert_file($oldname, $filename, $_coder_upgrade_replace_files = FALSE) {
  if (!file_exists($filename)) {
    return FALSE;
  }

  // Read the file and copy the contents.
  $cur = file_get_contents($filename);
  $new = $cur;

  // Apply regular expression routines.
  coder_upgrade_apply_regex($filename, $new);

  // Apply parser routines.
  coder_upgrade_apply_parser($filename, $new);

  // Write the new file.
  if ($new != $cur) {
    $filename = $_coder_upgrade_replace_files ? $oldname : $filename;
    if (file_put_contents($filename, $new) === FALSE) {
      coder_upgrade_log_print('File could not be written');
    }
    coder_upgrade_log_print('Replaced the file');
  }
}