mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-24 17:40:43 +01:00
Merge pull request #4677 from marc1706/ticket/15050
[ticket/15050] Use new file when new file already exists
This commit is contained in:
commit
cd4ceb2487
@ -132,42 +132,63 @@ 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) : '';
|
||||
|
||||
$filenames = array(
|
||||
$this->phpbb_root_path . $filename,
|
||||
$new_path . $filename
|
||||
);
|
||||
|
||||
foreach ($filenames as $file_to_diff)
|
||||
if (file_exists($old_path . $filename))
|
||||
{
|
||||
$file_contents[] = file_get_contents($file_to_diff);
|
||||
$file_contents[0] = file_get_contents($old_path . $filename);
|
||||
|
||||
if ($file_contents[sizeof($file_contents) - 1] === false)
|
||||
$filenames = array(
|
||||
$this->phpbb_root_path . $filename,
|
||||
$new_path . $filename
|
||||
);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
$diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]);
|
||||
unset($file_contents);
|
||||
|
||||
// Handle conflicts
|
||||
if ($diff->get_num_conflicts() !== 0)
|
||||
{
|
||||
$merge_conflicts[] = $filename;
|
||||
}
|
||||
|
||||
// Save merged output
|
||||
$this->cache->put(
|
||||
'_file_' . md5($filename),
|
||||
base64_encode(implode("\n", $diff->merged_output()))
|
||||
);
|
||||
|
||||
unset($diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_file_content = file_get_contents($new_path . $filename);
|
||||
|
||||
if ($new_file_content === false)
|
||||
{
|
||||
$this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff));
|
||||
unset($file_contents);
|
||||
unset($new_file_content );
|
||||
throw new user_interaction_required_exception();
|
||||
}
|
||||
|
||||
// Save new file content to cache
|
||||
$this->cache->put(
|
||||
'_file_' . md5($filename),
|
||||
base64_encode($new_file_content)
|
||||
);
|
||||
unset($new_file_content);
|
||||
}
|
||||
|
||||
$diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]);
|
||||
unset($file_contents);
|
||||
|
||||
// Handle conflicts
|
||||
if ($diff->get_num_conflicts() !== 0)
|
||||
{
|
||||
$merge_conflicts[] = $filename;
|
||||
}
|
||||
|
||||
// Save merged output
|
||||
$this->cache->put(
|
||||
'_file_' . md5($filename),
|
||||
base64_encode(implode("\n", $diff->merged_output()))
|
||||
);
|
||||
|
||||
unset($diff);
|
||||
|
||||
$progress_count++;
|
||||
$this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user