From 8f5a0ad6f73e7b7757b02c827436384c96069b5a Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 24 Jul 2015 09:20:50 +0200 Subject: [ticket/14039] Revamp updater PHPBB3-14039 --- .../html_migrator_output_handler.php | 46 ++++++++++ .../installer_migrator_output_handler.php | 46 ++++++++++ .../log_wrapper_migrator_output_handler.php | 100 +++++++++++++++++++++ .../migrator_output_handler_interface.php | 31 +++++++ .../null_migrator_output_handler.php | 24 +++++ 5 files changed, 247 insertions(+) create mode 100644 phpBB/phpbb/db/output_handler/html_migrator_output_handler.php create mode 100644 phpBB/phpbb/db/output_handler/installer_migrator_output_handler.php create mode 100644 phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php create mode 100644 phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php create mode 100644 phpBB/phpbb/db/output_handler/null_migrator_output_handler.php (limited to 'phpBB/phpbb/db/output_handler') 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..f15b8e5913 --- /dev/null +++ b/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php @@ -0,0 +1,46 @@ + +* @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($message); + echo $final_message . "
\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 @@ + + * @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..475b2616e5 --- /dev/null +++ b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php @@ -0,0 +1,100 @@ + +* @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($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 @@ + +* @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 @@ + +* @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) + { + } +} -- cgit v1.2.1 From 94bd35fd3b24b727adb91ba325e6bb8d1522c7b0 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Sun, 18 Oct 2015 18:28:12 +0200 Subject: [ticket/14039] Fix migrator's language calls PHPBB3-14039 --- phpBB/phpbb/db/output_handler/html_migrator_output_handler.php | 2 +- phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/db/output_handler') diff --git a/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php b/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php index f15b8e5913..67309649c9 100644 --- a/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php +++ b/phpBB/phpbb/db/output_handler/html_migrator_output_handler.php @@ -39,7 +39,7 @@ class html_migrator_output_handler implements migrator_output_handler_interface { if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) { - $final_message = $this->language->lang_array($message); + $final_message = $this->language->lang_array(array_shift($message), $message); echo $final_message . "
\n"; } } 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 index 475b2616e5..20991746ac 100644 --- a/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php +++ b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php @@ -82,7 +82,8 @@ class log_wrapper_migrator_output_handler implements migrator_output_handler_int if ($this->file_handle !== false) { - $translated_message = $this->language->lang_array($message); + + $translated_message = $this->language->lang_array(array_shift($message), $message); if ($verbosity <= migrator_output_handler_interface::VERBOSITY_NORMAL) { -- cgit v1.2.1 From a99cb31a5290883bba532e8c340e6ef7bca802fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Col=C3=B3n?= Date: Fri, 2 Dec 2016 14:23:44 +0100 Subject: [ticket/14885] Add a line break when writing to the migrator output file --- phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/db/output_handler') 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 index 20991746ac..d28c195baa 100644 --- a/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php +++ b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php @@ -94,7 +94,7 @@ class log_wrapper_migrator_output_handler implements migrator_output_handler_int $translated_message = '[DEBUG] ' . $translated_message; } - fwrite($this->file_handle, $translated_message); + fwrite($this->file_handle, $translated_message . "\r"); fflush($this->file_handle); } } -- cgit v1.2.1 From c3caa3d9dc156ed796c96810e88d4e98711d8d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Col=C3=B3n?= Date: Fri, 2 Dec 2016 16:50:55 +0100 Subject: [ticket/14885] Use \n instead of \r for output_handler messages --- phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/db/output_handler') 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 index d28c195baa..e4bd3ac8e0 100644 --- a/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php +++ b/phpBB/phpbb/db/output_handler/log_wrapper_migrator_output_handler.php @@ -94,7 +94,7 @@ class log_wrapper_migrator_output_handler implements migrator_output_handler_int $translated_message = '[DEBUG] ' . $translated_message; } - fwrite($this->file_handle, $translated_message . "\r"); + fwrite($this->file_handle, $translated_message . "\n"); fflush($this->file_handle); } } -- cgit v1.2.1