1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-25 17:41:25 +02:00

[ticket/14039] Revamp updater

PHPBB3-14039
This commit is contained in:
Mate Bartus
2015-07-24 09:20:50 +02:00
parent f1047ac854
commit 8f5a0ad6f7
94 changed files with 4514 additions and 263 deletions

View File

@@ -99,6 +99,8 @@ class config
'last_task_name' => '', // Stores the service name of the latest finished task
'max_task_progress' => 0,
'current_task_progress' => 0,
'_restart_points' => array(),
'use_restart_point' => false,
);
$this->install_config_file = $this->phpbb_root_path . 'store/install_config.php';
@@ -239,6 +241,56 @@ class config
}
}
/**
* Creates a progress restart point
*
* Restart points can be used to repeat certain tasks periodically.
* You need to call this method from the first task you want to repeat.
*
* @param string $name Name of the restart point
*/
public function create_progress_restart_point($name)
{
$tmp_progress_data = $this->progress_data;
unset($tmp_progress_data['_restart_points']);
$this->progress_data['_restart_points'][$name] = $tmp_progress_data;
}
/**
* Set restart point to continue from
*
* @param string $name Name of the restart point
*
* @return bool Returns false if the restart point name is not exist, true otherwise
*/
public function jump_to_restart_point($name)
{
if (!isset($this->progress_data['_restart_points'][$name]) || empty($this->progress_data['_restart_points'][$name]))
{
return false;
}
foreach ($this->progress_data['_restart_points'][$name] as $key => $value)
{
$this->progress_data[$key] = $value;
}
return true;
}
/**
* Returns whether a restart point with a given name exists or not
*
* @param string $name Name of the restart point
*
* @return bool
*/
public function has_restart_point($name)
{
return isset($this->progress_data['_restart_points'][$name]);
}
/**
* Dumps install configuration to disk
*/

View File

