aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2014-10-24 13:20:40 -0700
committerMarc Alexander <admin@m-a-styles.de>2014-10-24 13:22:56 -0700
commit516bd9ea51a2c2b908eb1f62bddaba967559db4a (patch)
tree70de1f06e02608fd1a24b89c828d0718f37409f6
parent14300a147587755ecf07fae038a3767039fd8504 (diff)
downloadforums-516bd9ea51a2c2b908eb1f62bddaba967559db4a.tar
forums-516bd9ea51a2c2b908eb1f62bddaba967559db4a.tar.gz
forums-516bd9ea51a2c2b908eb1f62bddaba967559db4a.tar.bz2
forums-516bd9ea51a2c2b908eb1f62bddaba967559db4a.tar.xz
forums-516bd9ea51a2c2b908eb1f62bddaba967559db4a.zip
[ticket/13211] Add log wrapper for writing database updater to log file
PHPBB3-13211
-rw-r--r--phpBB/install/database_update.php2
-rw-r--r--phpBB/phpbb/db/log_wrapper_migrator_output_handler.php95
2 files changed, 96 insertions, 1 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 5a2287c9e1..80fd40a944 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -174,7 +174,7 @@ define('IN_DB_UPDATE', true);
// End startup code
$migrator = $phpbb_container->get('migrator');
-$migrator->set_output_handler(new \phpbb\db\html_migrator_output_handler($user));
+$migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($user, new \phpbb\db\html_migrator_output_handler($user), $phpbb_root_path . 'store/migrations_' . time() . '.log'));
$migrator->create_migrations_table();
diff --git a/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php b/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php
new file mode 100644
index 0000000000..e81dfd7a62
--- /dev/null
+++ b/phpBB/phpbb/db/log_wrapper_migrator_output_handler.php
@@ -0,0 +1,95 @@
+<?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;
+
+use phpbb\user;
+
+class log_wrapper_migrator_output_handler implements migrator_output_handler_interface
+{
+ /**
+ * User object.
+ *
+ * @var user
+ */
+ protected $user;
+
+ /**
+ * HTML migrator output handler
+ *
+ * @var html_migrator_output_handler
+ */
+ protected $html_migrator;
+
+ /**
+ * Log file handle
+ * @var resource
+ */
+ protected $file_handle = false;
+
+ /**
+ * Constructor
+ *
+ * @param user $user User object
+ * @param html_migrator_output_handler $html_migrator HTML migrator output handler
+ * @param string $log_file File to log to
+ */
+ public function __construct(user $user, html_migrator_output_handler $html_migrator, $log_file)
+ {
+ $this->user = $user;
+ $this->html_migrator = $html_migrator;
+ $this->file_open($log_file);
+ }
+
+ /**
+ * Open file for logging
+ *
+ * @param string $file File to open
+ */
+ protected function file_open($file)
+ {
+ if (phpbb_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->html_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);
+ }
+ }
+}