PDF rausgenommen
This commit is contained in:
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\install\module\update_filesystem\task;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\install\exception\user_interaction_required_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\helper\update_helper;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
/**
|
||||
* Merges user made changes into the files
|
||||
*/
|
||||
class diff_files extends task_base
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* @var update_helper
|
||||
*/
|
||||
protected $update_helper;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param container_factory $container
|
||||
* @param config $config
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param update_helper $update_helper
|
||||
* @param string $phpbb_root_path
|
||||
* @param string $php_ext
|
||||
*/
|
||||
public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->installer_config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->update_helper = $update_helper;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->cache = $container->get('cache.driver');
|
||||
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
$files_to_diff = $this->installer_config->get('update_files', array());
|
||||
$files_to_diff = (isset($files_to_diff['update_with_diff'])) ? $files_to_diff['update_with_diff'] : array();
|
||||
|
||||
return $this->installer_config->get('do_update_files', false) && count($files_to_diff) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Include diff engine
|
||||
$this->update_helper->include_file('includes/diff/diff.' . $this->php_ext);
|
||||
$this->update_helper->include_file('includes/diff/engine.' . $this->php_ext);
|
||||
|
||||
// Set up basic vars
|
||||
$old_path = $this->update_helper->get_path_to_old_update_files();
|
||||
$new_path = $this->update_helper->get_path_to_new_update_files();
|
||||
|
||||
$update_files = $this->installer_config->get('update_files', array());
|
||||
$files_to_diff = $update_files['update_with_diff'];
|
||||
|
||||
// Set progress bar
|
||||
$this->iohandler->set_task_count(count($files_to_diff), true);
|
||||
$this->iohandler->set_progress('UPDATE_FILE_DIFF', 0);
|
||||
$progress_count = $this->installer_config->get('file_diff_update_count', 0);
|
||||
|
||||
// Recover progress
|
||||
$progress_key = $this->installer_config->get('differ_progress_key', -1);
|
||||
$progress_recovered = ($progress_key === -1);
|
||||
$merge_conflicts = $this->installer_config->get('merge_conflict_list', array());
|
||||
|
||||
foreach ($files_to_diff as $key => $filename)
|
||||
{
|
||||
if ($progress_recovered === false)
|
||||
{
|
||||
if ($progress_key === $key)
|
||||
{
|
||||
$progress_recovered = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read in files' content
|
||||
$file_contents = array();
|
||||
|
||||
// Handle the special case when user created a file with the filename that is now new in the core
|
||||
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
|
||||
);
|
||||
|
||||
foreach ($filenames as $file_to_diff)
|
||||
{
|
||||
$file_contents[] = file_get_contents($file_to_diff);
|
||||
|
||||
if ($file_contents[count($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]);
|
||||
|
||||
// Handle conflicts
|
||||
if ($diff->get_num_conflicts() !== 0)
|
||||
{
|
||||
$merge_conflicts[] = $filename;
|
||||
}
|
||||
|
||||
if ($diff->merged_output() !== $file_contents[1])
|
||||
{
|
||||
// Save merged output
|
||||
$this->cache->put(
|
||||
'_file_' . md5($filename),
|
||||
base64_encode(implode("\n", $diff->merged_output()))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($update_files['update_with_diff'][$key]);
|
||||
}
|
||||
|
||||
unset($file_contents);
|
||||
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($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);
|
||||
}
|
||||
|
||||
$progress_count++;
|
||||
$this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count);
|
||||
|
||||
if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
// Save differ progress
|
||||
$this->installer_config->set('differ_progress_key', $key);
|
||||
$this->installer_config->set('merge_conflict_list', $merge_conflicts);
|
||||
$this->installer_config->set('file_diff_update_count', $progress_count);
|
||||
|
||||
foreach ($update_files as $type => $files)
|
||||
{
|
||||
if (empty($files))
|
||||
{
|
||||
unset($update_files[$type]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->installer_config->set('update_files', $update_files);
|
||||
|
||||
// Request refresh
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
}
|
||||
|
||||
$this->iohandler->finish_progress('ALL_FILES_DIFFED');
|
||||
$this->installer_config->set('merge_conflict_list', $merge_conflicts);
|
||||
|
||||
foreach ($update_files as $type => $files)
|
||||
{
|
||||
if (empty($files))
|
||||
{
|
||||
unset($update_files[$type]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->installer_config->set('update_files', $update_files);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\install\module\update_filesystem\task;
|
||||
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\install\exception\jump_to_restart_point_exception;
|
||||
use phpbb\install\exception\user_interaction_required_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
class download_updated_files extends task_base
|
||||
{
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param config $config
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param filesystem $filesystem
|
||||
*/
|
||||
public function __construct(config $config, iohandler_interface $iohandler, filesystem $filesystem)
|
||||
{
|
||||
$this->installer_config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
return $this->installer_config->get('do_update_files', false)
|
||||
&& $this->installer_config->get('file_update_method', '') === 'compression';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->iohandler->get_input('database_update_submit', false))
|
||||
{
|
||||
// Remove archive
|
||||
$this->filesystem->remove(
|
||||
$this->installer_config->get('update_file_archive', null)
|
||||
);
|
||||
|
||||
$this->installer_config->set('update_file_archive', null);
|
||||
}
|
||||
else if ($this->iohandler->get_input('update_recheck_files_submit', false))
|
||||
{
|
||||
$this->installer_config->set('file_updater_elem_progress', '');
|
||||
$this->installer_config->set('update_files', array());
|
||||
throw new jump_to_restart_point_exception('check_update_files');
|
||||
}
|
||||
else
|
||||
{
|
||||
$file_update_info = $this->installer_config->get('update_files', array());
|
||||
|
||||
// Display download box only if the archive won't be empty
|
||||
if (!empty($file_update_info) && !(isset($file_update_info['delete']) && count($file_update_info) == 1))
|
||||
{
|
||||
// Render download box
|
||||
$this->iohandler->add_download_link(
|
||||
'phpbb_installer_update_file_download',
|
||||
'DOWNLOAD_UPDATE_METHOD',
|
||||
'DOWNLOAD_UPDATE_METHOD_EXPLAIN'
|
||||
);
|
||||
}
|
||||
|
||||
// Add form to continue update
|
||||
$this->iohandler->add_user_form_group('UPDATE_CONTINUE_UPDATE_PROCESS', array(
|
||||
'update_recheck_files_submit' => array(
|
||||
'label' => 'UPDATE_RECHECK_UPDATE_FILES',
|
||||
'type' => 'submit',
|
||||
'is_secondary' => empty($file_update_info),
|
||||
),
|
||||
'database_update_submit' => array(
|
||||
'label' => 'UPDATE_CONTINUE_UPDATE_PROCESS',
|
||||
'type' => 'submit',
|
||||
'disabled' => !empty($file_update_info),
|
||||
),
|
||||
));
|
||||
|
||||
throw new user_interaction_required_exception();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\install\module\update_filesystem\task;
|
||||
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\helper\update_helper;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
/**
|
||||
* Updater task performing file checking
|
||||
*/
|
||||
class file_check extends task_base
|
||||
{
|
||||
/**
|
||||
* @var filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var update_helper
|
||||
*/
|
||||
protected $update_helper;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param filesystem $filesystem
|
||||
* @param config $config
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param update_helper $update_helper
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct(filesystem $filesystem, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path)
|
||||
{
|
||||
$this->filesystem = $filesystem;
|
||||
$this->installer_config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->update_helper = $update_helper;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
return $this->installer_config->get('do_update_files', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (!$this->installer_config->has_restart_point('check_update_files'))
|
||||
{
|
||||
$this->installer_config->create_progress_restart_point('check_update_files');
|
||||
}
|
||||
|
||||
$old_path = $this->update_helper->get_path_to_old_update_files();
|
||||
$new_path = $this->update_helper->get_path_to_new_update_files();
|
||||
|
||||
$update_info = $this->installer_config->get('update_info', array());
|
||||
$file_update_info = $this->installer_config->get('update_files', array());
|
||||
|
||||
if (empty($update_info))
|
||||
{
|
||||
$root_path = $this->phpbb_root_path;
|
||||
|
||||
$update_info = $this->installer_config->get('update_info_unprocessed', array());
|
||||
|
||||
$file_update_info = array();
|
||||
$file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
|
||||
|
||||
foreach ($file_update_info['update_without_diff'] as $key => $binary_file)
|
||||
{
|
||||
$new_file = $new_path . $binary_file;
|
||||
$file = $this->phpbb_root_path . $binary_file;
|
||||
|
||||
if (!$this->filesystem->exists($file))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (md5_file($file) === md5_file($new_file))
|
||||
{
|
||||
// File already up to date
|
||||
unset($file_update_info['update_without_diff'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove update without diff info if empty
|
||||
if (count($file_update_info['update_without_diff']) < 1)
|
||||
{
|
||||
unset($file_update_info['update_without_diff']);
|
||||
}
|
||||
|
||||
// Filter out files that are already deleted
|
||||
$file_update_info['delete'] = array_filter(
|
||||
$update_info['deleted'],
|
||||
function ($filename) use ($root_path)
|
||||
{
|
||||
return file_exists($root_path . $filename);
|
||||
}
|
||||
);
|
||||
|
||||
// Remove files to delete list if empty
|
||||
if (count($file_update_info['delete']) < 1)
|
||||
{
|
||||
unset($file_update_info['delete']);
|
||||
}
|
||||
}
|
||||
|
||||
$progress_count = $this->installer_config->get('file_check_progress_count', 0);
|
||||
$task_count = count($update_info['files']);
|
||||
$this->iohandler->set_task_count($task_count);
|
||||
$this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
|
||||
|
||||
// Create list of default extensions that should have been added prior
|
||||
// to this update
|
||||
$default_update_extensions = [];
|
||||
foreach (\phpbb\install\module\update_database\task\update_extensions::$default_extensions_update as $version => $extensions)
|
||||
{
|
||||
if ($this->update_helper->phpbb_version_compare($update_info['version']['from'], $version, '>='))
|
||||
{
|
||||
$default_update_extensions = array_merge($default_update_extensions, $extensions);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($update_info['files'] as $key => $filename)
|
||||
{
|
||||
$old_file = $old_path . $filename;
|
||||
$new_file = $new_path . $filename;
|
||||
$file = $this->phpbb_root_path . $filename;
|
||||
|
||||
if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
// Save progress
|
||||
$this->installer_config->set('update_info', $update_info);
|
||||
$this->installer_config->set('file_check_progress_count', $progress_count);
|
||||
$this->installer_config->set('update_files', $file_update_info);
|
||||
|
||||
// Request refresh
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
|
||||
$progress_count++;
|
||||
$this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
|
||||
|
||||
// Do not copy default extension again if the previous version was
|
||||
// packaged with it but it does not exist (e.g. deleted by admin)
|
||||
if (strpos($file, $this->phpbb_root_path . 'ext/') !== false)
|
||||
{
|
||||
$skip_file = false;
|
||||
foreach ($default_update_extensions as $ext_name)
|
||||
{
|
||||
if (strpos($file, $this->phpbb_root_path . 'ext/' . $ext_name) !== false &&
|
||||
!$this->filesystem->exists($this->phpbb_root_path . 'ext/' . $ext_name . '/composer.json'))
|
||||
{
|
||||
$skip_file = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($skip_file)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->filesystem->exists($file))
|
||||
{
|
||||
$file_update_info['new'][] = $filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
$file_checksum = md5_file($file);
|
||||
|
||||
if ($file_checksum === md5_file($new_file))
|
||||
{
|
||||
// File already up to date
|
||||
continue;
|
||||
}
|
||||
else if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file))
|
||||
{
|
||||
// No need to diff the file
|
||||
$file_update_info['update_without_diff'][] = $filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
$file_update_info['update_with_diff'][] = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
unset($update_info['files'][$key]);
|
||||
}
|
||||
|
||||
$this->installer_config->set('update_files', $file_update_info);
|
||||
$this->installer_config->set('update_info', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\install\module\update_filesystem\task;
|
||||
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\install\exception\user_interaction_required_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\file_updater\factory;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
class show_file_status extends task_base
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\file_updater\compression_file_updater
|
||||
*/
|
||||
protected $file_updater;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param container_factory $container
|
||||
* @param config $config
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param filesystem $filesystem
|
||||
* @param factory $file_updater_factory
|
||||
*/
|
||||
public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, filesystem $filesystem, factory $file_updater_factory)
|
||||
{
|
||||
$this->installer_config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
$this->cache = $container->get('cache.driver');
|
||||
|
||||
// Initialize compression file updater
|
||||
$this->file_updater = $file_updater_factory->get('compression');
|
||||
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
return $this->installer_config->get('do_update_files', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (!$this->iohandler->get_input('submit_continue_file_update', false))
|
||||
{
|
||||
// Handle merge conflicts
|
||||
$merge_conflicts = $this->installer_config->get('merge_conflict_list', array());
|
||||
|
||||
// Create archive for merge conflicts
|
||||
if (!empty($merge_conflicts))
|
||||
{
|
||||
$compression_method = $this->installer_config->get('file_update_compression', '');
|
||||
$conflict_archive = $this->file_updater->init($compression_method);
|
||||
$this->installer_config->set('update_file_conflict_archive', $conflict_archive);
|
||||
|
||||
foreach ($merge_conflicts as $filename)
|
||||
{
|
||||
$this->file_updater->create_new_file(
|
||||
$filename,
|
||||
base64_decode($this->cache->get('_file_' . md5($filename))),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
// Render download box
|
||||
$this->iohandler->add_download_link(
|
||||
'phpbb_installer_update_conflict_download',
|
||||
'DOWNLOAD_CONFLICTS',
|
||||
'DOWNLOAD_CONFLICTS_EXPLAIN'
|
||||
);
|
||||
|
||||
$this->file_updater->close();
|
||||
}
|
||||
|
||||
// Render update file statuses
|
||||
$file_update_info = $this->installer_config->get('update_files', array());
|
||||
$file_status = array(
|
||||
'deleted' => (!isset($file_update_info['delete'])) ? array() : $file_update_info['delete'],
|
||||
'new' => (!isset($file_update_info['new'])) ? array() : $file_update_info['new'],
|
||||
'conflict' => $this->installer_config->get('merge_conflict_list', array()),
|
||||
'modified' => (!isset($file_update_info['update_with_diff'])) ? array() : $file_update_info['update_with_diff'],
|
||||
'not_modified' => (!isset($file_update_info['update_without_diff'])) ? array() : $file_update_info['update_without_diff'],
|
||||
);
|
||||
|
||||
$this->iohandler->render_update_file_status($file_status);
|
||||
|
||||
// Add form to continue update
|
||||
$this->iohandler->add_user_form_group('UPDATE_CONTINUE_FILE_UPDATE', array(
|
||||
'submit_continue_file_update' => array(
|
||||
'label' => 'UPDATE_CONTINUE_FILE_UPDATE',
|
||||
'type' => 'submit',
|
||||
),
|
||||
));
|
||||
|
||||
// Show results to the user
|
||||
throw new user_interaction_required_exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
$conflict_archive_path = $this->installer_config->get('update_file_conflict_archive', null);
|
||||
|
||||
// Remove archive
|
||||
if ($conflict_archive_path !== null && $this->filesystem->exists($conflict_archive_path))
|
||||
{
|
||||
$this->filesystem->remove($conflict_archive_path);
|
||||
}
|
||||
|
||||
$this->installer_config->set('update_file_conflict_archive', null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\install\module\update_filesystem\task;
|
||||
|
||||
use phpbb\exception\runtime_exception;
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\file_updater\factory;
|
||||
use phpbb\install\helper\file_updater\file_updater_interface;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\helper\update_helper;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
/**
|
||||
* File updater task
|
||||
*/
|
||||
class update_files extends task_base
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var factory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* @var file_updater_interface
|
||||
*/
|
||||
protected $file_updater;
|
||||
|
||||
/**
|
||||
* @var update_helper
|
||||
*/
|
||||
protected $update_helper;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param container_factory $container
|
||||
* @param config $config
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param factory $file_updater_factory
|
||||
* @param update_helper $update_helper
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, factory $file_updater_factory, update_helper $update_helper, $phpbb_root_path)
|
||||
{
|
||||
$this->factory = $file_updater_factory;
|
||||
$this->installer_config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->update_helper = $update_helper;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
|
||||
$this->cache = $container->get('cache.driver');
|
||||
$this->file_updater = null;
|
||||
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
return $this->installer_config->get('do_update_files', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$new_path = $this->update_helper->get_path_to_new_update_files();
|
||||
|
||||
$file_update_info = $this->installer_config->get('update_files', array());
|
||||
|
||||
$update_type_progress = $this->installer_config->get('file_updater_type_progress', '');
|
||||
$update_elem_progress = $this->installer_config->get('file_updater_elem_progress', '');
|
||||
$type_progress_found = false;
|
||||
$elem_progress_found = false;
|
||||
|
||||
// Progress bar
|
||||
$task_count = 0;
|
||||
foreach ($file_update_info as $sub_array)
|
||||
{
|
||||
$task_count += count($sub_array);
|
||||
}
|
||||
|
||||
// Everything is up to date, so just continue
|
||||
if ($task_count === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$progress_count = $this->installer_config->get('file_update_progress_count', 0);
|
||||
$this->iohandler->set_task_count($task_count, true);
|
||||
$this->iohandler->set_progress('UPDATE_UPDATING_FILES', 0);
|
||||
|
||||
$this->file_updater = $this->get_file_updater();
|
||||
|
||||
// File updater fallback logic
|
||||
try
|
||||
{
|
||||
// Update files
|
||||
foreach ($file_update_info as $type => $file_update_vector)
|
||||
{
|
||||
if (!$type_progress_found)
|
||||
{
|
||||
if ($type === $update_type_progress || empty($update_elem_progress))
|
||||
{
|
||||
$type_progress_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($file_update_vector as $path)
|
||||
{
|
||||
if (!$elem_progress_found)
|
||||
{
|
||||
if ($path === $update_elem_progress || empty($update_elem_progress))
|
||||
{
|
||||
$elem_progress_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'delete':
|
||||
$this->file_updater->delete_file($path);
|
||||
break;
|
||||
case 'new':
|
||||
$this->file_updater->create_new_file($path, $new_path . $path);
|
||||
break;
|
||||
case 'update_without_diff':
|
||||
$this->file_updater->update_file($path, $new_path . $path);
|
||||
break;
|
||||
case 'update_with_diff':
|
||||
$this->file_updater->update_file(
|
||||
$path,
|
||||
base64_decode($this->cache->get('_file_' . md5($path))),
|
||||
true
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
// Save progress
|
||||
$this->installer_config->set('file_updater_type_progress', $type);
|
||||
$this->installer_config->set('file_updater_elem_progress', $path);
|
||||
$progress_count++;
|
||||
$this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count);
|
||||
|
||||
if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
// Request refresh
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->iohandler->finish_progress('UPDATE_UPDATING_FILES');
|
||||
}
|
||||
catch (runtime_exception $e)
|
||||
{
|
||||
if ($e instanceof resource_limit_reached_exception)
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
|
||||
$current_method = $this->installer_config->get('file_update_method', '');
|
||||
|
||||
// File updater failed, try to fallback to download file update mode
|
||||
if ($current_method !== 'compression')
|
||||
{
|
||||
$this->iohandler->add_warning_message(array(
|
||||
'UPDATE_FILE_UPDATER_HAS_FAILED',
|
||||
$current_method,
|
||||
'compression'
|
||||
));
|
||||
$this->installer_config->set('file_update_method', 'compression');
|
||||
|
||||
// We only want a simple refresh here
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nowhere to fallback to :(
|
||||
// Due to the way the installer handles fatal errors, we need to throw a low level exception
|
||||
throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
$file_updater_method = $this->installer_config->get('file_update_method', '');
|
||||
if ($file_updater_method === 'compression' || $file_updater_method === 'ftp')
|
||||
{
|
||||
$this->file_updater->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file updater
|
||||
*
|
||||
* @param null|string $file_updater_method Name of the file updater to use
|
||||
*
|
||||
* @return file_updater_interface File updater
|
||||
*/
|
||||
protected function get_file_updater($file_updater_method = null)
|
||||
{
|
||||
$file_updater_method = ($file_updater_method === null) ? $this->installer_config->get('file_update_method', '') : $file_updater_method;
|
||||
|
||||
if ($file_updater_method === 'compression')
|
||||
{
|
||||
$compression_method = $this->installer_config->get('file_update_compression', '');
|
||||
|
||||
/** @var \phpbb\install\helper\file_updater\compression_file_updater $file_updater */
|
||||
$file_updater = $this->factory->get('compression');
|
||||
$archive_path = $file_updater->init($compression_method);
|
||||
$this->installer_config->set('update_file_archive', $archive_path);
|
||||
}
|
||||
else if ($file_updater_method === 'ftp')
|
||||
{
|
||||
/** @var \phpbb\install\helper\file_updater\ftp_file_updater $file_updater */
|
||||
$file_updater = $this->factory->get('ftp');
|
||||
$file_updater->init(
|
||||
$this->installer_config->get('ftp_method', ''),
|
||||
$this->installer_config->get('ftp_host', ''),
|
||||
$this->installer_config->get('ftp_user', ''),
|
||||
$this->installer_config->get('ftp_pass', ''),
|
||||
$this->installer_config->get('ftp_path', ''),
|
||||
$this->installer_config->get('ftp_port', 0),
|
||||
$this->installer_config->get('ftp_timeout', 10)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** @var file_updater_interface $file_updater */
|
||||
$file_updater = $this->factory->get('direct_file');
|
||||
}
|
||||
|
||||
return $file_updater;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user