@@ -134,8 +134,13 @@ class container_factory
$this->request->enable_super_globals();
}
$this->container = $phpbb_container = $phpbb_container_builder
$other_config_path = $this->phpbb_root_path . 'install/update/new/config';
$config_path = (is_dir($other_config_path)) ? $other_config_path : $this->phpbb_root_path . 'config';
$this->container = $phpbb_container_builder
->with_environment('production')
->with_config($phpbb_config_php_file)
->with_config_path($config_path)
->without_cache()
->without_compiled_container()
->get_container();
@@ -145,11 +150,17 @@ class container_factory
$this->container->register('request')->setSynthetic(true);
$this->container->set('request', $this->request);
// Replace cache service, as config gets cached, and we don't want that
$this->container->register('cache.driver')->setSynthetic(true);
$this->container->set('cache.driver', new dummy());
// Replace cache service, as config gets cached, and we don't want that when we are installing
if (!is_dir($other_config_path))
{
$this->container->register('cache.driver')->setSynthetic(true);
$this->container->set('cache.driver', new dummy());
}
$this->container->compile();
$phpbb_container = $this->container;
// Restore super globals to previous state
if ($disable_super_globals)
{

View File

@@ -338,7 +338,7 @@ class database
$db->sql_return_on_error(true);
// Check that we actually have a database name before going any further
if (!in_array($dbms_info['SCHEMA'], array('sqlite', 'oracle')) && $dbname === '')
if (!in_array($dbms_info['SCHEMA'], array('sqlite', 'oracle'), true) && $dbname === '')
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_NAME',

View File

@@ -0,0 +1,131 @@
<?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\helper\file_updater;
use phpbb\install\helper\update_helper;
/**
* File updater for generating archive with updated files
*/
class compression_file_updater implements file_updater_interface
{
/**
* @var \compress
*/
protected $compress;
/**
* @var update_helper
*/
protected $update_helper;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param update_helper $update_helper
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(update_helper $update_helper, $phpbb_root_path, $php_ext)
{
$this->compress = null;
$this->update_helper = $update_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Set the compression method
*
* @param string $method Compression method's file extension
*
* @return string Archive's filename
*/
public function init($method)
{
$this->update_helper->include_file('includes/functions_compress.' . $this->php_ext);
$archive_filename = 'update_archive_' . time() . '_' . uniqid();
$path = $this->phpbb_root_path . 'store/' . $archive_filename . '' . $method;
if ($method === '.zip')
{
$this->compress = new \compress_zip('w', $path);
}
else
{
$this->compress = new \compress_tar('w', $path, $method);
}
return $path;
}
/**
* Close archive writing process
*/
public function close()
{
$this->compress->close();
}
/**
* {@inheritdoc}
*/
public function delete_file($path_to_file)
{
// We do absolutely nothing here
}
/**
* {@inheritdoc}
*/
public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
{
if ($create_from_content)
{
$this->compress->add_data($source, $path_to_file_to_create);
}
else
{
$this->compress->add_custom_file($source, $path_to_file_to_create);
}
}
/**
* {@inheritdoc}
*/
public function update_file($path_to_file_to_update, $source, $create_from_content = false)
{
// Both functions are identical here
$this->create_new_file($path_to_file_to_update, $source, $create_from_content);
}
/**
* {@inheritdoc}
*/
public function get_method_name()
{
return 'compression';
}
}

View File

@@ -0,0 +1,69 @@
<?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\helper\file_updater;
use phpbb\di\service_collection;
use phpbb\install\exception\file_updater_failure_exception;
/**
* File updater factory
*/
class factory
{
/**
* @var array
*/
protected $file_updaters;
/**
* Constructor
*
* @param service_collection $collection File updater service collection
*/
public function __construct(service_collection $collection)
{
foreach ($collection as $service)
{
$this->register($service);
}
}
/**
* Register updater object
*
* @param file_updater_interface $updater Updater object
*/
public function register(file_updater_interface $updater)
{
$name = $updater->get_method_name();
$this->file_updaters[$name] = $updater;
}
/**
* Returns file updater object
*
* @param string $name Name of the updater method
*
* @throws file_updater_failure_exception When the specified file updater does not exist
*/
public function get($name)
{
if (!isset($this->file_updaters[$name]))
{
throw new file_updater_failure_exception();
}
return $this->file_updaters[$name];
}
}

View File

@@ -0,0 +1,210 @@
<?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\helper\file_updater;
use phpbb\filesystem\exception\filesystem_exception;
use phpbb\filesystem\filesystem;
use phpbb\install\exception\file_updater_failure_exception;
/**
* File updater for direct filesystem access
*/
class file_updater implements file_updater_interface
{
/**
* @var filesystem
*/
protected $filesystem;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* Constructor
*
* @param filesystem $filesystem
* @param string $phpbb_root_path
*/
public function __construct(filesystem $filesystem, $phpbb_root_path)
{
$this->filesystem = $filesystem;
$this->phpbb_root_path = $phpbb_root_path;
}
/**
* {@inheritdoc}
*
* @throws file_updater_failure_exception When the file is not writable
* @throws filesystem_exception When the filesystem class fails
*/
public function delete_file($path_to_file)
{
$this->filesystem->remove($this->phpbb_root_path . $path_to_file);
}
/**
* {@inheritdoc}
*
* @throws file_updater_failure_exception When the file is not writable
* @throws filesystem_exception When the filesystem class fails
*/
public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
{
$path_to_file_to_create = $this->phpbb_root_path . $path_to_file_to_create;
$dir = dirname($path_to_file_to_create);
if (!$this->filesystem->exists($dir))
{
$this->make_dir($dir);
}
$original_dir_perms = false;
if (!$this->filesystem->is_writable($dir))
{
// Extract last 9 bits we actually need
$original_dir_perms = @fileperms($dir) & 511;
$this->filesystem->phpbb_chmod($dir, filesystem::CHMOD_ALL);
}
if (!$create_from_content)
{
try
{
$this->filesystem->copy($source, $path_to_file_to_create);
}
catch (filesystem_exception $e)
{
$this->write_file($path_to_file_to_create, $source, $create_from_content);
}
}
else
{
$this->write_file($path_to_file_to_create, $source, $create_from_content);
}
if ($original_dir_perms !== false)
{
$this->filesystem->phpbb_chmod($dir, $original_dir_perms);
}
}
/**
* {@inheritdoc}
*
* @throws file_updater_failure_exception When the file is not writable
* @throws filesystem_exception When the filesystem class fails
*/
public function update_file($path_to_file_to_update, $source, $create_from_content = false)
{
$path_to_file_to_update = $this->phpbb_root_path . $path_to_file_to_update;
$original_file_perms = false;
if (!$this->filesystem->is_writable($path_to_file_to_update))
{
// Extract last 9 bits we actually need
$original_file_perms = @fileperms($path_to_file_to_update) & 511;
$this->filesystem->phpbb_chmod($path_to_file_to_update, filesystem::CHMOD_WRITE);
}
if (!$create_from_content)
{
try
{
$this->filesystem->copy($source, $path_to_file_to_update, true);
}
catch (filesystem_exception $e)
{
$this->write_file($path_to_file_to_update, $source, $create_from_content);
}
}
else
{
$this->write_file($path_to_file_to_update, $source, $create_from_content);
}
if ($original_file_perms !== false)
{
$this->filesystem->phpbb_chmod($path_to_file_to_update, $original_file_perms);
}
}
/**
* Creates directory structure
*
* @param string $path Path to the directory where the file should be placed (and non-existent)
*/
private function make_dir($path)
{
if (is_dir($path))
{
return;
}
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
$dirs = explode('/', $path);
$dirs_to_create = array();
do
{
$path .= '../';
$dirs_to_create[] = array_pop($dirs);
}
while (!is_dir($path));
foreach ($dirs_to_create as $directory)
{
$path .= $directory;
$this->filesystem->mkdir($path, 493); // 493 === 0755
$path .= '/';
}
}
/**
* Fallback function for file writing
*
* @param string $path_to_file Path to the file's location
* @param string $source Path to file to copy or string with the new file's content
* @param bool|false $create_from_content Whether or not to use $source as the content, false by default
*
* @throws file_updater_failure_exception When the file is not writable
*/
private function write_file($path_to_file, $source, $create_from_content = false)
{
if (!$create_from_content)
{
$source = @file_get_contents($source);
}
$file_pointer = @fopen($path_to_file, 'w');
if (!is_resource($file_pointer))
{
throw new file_updater_failure_exception();
}
@fwrite($file_pointer, $source);
@fclose($file_pointer);
}
/**
* {@inheritdoc}
*/
public function get_method_name()
{
return 'direct_file';
}
}

View File

@@ -0,0 +1,49 @@
<?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\helper\file_updater;
interface file_updater_interface
{
/**
* Deletes a file
*
* @param string $path_to_file Path to the file to delete
*/
public function delete_file($path_to_file);
/**
* Creates a new file
*
* @param string $path_to_file_to_create Path to the new file's location
* @param string $source Path to file to copy or string with the new file's content
* @param bool $create_from_content Whether or not to use $source as the content, false by default
*/
public function create_new_file($path_to_file_to_create, $source, $create_from_content = false);
/**
* Update file
*
* @param string $path_to_file_to_update Path to the file's location
* @param string $source Path to file to copy or string with the new file's content
* @param bool $create_from_content Whether or not to use $source as the content, false by default
*/
public function update_file($path_to_file_to_update, $source, $create_from_content = false);
/**
* Returns the name of the file updater method
*
* @return string
*/
public function get_method_name();
}

View File

@@ -0,0 +1,136 @@
<?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\helper\file_updater;
use phpbb\install\helper\update_helper;
/**
* File updater for FTP updates
*/
class ftp_file_updater implements file_updater_interface
{
/**
* @var \transfer
*/
protected $transfer;
/**
* @var update_helper
*/
protected $update_helper;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param update_helper $update_helper
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __constructor(update_helper $update_helper, $phpbb_root_path, $php_ext)
{
$this->transfer = null;
$this->update_helper = $update_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Initialize FTP connection
*
* @param string $method
* @param string $host
* @param string $user
* @param string $pass
* @param string $path
* @param int $port
* @param int $timeout
*/
public function init($method, $host, $user, $pass, $path, $port, $timeout)
{
$this->update_helper->include_file('includes/functions_transfer.' . $this->php_ext);
$this->transfer = new $method($host, $user, $pass, $path, $port, $timeout);
$this->transfer->open_session();
}
/**
* Close FTP session
*/
public function close()
{
$this->transfer->close_session();
}
/**
* {@inheritdoc}
*/
public function delete_file($path_to_file)
{
$this->transfer->delete_file($path_to_file);
}
/**
* {@inheritdoc}
*/
public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
{
$dirname = dirname($path_to_file_to_create);
if ($dirname && !file_exists($this->phpbb_root_path . $dirname))
{
$this->transfer->make_dir($dirname);
}
if ($create_from_content)
{
$this->transfer->write_file($path_to_file_to_create, $source);
}
else
{
$this->transfer->copy_file($path_to_file_to_create, $source);
}
}
/**
* {@inheritdoc}
*/
public function update_file($path_to_file_to_update, $source, $create_from_content = false)
{
if ($create_from_content)
{
$this->transfer->write_file($path_to_file_to_update, $source);
}
else
{
$this->transfer->copy_file($path_to_file_to_update, $source);
}
}
/**
* {@inheritdoc}
*/
public function get_method_name()
{
return 'ftp';
}
}

View File

@@ -13,11 +13,19 @@
namespace phpbb\install\helper\iohandler;
use phpbb\path_helper;
use phpbb\routing\router;
/**
* Input-Output handler for the AJAX frontend
*/
class ajax_iohandler extends iohandler_base
{
/**
* @var path_helper
*/
protected $path_helper;
/**
* @var \phpbb\request\request_interface
*/
@@ -28,6 +36,16 @@ class ajax_iohandler extends iohandler_base
*/
protected $template;
/**
* @var router
*/
protected $router;
/**
* @var string
*/
protected $file_status;
/**
* @var string
*/
@@ -48,19 +66,30 @@ class ajax_iohandler extends iohandler_base
*/
protected $cookies;
/**
* @var array
*/
protected $download;
/**
* Constructor
*
* @param path_helper $path_helper
* @param \phpbb\request\request_interface $request HTTP request interface
* @param \phpbb\template\template $template Template engine
* @param router $router Router
*/
public function __construct(\phpbb\request\request_interface $request, \phpbb\template\template $template)
public function __construct(path_helper $path_helper, \phpbb\request\request_interface $request, \phpbb\template\template $template, router $router)
{
$this->path_helper = $path_helper;
$this->request = $request;
$this->router = $router;
$this->template = $template;
$this->form = '';
$this->nav_data = array();
$this->cookies = array();
$this->download = array();
$this->file_status = '';
parent::__construct();
}
@@ -102,13 +131,13 @@ class ajax_iohandler extends iohandler_base
*/
public function add_user_form_group($title, $form)
{
$this->template->assign_var('S_FORM_ELEM_COUNT', sizeof($form));
$this->template->assign_block_vars('options', array(
'LEGEND' => $this->language->lang($title),
'S_LEGEND' => true,
));
$not_button_form = false;
foreach ($form as $input_name => $input_options)
{
if (!isset($input_options['type']))
@@ -117,6 +146,7 @@ class ajax_iohandler extends iohandler_base
}
$tpl_ary = array();
$not_button_form = ($input_options['type'] !== 'submit' || $not_button_form);
$tpl_ary['TYPE'] = $input_options['type'];
$tpl_ary['TITLE'] = $this->language->lang($input_options['label']);
@@ -136,7 +166,7 @@ class ajax_iohandler extends iohandler_base
$tpl_ary['S_EXPLAIN'] = true;
}
if (in_array($input_options['type'], array('select', 'radio')))
if (in_array($input_options['type'], array('select', 'radio'), true))
{
for ($i = 0, $total = sizeof($input_options['options']); $i < $total; $i++)
{
@@ -149,9 +179,12 @@ class ajax_iohandler extends iohandler_base
$tpl_ary['OPTIONS'] = $input_options['options'];
}
$this->template->assign_block_vars('options', $tpl_ary);
$block_name = ($input_options['type'] === 'submit') ? 'submit_buttons' : 'options';
$this->template->assign_block_vars($block_name, $tpl_ary);
}
$this->template->assign_var('S_NOT_ONLY_BUTTON_FORM', $not_button_form);
$this->template->set_filenames(array(
'form_install' => 'installer_form.html',
));
@@ -185,14 +218,27 @@ class ajax_iohandler extends iohandler_base
'warnings' => $this->warnings,
'logs' => $this->logs,
'success' => $this->success,
'download' => $this->download,
);
$this->errors = array();
$this->warnings = array();
$this->logs = array();
$this->success = array();
$this->download = array();
if (!empty($this->form))
{
$json_array['form'] = $this->form;
$this->form = '';
}
if (!empty($this->file_status))
{
$json_array['file_status'] = $this->file_status;
$this->file_status = '';
}
// If current task name is set, we push progress message to the client side
if (!empty($this->current_task_name))
{
@@ -201,19 +247,20 @@ class ajax_iohandler extends iohandler_base
'task_num' => $this->current_task_progress,
'task_count' => $this->task_progress_count,
);
if ($this->restart_progress_bar)
{
$json_array['progress']['restart'] = 1;
$this->restart_progress_bar = false;
}
}
if (!empty($this->nav_data))
{
$json_array['nav'] = $this->nav_data;
$this->nav_data = array();
}
$this->errors = array();
$this->warnings = array();
$this->logs = array();
$this->success = array();
$this->nav_data = array();
if ($this->request_client_refresh)
{
$json_array['refresh'] = true;
@@ -275,6 +322,56 @@ class ajax_iohandler extends iohandler_base
);
}
/**
* {@inheritdoc}
*/
public function add_download_link($route, $title, $msg = null)
{
$link_properties = array(
'href' => $this->router->generate($route),
'title' => $this->language->lang($title),
'download' => $this->language->lang('DOWNLOAD'),
);
if ($msg !== null)
{
$link_properties['msg'] = htmlspecialchars_decode($this->language->lang($msg));
}
$this->download[] = $link_properties;
}
/**
* {@inheritdoc}
*/
public function render_update_file_status($status_array)
{
$this->template->assign_vars(array(
'T_IMAGE_PATH' => $this->path_helper->get_web_root_path() . 'adm/images/',
));
foreach ($status_array as $block => $list)
{
foreach ($list as $filename)
{
$dirname = dirname($filename);
$this->template->assign_block_vars($block, array(
'STATUS' => $block,
'FILENAME' => $filename,
'DIR_PART' => (!empty($dirname) && $dirname !== '.') ? dirname($filename) . '/' : false,
'FILE_PART' => basename($filename),
));
}
}
$this->template->set_filenames(array(
'file_status' => 'installer_update_file_status.html',
));
$this->file_status = $this->template->assign_display('file_status');
}
/**
* Callback function for language replacing
*

View File

@@ -181,9 +181,12 @@ class cli_iohandler extends iohandler_base
}
}
public function set_task_count($task_count)
/**
* {@inheritdoc}
*/
public function set_task_count($task_count, $restart = false)
{
parent::set_task_count($task_count);
parent::set_task_count($task_count, $restart);
if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL)
{
@@ -206,6 +209,9 @@ class cli_iohandler extends iohandler_base
}
}
/**
* {@inheritdoc}
*/
public function set_progress($task_lang_key, $task_number)
{
parent::set_progress($task_lang_key, $task_number);
@@ -262,4 +268,18 @@ class cli_iohandler extends iohandler_base
public function set_cookie($cookie_name, $cookie_value)
{
}
/**
* {@inheritdoc}
*/
public function add_download_link($route, $title, $msg = null)
{
}
/**
* {@inheritdoc}
*/
public function render_update_file_status($status_array)
{
}
}

