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 --- phpBB/phpbb/db/html_migrator_output_handler.php | 48 ---------- .../db/log_wrapper_migrator_output_handler.php | 102 --------------------- phpBB/phpbb/db/migrator.php | 4 +- .../phpbb/db/migrator_output_handler_interface.php | 31 ------- phpBB/phpbb/db/null_migrator_output_handler.php | 24 ----- .../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 +++++ 10 files changed, 250 insertions(+), 206 deletions(-) delete mode 100644 phpBB/phpbb/db/html_migrator_output_handler.php delete mode 100644 phpBB/phpbb/db/log_wrapper_migrator_output_handler.php delete mode 100644 phpBB/phpbb/db/migrator_output_handler_interface.php delete mode 100644 phpBB/phpbb/db/null_migrator_output_handler.php 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') diff --git a/phpBB/phpbb/db/html_migrator_output_handler.php b/phpBB/phpbb/db/html_migrator_output_handler.php deleted file mode 100644 index e37c667463..0000000000 --- a/phpBB/phpbb/db/html_migrator_output_handler.php +++ /dev/null @@ -1,48 +0,0 @@ - -* @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; - -use phpbb\user; - -class html_migrator_output_handler implements migrator_output_handler_interface -{ - /** - * User object. - * - * @var user - */ - private $user; - - /** - * Constructor - * - * @param user $user User object - */ - public function __construct(user $user) - { - $this->user = $user; - } - - /** - * {@inheritdoc} - */ - public function write($message, $verbosity) - { - if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) - { - $final_message = call_user_func_array(array($this->user, 'lang'), $message); - echo $final_message . "
\n"; - } - } -} diff --git a/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php b/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php deleted file mode 100644 index 4c85bf4d67..0000000000 --- a/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php +++ /dev/null @@ -1,102 +0,0 @@ - -* @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; - -use phpbb\user; - -class log_wrapper_migrator_output_handler implements migrator_output_handler_interface -{ - /** - * User object. - * - * @var user - */ - protected $user; - - /** - * 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 user $user User object - * @param migrator_output_handler_interface $migrator Migrator output handler - * @param string $log_file File to log to - * @param \phpbb\filesystem\filesystem_interface phpBB filesystem object - */ - public function __construct(user $user, migrator_output_handler_interface $migrator, $log_file, \phpbb\filesystem\filesystem_interface $filesystem) - { - $this->user = $user; - $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 = call_user_func_array(array($this->user, 'lang'), $message) . "\n"; - - 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/migrator.php b/phpBB/phpbb/db/migrator.php index 18c6403c07..a809bc14f9 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -13,6 +13,8 @@ namespace phpbb\db; +use phpbb\db\output_handler\migrator_output_handler_interface; +use phpbb\db\output_handler\null_migrator_output_handler; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -122,7 +124,7 @@ class migrator /** * Set the output handler. * - * @param migrator_output_handler $handler The output handler + * @param migrator_output_handler_interface $handler The output handler */ public function set_output_handler(migrator_output_handler_interface $handler) { diff --git a/phpBB/phpbb/db/migrator_output_handler_interface.php b/phpBB/phpbb/db/migrator_output_handler_interface.php deleted file mode 100644 index a923af99f6..0000000000 --- a/phpBB/phpbb/db/migrator_output_handler_interface.php +++ /dev/null @@ -1,31 +0,0 @@ - -* @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; - -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/null_migrator_output_handler.php b/phpBB/phpbb/db/null_migrator_output_handler.php deleted file mode 100644 index 0e8cfbb049..0000000000 --- a/phpBB/phpbb/db/null_migrator_output_handler.php +++ /dev/null @@ -1,24 +0,0 @@ - -* @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; - -class null_migrator_output_handler implements migrator_output_handler_interface -{ - /** - * {@inheritdoc} - */ - public function write($message, $verbosity) - { - } -} 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