diff options
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php | 39 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php | 4 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/softdelete_p1.php | 37 | ||||
-rw-r--r-- | phpBB/phpbb/db/migrator.php | 4 | ||||
-rw-r--r-- | phpBB/phpbb/filesystem.php | 145 | ||||
-rw-r--r-- | phpBB/phpbb/path_helper.php | 175 | ||||
-rw-r--r-- | phpBB/phpbb/template/asset.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/environment.php | 22 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/node/includeasset.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/twig.php | 22 |
10 files changed, 267 insertions, 193 deletions
diff --git a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index bd7614e1c2..4195623618 100644 --- a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -19,35 +19,44 @@ class notification_options_reconvert extends \phpbb\db\migration\migration public function update_data() { return array( + array('custom', array(array($this, 'purge_notifications'))), array('custom', array(array($this, 'convert_notifications'))), ); } - public function convert_notifications() + public function purge_notifications() { - $insert_table = $this->table_prefix . 'user_notifications'; - $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $insert_table); + $sql = 'DELETE FROM ' . $this->table_prefix . 'user_notifications'; + $this->sql_query($sql); + } + + public function convert_notifications($start) + { + $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications'); - $this->perform_conversion($insert_buffer, $insert_table); + return $this->perform_conversion($insert_buffer, $start); } /** * Perform the conversion (separate for testability) * - * @param \phpbb\db\sql_insert_buffer $insert_buffer - * @param string $insert_table + * @param \phpbb\db\sql_insert_buffer $insert_buffer + * @param int $start Start of staggering step + * @return mixed int start of the next step, null if the end was reached */ - public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $insert_table) + public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $start) { - $sql = 'DELETE FROM ' . $insert_table; - $this->db->sql_query($sql); + $limit = 250; + $converted_users = 0; $sql = 'SELECT user_id, user_notify_type, user_notify_pm - FROM ' . USERS_TABLE; - $result = $this->db->sql_query($sql); + FROM ' . $this->table_prefix . 'users + ORDER BY user_id'; + $result = $this->db->sql_query_limit($sql, $limit, $start); while ($row = $this->db->sql_fetchrow($result)) { + $converted_users++; $notification_methods = array(); // In-board notification @@ -91,6 +100,14 @@ class notification_options_reconvert extends \phpbb\db\migration\migration $this->db->sql_freeresult($result); $insert_buffer->flush(); + + if ($converted_users < $limit) + { + // No more users left, we are done... + return; + } + + return $start + $limit; } /** diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php index 2db9780601..d1a31815b2 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php @@ -28,8 +28,8 @@ class softdelete_mcp_modules extends \phpbb\db\migration\migration static public function depends_on() { return array( - 'phpbb\db\migration\data\v310\dev', - 'phpbb\db\migration\data\v310\softdelete_p2', + '\phpbb\db\migration\data\v310\dev', + '\phpbb\db\migration\data\v310\softdelete_p2', ); } diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index 0418d5cc2b..f080c78c50 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -101,7 +101,8 @@ class softdelete_p1 extends \phpbb\db\migration\migration return array( array('custom', array(array($this, 'update_post_visibility'))), array('custom', array(array($this, 'update_topic_visibility'))), - array('custom', array(array($this, 'update_topic_forum_counts'))), + array('custom', array(array($this, 'update_topics_post_counts'))), + array('custom', array(array($this, 'update_forums_topic_and_post_counts'))), array('permission.add', array('f_softdelete', false)), array('permission.add', array('m_softdelete', false)), @@ -122,28 +123,43 @@ class softdelete_p1 extends \phpbb\db\migration\migration $this->sql_query($sql); } - public function update_topic_forum_counts() + public function update_topics_post_counts() { + /* + * Using sql_case here to avoid "BIGINT UNSIGNED value is out of range" errors. + * As we update all topics in 2 queries, one broken topic would stop the conversion + * for all topics and the surpressed error will cause the admin to not even notice it. + */ $sql = 'UPDATE ' . $this->table_prefix . 'topics SET topic_posts_approved = topic_replies + 1, - topic_posts_unapproved = topic_replies_real - topic_replies + topic_posts_unapproved = ' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ' WHERE topic_visibility = ' . ITEM_APPROVED; $this->sql_query($sql); $sql = 'UPDATE ' . $this->table_prefix . 'topics SET topic_posts_approved = 0, - topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 + topic_posts_unapproved = (' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ') + 1 WHERE topic_visibility = ' . ITEM_UNAPPROVED; $this->sql_query($sql); + } + + public function update_forums_topic_and_post_counts($start) + { + $start = (int) $start; + $limit = 10; + $converted_forums = 0; $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics - GROUP BY forum_id, topic_visibility'; - $result = $this->db->sql_query($sql); + GROUP BY forum_id, topic_visibility + ORDER BY forum_id, topic_visibility'; + $result = $this->db->sql_query_limit($sql, $limit, $start); $update_forums = array(); while ($row = $this->db->sql_fetchrow($result)) { + $converted_forums++; + $forum_id = (int) $row['forum_id']; if (!isset($update_forums[$forum_id])) { @@ -169,5 +185,14 @@ class softdelete_p1 extends \phpbb\db\migration\migration WHERE forum_id = ' . $forum_id; $this->sql_query($sql); } + + if ($converted_forums < $limit) + { + // There are no more topics, we are done + return; + } + + // There are still more topics to query, return the next start value + return $start + $limit; } } diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index d7d2b3df59..7efb23a230 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -208,7 +208,7 @@ class migrator if (!isset($this->migration_state[$name])) { - if ($migration->effectively_installed()) + if ($state['migration_start_time'] == 0 && $migration->effectively_installed()) { $state = array( 'migration_depends_on' => $migration->depends_on(), @@ -227,6 +227,8 @@ class migrator } } + $this->set_migration_state($name, $state); + if (!$state['migration_schema_done']) { $this->apply_schema_changes($migration->update_schema()); diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 662b6b866e..dbfaebe0fa 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -23,151 +23,6 @@ if (!defined('IN_PHPBB')) */ class filesystem { - /** @var \phpbb\symfony_request */ - protected $symfony_request; - - /** @var string */ - protected $phpbb_root_path; - - /** @var string */ - protected $adm_relative_path; - - /** @var string */ - protected $php_ext; - - /** @var string */ - protected $web_root_path; - - /** - * Constructor - * - * @param \phpbb\symfony_request $symfony_request - * @param string $phpbb_root_path Relative path to phpBB root - * @param string $php_ext PHP extension (php) - */ - public function __construct(\phpbb\symfony_request $symfony_request, $phpbb_root_path, $php_ext, $adm_relative_path = null) - { - $this->symfony_request = $symfony_request; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->adm_relative_path = $adm_relative_path; - } - - /** - * Get the phpBB root path - * - * @return string - */ - public function get_phpbb_root_path() - { - return $this->phpbb_root_path; - } - - /** - * Get the adm root path - * - * @return string - */ - public function get_adm_relative_path() - { - return $this->adm_relative_path; - } - - /** - * Get the php extension - * - * @return string - */ - public function get_php_ext() - { - return $this->php_ext; - } - - /** - * Update a path to the correct relative root path - * - * This replaces $phpbb_root_path . some_url with - * get_web_root_path() . some_url OR if $phpbb_root_path - * is not at the beginning of $path, just prepends the - * web root path - * - * @param string $path The path to be updated - * @return string - */ - public function update_web_root_path($path) - { - $web_root_path = $this->get_web_root_path($this->symfony_request); - - if (strpos($path, $this->phpbb_root_path) === 0) - { - $path = substr($path, strlen($this->phpbb_root_path)); - } - - return $web_root_path . $path; - } - - /** - * Get a relative root path from the current URL - * - * @return string - */ - public function get_web_root_path() - { - if ($this->symfony_request === null) - { - return $this->phpbb_root_path; - } - - if (null !== $this->web_root_path) - { - return $this->web_root_path; - } - - // Path info (e.g. /foo/bar) - $path_info = $this->clean_path($this->symfony_request->getPathInfo()); - - // Full request URI (e.g. phpBB/app.php/foo/bar) - $request_uri = $this->symfony_request->getRequestUri(); - - // Script name URI (e.g. phpBB/app.php) - $script_name = $this->symfony_request->getScriptName(); - - /* - * If the path info is empty (single /), then we're not using - * a route like app.php/foo/bar - */ - if ($path_info === '/') - { - return $this->web_root_path = $this->phpbb_root_path; - } - - // How many corrections might we need? - $corrections = substr_count($path_info, '/'); - - /* - * If the script name (e.g. phpBB/app.php) exists in the - * requestUri (e.g. phpBB/app.php/foo/template), then we - * are have a non-rewritten URL. - */ - if (strpos($request_uri, $script_name) === 0) - { - /* - * Append ../ to the end of the phpbb_root_path as many times - * as / exists in path_info - */ - return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); - } - - /* - * If we're here it means we're at a re-written path, so we must - * correct the relative path for web URLs. We must append ../ - * to the end of the root path as many times as / exists in path_info - * less one time (because the script, e.g. /app.php, doesn't exist in - * the URL) - */ - return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); - } - /** * Eliminates useless . and .. components from specified path. * diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php new file mode 100644 index 0000000000..b2ed11a927 --- /dev/null +++ b/phpBB/phpbb/path_helper.php @@ -0,0 +1,175 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* A class with various functions that are related to paths, files and the filesystem +* @package phpBB3 +*/ +class path_helper +{ + /** @var \phpbb\symfony_request */ + protected $symfony_request; + + /** @var \phpbb\filesystem */ + protected $filesystem; + + /** @var string */ + protected $phpbb_root_path; + + /** @var string */ + protected $adm_relative_path; + + /** @var string */ + protected $php_ext; + + /** @var string */ + protected $web_root_path; + + /** + * Constructor + * + * @param \phpbb\symfony_request $symfony_request + * @param \phpbb\filesystem $filesystem + * @param string $phpbb_root_path Relative path to phpBB root + * @param string $php_ext PHP extension (php) + */ + public function __construct(\phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $adm_relative_path = null) + { + $this->symfony_request = $symfony_request; + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->adm_relative_path = $adm_relative_path; + } + + /** + * Get the phpBB root path + * + * @return string + */ + public function get_phpbb_root_path() + { + return $this->phpbb_root_path; + } + + /** + * Get the adm root path + * + * @return string + */ + public function get_adm_relative_path() + { + return $this->adm_relative_path; + } + + /** + * Get the php extension + * + * @return string + */ + public function get_php_ext() + { + return $this->php_ext; + } + + /** + * Update a path to the correct relative root path + * + * This replaces $phpbb_root_path . some_url with + * get_web_root_path() . some_url OR if $phpbb_root_path + * is not at the beginning of $path, just prepends the + * web root path + * + * @param string $path The path to be updated + * @return string + */ + public function update_web_root_path($path) + { + $web_root_path = $this->get_web_root_path($this->symfony_request); + + if (strpos($path, $this->phpbb_root_path) === 0) + { + $path = substr($path, strlen($this->phpbb_root_path)); + } + + return $web_root_path . $path; + } + + /** + * Get a relative root path from the current URL + * + * @return string + */ + public function get_web_root_path() + { + if ($this->symfony_request === null) + { + return $this->phpbb_root_path; + } + + if (null !== $this->web_root_path) + { + return $this->web_root_path; + } + + // Path info (e.g. /foo/bar) + $path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo()); + + // Full request URI (e.g. phpBB/app.php/foo/bar) + $request_uri = $this->symfony_request->getRequestUri(); + + // Script name URI (e.g. phpBB/app.php) + $script_name = $this->symfony_request->getScriptName(); + + /* + * If the path info is empty (single /), then we're not using + * a route like app.php/foo/bar + */ + if ($path_info === '/') + { + return $this->web_root_path = $this->phpbb_root_path; + } + + // How many corrections might we need? + $corrections = substr_count($path_info, '/'); + + /* + * If the script name (e.g. phpBB/app.php) exists in the + * requestUri (e.g. phpBB/app.php/foo/template), then we + * are have a non-rewritten URL. + */ + if (strpos($request_uri, $script_name) === 0) + { + /* + * Append ../ to the end of the phpbb_root_path as many times + * as / exists in path_info + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); + } + + /* + * If we're here it means we're at a re-written path, so we must + * correct the relative path for web URLs. We must append ../ + * to the end of the root path as many times as / exists in path_info + * less one time (because the script, e.g. /app.php, doesn't exist in + * the URL) + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); + } +} diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php index 0e0b6b4782..27564bf347 100644 --- a/phpBB/phpbb/template/asset.php +++ b/phpBB/phpbb/template/asset.php @@ -21,17 +21,17 @@ class asset { protected $components = array(); - /** @var \phpbb\filesystem **/ - protected $phpbb_filesystem; + /** @var \phpbb\path_helper **/ + protected $path_helper; /** * Constructor * * @param string $url URL */ - public function __construct($url, \phpbb\filesystem $phpbb_filesystem) + public function __construct($url, \phpbb\path_helper $path_helper) { - $this->phpbb_filesystem = $phpbb_filesystem; + $this->path_helper = $path_helper; $this->set_url($url); } @@ -119,7 +119,7 @@ class asset */ public function get_url() { - return $this->phpbb_filesystem->update_web_root_path($this->join_url($this->components)); + return $this->path_helper->update_web_root_path($this->join_url($this->components)); } /** diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index e0ee23dcd9..a6c0e476f0 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -25,8 +25,8 @@ class environment extends \Twig_Environment /** @var \phpbb\config\config */ protected $phpbb_config; - /** @var \phpbb\filesystem */ - protected $phpbb_filesystem; + /** @var \phpbb\path_helper */ + protected $phpbb_path_helper; /** @var string */ protected $phpbb_root_path; @@ -42,19 +42,19 @@ class environment extends \Twig_Environment * * @param \phpbb\config\config $phpbb_config * @param array $phpbb_extensions Array of enabled extensions (name => path) - * @param \phpbb\filesystem + * @param \phpbb\path_helper * @param string $phpbb_root_path * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, $phpbb_extensions, \phpbb\filesystem $phpbb_filesystem, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, $phpbb_extensions, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->phpbb_extensions = $phpbb_extensions; - $this->phpbb_filesystem = $phpbb_filesystem; - $this->phpbb_root_path = $this->phpbb_filesystem->get_phpbb_root_path(); - $this->web_root_path = $this->phpbb_filesystem->get_web_root_path(); + $this->phpbb_path_helper = $path_helper; + $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); + $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); return parent::__construct($loader, $options); } @@ -102,13 +102,13 @@ class environment extends \Twig_Environment } /** - * Get the phpbb_filesystem object + * Get the phpbb path helper object * - * @return \phpbb\filesystem + * @return \phpbb\path_helper */ - public function get_filesystem() + public function get_path_helper() { - return $this->phpbb_filesystem; + return $this->phpbb_path_helper; } /** diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index f15fd6296b..f6c9dc9c58 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -35,7 +35,7 @@ abstract class includeasset extends \Twig_Node ->write("\$asset_file = ") ->subcompile($this->getNode('expr')) ->raw(";\n") - ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_filesystem());\n") + ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n") ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") ->indent() ->write("\$asset_path = \$asset->get_path();") diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 2da7405743..9df9310427 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -33,10 +33,10 @@ class twig extends \phpbb\template\base private $cachepath = ''; /** - * phpBB filesystem - * @var \phpbb\filesystem + * phpBB path helper + * @var \phpbb\path_helper */ - protected $phpbb_filesystem; + protected $path_helper; /** * phpBB root path @@ -79,17 +79,17 @@ class twig extends \phpbb\template\base /** * Constructor. * - * @param \phpbb\filesystem $phpbb_filesystem + * @param \phpbb\path_helper $path_helper * @param \phpbb\config\config $config * @param \phpbb\user $user * @param \phpbb\template\context $context template context * @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked */ - public function __construct(\phpbb\filesystem $phpbb_filesystem, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null) + public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null) { - $this->phpbb_filesystem = $phpbb_filesystem; - $this->phpbb_root_path = $phpbb_filesystem->get_phpbb_root_path(); - $this->php_ext = $phpbb_filesystem->get_php_ext(); + $this->path_helper = $path_helper; + $this->phpbb_root_path = $path_helper->get_phpbb_root_path(); + $this->php_ext = $path_helper->get_php_ext(); $this->config = $config; $this->user = $user; $this->context = $context; @@ -103,7 +103,7 @@ class twig extends \phpbb\template\base $this->twig = new \phpbb\template\twig\environment( $this->config, ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(), - $this->phpbb_filesystem, + $this->path_helper, $loader, array( 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath, @@ -125,9 +125,9 @@ class twig extends \phpbb\template\base $this->twig->setLexer($lexer); // Add admin namespace - if ($this->phpbb_filesystem->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/')) + if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) { - $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/', 'admin'); + $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/', 'admin'); } } |