View File

@@ -80,6 +80,7 @@ abstract class iohandler_base implements iohandler_interface
$this->logs = array();
$this->success = array();
$this->restart_progress_bar = false;
$this->task_progress_count = 0;
$this->current_task_progress = 0;
$this->current_task_name = '';
@@ -130,9 +131,10 @@ abstract class iohandler_base implements iohandler_interface
/**
* {@inheritdoc}
*/
public function set_task_count($task_count)
public function set_task_count($task_count, $restart = false)
{
$this->task_progress_count = $task_count;
$this->restart_progress_bar = $restart;
}
/**

View File

@@ -127,8 +127,9 @@ interface iohandler_interface
* Sets the number of tasks belonging to the installer in the current mode.
*
* @param int $task_count Number of tasks
* @param bool $restart Whether or not to restart the progress bar, false by default
*/
public function set_task_count($task_count);
public function set_task_count($task_count, $restart = false);
/**
* Sets the progress information
@@ -164,6 +165,22 @@ interface iohandler_interface
*/
public function finish_progress($message_lang_key);
/**
* Adds a download link
*
* @param string $route Route for the link
* @param string $title Language key for the title
* @param string|null|array $msg Language key for the message
*/
public function add_download_link($route, $title, $msg = null);
/**
* Renders the status of update files
*
* @param array $status_array Array containing files in groups to render
*/
public function render_update_file_status($status_array);
/**
* Sends and sets cookies
*

View File

@@ -0,0 +1,80 @@
<?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\helper\navigation;
use phpbb\install\helper\install_helper;
class update_navigation implements navigation_interface
{
/**
* @var install_helper
*/
private $install_helper;
/**
* Constructor
*
* @param install_helper $install_helper
*/
public function __construct(install_helper $install_helper)
{
$this->install_helper = $install_helper;
}
/**
* {@inheritdoc}
*/
public function get()
{
if (!$this->install_helper->is_phpbb_installed())
{
return array();
}
return array(
'update' => array(
'label' => 'UPDATE',
'route' => 'phpbb_installer_update',
'order' => 1,
array(
'introduction' => array(
'label' => 'INTRODUCTION_TITLE',
'stage' => true,
'order' => 0,
),
'requirements' => array(
'label' => 'STAGE_REQUIREMENTS',
'stage' => true,
'order' => 1,
),
'obtain_data' => array(
'label' => 'STAGE_OBTAIN_DATA',
'stage' => true,
'order' => 2,
),
'update_files' => array(
'label' => 'STAGE_UPDATE_FILES',
'stage' => true,
'order' => 3,
),
'update_database' => array(
'label' => 'STAGE_UPDATE_DATABASE',
'stage' => true,
'order' => 4,
),
),
),
);
}
}

