protected function rewrite_step_backup_file_for_legacy_freeze($filepath) {
        $foundnode = false;
        $newfile = make_request_directory(true) . DIRECTORY_SEPARATOR . 'file.xml';
        $fr = fopen($filepath, 'r');
        $fw = fopen($newfile, 'w');
        if ($fr && $fw) {
            while (($line = fgets($fr, 4096)) !== false) {
                if (!$foundnode && strpos($line, '<gradebook ') === 0) {
                    $foundnode = true;
                    $matches = array();
                    $pattern = '@calculations_freeze=.([0-9]+).@';
                    if (preg_match($pattern, $line, $matches)) {
                        $freeze = $matches[1];
                        $line = preg_replace($pattern, '', $line);
                        $line .= "  <attributes>\n    <calculations_freeze>$freeze</calculations_freeze>\n  </attributes>\n";
                    }
                }
                fputs($fw, $line);
            }
            if (!feof($fr)) {
                throw new restore_step_exception('Error while attempting to rewrite the gradebook step file.');
            }
            fclose($fr);
            fclose($fw);
            if (!rename($newfile, $filepath)) {
                throw new restore_step_exception('Error while attempting to rename the gradebook step file.');
            }
        } else {
            if ($fr) {
                fclose($fr);
            }
            if ($fw) {
                fclose($fw);
            }
        }
    }