diff options
author | Máté Bartus <mate.bartus@gmail.com> | 2017-01-29 14:40:02 +0100 |
---|---|---|
committer | Máté Bartus <mate.bartus@gmail.com> | 2017-01-29 14:40:02 +0100 |
commit | cd4ceb24871783e1d2efe623b8a603ff1a0fff6f (patch) | |
tree | da3a8cdcbe8d9d21b9e187153c51ef02f592e31a /phpBB/phpbb/install/module | |
parent | 3bfeca460175906bf1a73c70e6f15ed58c1927f2 (diff) | |
parent | b5ed02d03c2a28e01e68c9f52fc9044fae2de05c (diff) | |
download | forums-cd4ceb24871783e1d2efe623b8a603ff1a0fff6f.tar forums-cd4ceb24871783e1d2efe623b8a603ff1a0fff6f.tar.gz forums-cd4ceb24871783e1d2efe623b8a603ff1a0fff6f.tar.bz2 forums-cd4ceb24871783e1d2efe623b8a603ff1a0fff6f.tar.xz forums-cd4ceb24871783e1d2efe623b8a603ff1a0fff6f.zip |
Merge pull request #4677 from marc1706/ticket/15050
[ticket/15050] Use new file when new file already exists
Diffstat (limited to 'phpBB/phpbb/install/module')
-rw-r--r-- | phpBB/phpbb/install/module/update_filesystem/task/diff_files.php | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php b/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php index e3e6db6263..1792a3b723 100644 --- a/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php +++ b/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php @@ -132,41 +132,62 @@ class diff_files extends task_base $file_contents = array(); // Handle the special case when user created a file with the filename that is now new in the core - $file_contents[0] = (file_exists($old_path . $filename)) ? file_get_contents($old_path . $filename) : ''; + if (file_exists($old_path . $filename)) + { + $file_contents[0] = file_get_contents($old_path . $filename); - $filenames = array( - $this->phpbb_root_path . $filename, - $new_path . $filename - ); + $filenames = array( + $this->phpbb_root_path . $filename, + $new_path . $filename + ); - foreach ($filenames as $file_to_diff) - { - $file_contents[] = file_get_contents($file_to_diff); + foreach ($filenames as $file_to_diff) + { + $file_contents[] = file_get_contents($file_to_diff); + + if ($file_contents[sizeof($file_contents) - 1] === false) + { + $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff)); + unset($file_contents); + throw new user_interaction_required_exception(); + } + } - if ($file_contents[sizeof($file_contents) - 1] === false) + $diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]); + unset($file_contents); + + // Handle conflicts + if ($diff->get_num_conflicts() !== 0) { - $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff)); - unset($file_contents); - throw new user_interaction_required_exception(); + $merge_conflicts[] = $filename; } - } - $diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]); - unset($file_contents); + // Save merged output + $this->cache->put( + '_file_' . md5($filename), + base64_encode(implode("\n", $diff->merged_output())) + ); - // Handle conflicts - if ($diff->get_num_conflicts() !== 0) - { - $merge_conflicts[] = $filename; + unset($diff); } + else + { + $new_file_content = file_get_contents($new_path . $filename); - // Save merged output - $this->cache->put( - '_file_' . md5($filename), - base64_encode(implode("\n", $diff->merged_output())) - ); + if ($new_file_content === false) + { + $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff)); + unset($new_file_content ); + throw new user_interaction_required_exception(); + } - unset($diff); + // Save new file content to cache + $this->cache->put( + '_file_' . md5($filename), + base64_encode($new_file_content) + ); + unset($new_file_content); + } $progress_count++; $this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count); |