View File

@@ -0,0 +1,118 @@
<?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\helper;
/**
* General helper functionality for the updater
*/
class update_helper
{
/**
* @var string
*/
protected $path_to_new_files;
/**
* @var string
*/
protected $path_to_old_files;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* Constructor
*
* @param string $phpbb_root_path
*/
public function __construct($phpbb_root_path)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->path_to_new_files = $phpbb_root_path . 'install/update/new/';
$this->path_to_old_files = $phpbb_root_path . 'install/update/old/';
}
/**
* Returns path to new update files
*
* @return string
*/
public function get_path_to_new_update_files()
{
return $this->path_to_new_files;
}
/**
* Returns path to new update files
*
* @return string
*/
public function get_path_to_old_update_files()
{
return $this->path_to_old_files;
}
/**
* Includes the updated file if available
*
* @param string $filename Path to the file relative to phpBB root path
*/
public function include_file($filename)
{
if (!is_file($this->phpbb_root_path . $filename))
{
return;
}
if (is_file($this->path_to_new_files . $filename))
{
include_once($this->path_to_new_files . $filename);
}
else
{
include_once($this->phpbb_root_path . $filename);
}
}
/**
* Customized version_compare()
*
* @param string $version_number1
* @param string $version_number2
* @param string|null $operator
* @return int|bool The returned value is identical to the PHP build-in function version_compare()
*/
public function phpbb_version_compare($version_number1, $version_number2, $operator = null)
{
if ($operator === null)
{
$result = version_compare(
str_replace('rc', 'RC', strtolower($version_number1)),
str_replace('rc', 'RC', strtolower($version_number2))
);
}
else
{
$result = version_compare(
str_replace('rc', 'RC', strtolower($version_number1)),
str_replace('rc', 'RC', strtolower($version_number2)),
$operator
);
}
return $result;
}
}