diff options
Diffstat (limited to 'phpBB/phpbb/db/output_handler')
5 files changed, 248 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php b/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php new file mode 100644 index 0000000000..67309649c9 --- /dev/null +++ b/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php @@ -0,0 +1,46 @@ +<?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\db\output_handler; + +class html_migrator_output_handler implements migrator_output_handler_interface +{ +	/** +	 * Language object. +	 * +	 * @var \phpbb\language\language +	 */ +	private $language; + +	/** +	 * Constructor +	 * +	 * @param \phpbb\language\language	$language	Language object +	 */ +	public function __construct(\phpbb\language\language $language) +	{ +		$this->language = $language; +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function write($message, $verbosity) +	{ +		if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) +		{ +			$final_message = $this->language->lang_array(array_shift($message), $message); +			echo $final_message . "<br />\n"; +		} +	} +} diff --git a/phpBB/phpbb/db/output_handler/installer_migrator_output_handler.php b/phpBB/phpbb/db/output_handler/installer_migrator_output_handler.php new file mode 100644 index 0000000000..56d5cf49a1 --- /dev/null +++ b/phpBB/phpbb/db/output_handler/installer_migrator_output_handler.php @@ -0,0 +1,46 @@ +<?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\db\output_handler; + +use phpbb\install\helper\iohandler\iohandler_interface; + +class installer_migrator_output_handler implements migrator_output_handler_interface +{ +	/** +	 * @var iohandler_interface +	 */ +	protected $iohandler; + +	/** +	 * Constructor +	 * +	 * @param iohandler_interface	$iohandler	Installer's IO-handler +	 */ +	public function __construct(iohandler_interface $iohandler) +	{ +		$this->iohandler = $iohandler; +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function write($message, $verbosity) +	{ +		if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) +		{ +			$this->iohandler->add_log_message($message); +			$this->iohandler->send_response(); +		} +	} +} diff --git a/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php new file mode 100644 index 0000000000..20991746ac --- /dev/null +++ b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php @@ -0,0 +1,101 @@ +<?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\db\output_handler; + +class log_wrapper_migrator_output_handler implements migrator_output_handler_interface +{ +	/** +	 * Language object. +	 * +	 * @var \phpbb\language\language +	 */ +	protected $language; + +	/** +	 * A migrator output handler +	 * +	 * @var migrator_output_handler_interface +	 */ +	protected $migrator; + +	/** +	 * Log file handle +	 * @var resource +	 */ +	protected $file_handle = false; + +	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/** +	 * Constructor +	 * +	 * @param \phpbb\language\language					$language	Language object +	 * @param migrator_output_handler_interface			$migrator	Migrator output handler +	 * @param string									$log_file	File to log to +	 * @param \phpbb\filesystem\filesystem_interface	$filesystem	phpBB filesystem object +	 */ +	public function __construct(\phpbb\language\language $language, migrator_output_handler_interface $migrator, $log_file, \phpbb\filesystem\filesystem_interface $filesystem) +	{ +		$this->language = $language; +		$this->migrator = $migrator; +		$this->filesystem = $filesystem; +		$this->file_open($log_file); +	} + +	/** +	 * Open file for logging +	 * +	 * @param string $file File to open +	 */ +	protected function file_open($file) +	{ +		if ($this->filesystem->is_writable(dirname($file))) +		{ +			$this->file_handle = fopen($file, 'w'); +		} +		else +		{ +			throw new \RuntimeException('Unable to write to migrator log file'); +		} +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function write($message, $verbosity) +	{ +		$this->migrator->write($message, $verbosity); + +		if ($this->file_handle !== false) +		{ + +			$translated_message = $this->language->lang_array(array_shift($message), $message); + +			if ($verbosity <= migrator_output_handler_interface::VERBOSITY_NORMAL) +			{ +				$translated_message = '[INFO] ' . $translated_message; +			} +			else +			{ +				$translated_message = '[DEBUG] ' . $translated_message; +			} + +			fwrite($this->file_handle, $translated_message); +			fflush($this->file_handle); +		} +	} +} diff --git a/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php b/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php new file mode 100644 index 0000000000..7bb5c73fec --- /dev/null +++ b/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php @@ -0,0 +1,31 @@ +<?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\db\output_handler; + +interface migrator_output_handler_interface +{ +	const VERBOSITY_QUIET        = 0; +	const VERBOSITY_NORMAL       = 1; +	const VERBOSITY_VERBOSE      = 2; +	const VERBOSITY_VERY_VERBOSE = 3; +	const VERBOSITY_DEBUG        = 4; + +	/** +	 * Write output using the configured closure. +	 * +	 * @param string|array $message The message to write or an array containing the language key and all of its parameters. +	 * @param int $verbosity The verbosity of the message. +	 */ +	public function write($message, $verbosity); +} diff --git a/phpBB/phpbb/db/output_handler/null_migrator_output_handler.php b/phpBB/phpbb/db/output_handler/null_migrator_output_handler.php new file mode 100644 index 0000000000..5fc2a52577 --- /dev/null +++ b/phpBB/phpbb/db/output_handler/null_migrator_output_handler.php @@ -0,0 +1,24 @@ +<?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\db\output_handler; + +class null_migrator_output_handler implements migrator_output_handler_interface +{ +	/** +	 * {@inheritdoc} +	 */ +	public function write($message, $verbosity) +	{ +	} +}  | 
