diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | build/build.xml | 20 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 99 | ||||
-rw-r--r-- | phpBB/includes/functions_acp.php | 31 | ||||
-rw-r--r-- | phpBB/phpbb/di/service_collection.php | 47 | ||||
-rw-r--r-- | phpBB/phpbb/di/service_collection_iterator.php | 87 | ||||
-rw-r--r-- | phpBB/phpbb/notification/manager.php | 52 | ||||
-rw-r--r-- | tests/notification/notification_test.php | 21 |
8 files changed, 275 insertions, 88 deletions
diff --git a/.gitignore b/.gitignore index 18f598cf67..de503c10ad 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,13 @@ /phpBB/files/* /phpBB/images/avatars/gallery/* /phpBB/images/avatars/upload/* +/phpBB/images/ranks/* +/phpBB/language/* +!/phpBB/language/en /phpBB/store/* +/phpBB/styles/* +!/phpBB/styles/prosilver +!/phpBB/styles/subsilver2 /phpBB/vendor /tests/phpbb_unit_tests.sqlite* /tests/test_config*.php diff --git a/build/build.xml b/build/build.xml index ec94cf3ea6..510e7d0955 100644 --- a/build/build.xml +++ b/build/build.xml @@ -78,22 +78,22 @@ -s --extensions=php --standard=build/code_sniffer/ruleset-php-strict.xml - --ignore=phpBB/phpbb/db/migration/data/v30x/* + --ignore=${project.basedir}/phpBB/phpbb/db/migration/data/v30x/* phpBB/phpbb" dir="." returnProperty="retval-php-strict" passthru="true" /> <exec command="phpBB/vendor/bin/phpcs -s --extensions=php --standard=build/code_sniffer/ruleset-php-legacy.xml - --ignore=phpBB/cache/* - --ignore=phpBB/develop/* - --ignore=phpBB/includes/diff/*.php - --ignore=phpBB/includes/sphinxapi.php - --ignore=phpBB/includes/utf/data/* - --ignore=phpBB/install/data/* - --ignore=phpBB/install/database_update.php - --ignore=phpBB/phpbb/* - --ignore=phpBB/vendor/* + --ignore=${project.basedir}/phpBB/cache/* + --ignore=${project.basedir}/phpBB/develop/* + --ignore=${project.basedir}/phpBB/includes/diff/*.php + --ignore=${project.basedir}/phpBB/includes/sphinxapi.php + --ignore=${project.basedir}/phpBB/includes/utf/data/* + --ignore=${project.basedir}/phpBB/install/data/* + --ignore=${project.basedir}/phpBB/install/database_update.php + --ignore=${project.basedir}/phpBB/phpbb/* + --ignore=${project.basedir}/phpBB/vendor/* phpBB" dir="." returnProperty="retval-php-legacy" passthru="true" /> <if> diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3238f66e96..3d0a4761f3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5031,6 +5031,72 @@ function page_header($page_title = '', $display_online_list = false, $item_id = } /** +* Check and display the SQL report if requested. +* +* @param \phpbb\request\request_interface $request Request object +* @param \phpbb\auth\auth $auth Auth object +* @param \phpbb\db\driver\driver_interface $db Database connection +*/ +function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db) +{ + if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG')) + { + $db->sql_report('display'); + } +} + +/** +* Generate the debug output string +* +* @param \phpbb\db\driver\driver_interface $db Database connection +* @param \phpbb\config\config $config Config object +* @param \phpbb\auth\auth $auth Auth object +* @param \phpbb\user $user User object +* @return string +*/ +function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\auth\auth $auth, \phpbb\user $user) +{ + $debug_info = array(); + + // Output page creation time + if (defined('PHPBB_DISPLAY_LOAD_TIME')) + { + if (isset($GLOBALS['starttime'])) + { + $totaltime = microtime(true) - $GLOBALS['starttime']; + $debug_info[] = sprintf('Time: %.3fs', $totaltime); + } + + $debug_info[] = $db->sql_num_queries() . ' Queries (' . $db->sql_num_queries(true) . ' cached)'; + + $memory_usage = memory_get_peak_usage(); + if ($memory_usage) + { + $memory_usage = get_formatted_filesize($memory_usage); + + $debug_info[] = 'Peak Memory Usage: ' . $memory_usage; + } + } + + if (defined('DEBUG')) + { + $debug_info[] = 'GZIP: ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off'); + + if ($user->load) + { + $debug_info[] = 'Load: ' . $user->load; + } + + if ($auth->acl_get('a_')) + { + $debug_info[] = '<a href="' . build_url() . '&explain=1">SQL Explain</a>'; + } + } + + return implode(' | ', $debug_info); +} + +/** * Generate page footer * * @param bool $run_cron Whether or not to run the cron @@ -5062,37 +5128,10 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler = return; } - // Output page creation time - if (defined('DEBUG')) - { - $mtime = explode(' ', microtime()); - $totaltime = $mtime[0] + $mtime[1] - $starttime; - - if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report')) - { - $db->sql_report('display'); - } - - $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); - - if ($auth->acl_get('a_') && defined('DEBUG')) - { - if (function_exists('memory_get_peak_usage')) - { - if ($memory_usage = memory_get_peak_usage()) - { - $memory_usage = get_formatted_filesize($memory_usage); - - $debug_output .= ' | Peak Memory Usage: ' . $memory_usage; - } - } - - $debug_output .= ' | <a href="' . build_url() . '&explain=1">Explain</a>'; - } - } + phpbb_check_and_display_sql_report($request, $auth, $db); $template->assign_vars(array( - 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', + 'DEBUG_OUTPUT' => phpbb_generate_debug_output($db, $config, $auth, $user), 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'), @@ -5272,7 +5311,7 @@ function phpbb_convert_30_dbms_to_31($dbms) // true for mysqli class. // However, per the docblock any valid 3.1 driver name should be // recognized by this function, and have priority over 3.0 dbms. - if (class_exists('phpbb\db\driver\\' . $dbms)) + if (strpos($dbms, 'phpbb\db\driver') === false && class_exists('phpbb\db\driver\\' . $dbms)) { return 'phpbb\db\driver\\' . $dbms; } diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 373eb57934..8453da6e6e 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -146,37 +146,10 @@ function adm_page_footer($copyright_html = true) return; } - // Output page creation time - if (defined('DEBUG')) - { - $mtime = explode(' ', microtime()); - $totaltime = $mtime[0] + $mtime[1] - $starttime; - - if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report')) - { - $db->sql_report('display'); - } - - $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); - - if ($auth->acl_get('a_') && defined('DEBUG')) - { - if (function_exists('memory_get_peak_usage')) - { - if ($memory_usage = memory_get_peak_usage()) - { - $memory_usage = get_formatted_filesize($memory_usage); - - $debug_output .= ' | Peak Memory Usage: ' . $memory_usage; - } - } - - $debug_output .= ' | <a href="' . build_url() . '&explain=1">Explain</a>'; - } - } + phpbb_check_and_display_sql_report($request, $auth, $db); $template->assign_vars(array( - 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', + 'DEBUG_OUTPUT' => phpbb_generate_debug_output($db, $config, $auth, $user), 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', 'S_COPYRIGHT_HTML' => $copyright_html, 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'), diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 3a18644891..a8eeeab8bb 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -21,6 +21,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class service_collection extends \ArrayObject { /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** * Constructor * * @param ContainerInterface $container Container object @@ -31,6 +36,44 @@ class service_collection extends \ArrayObject } /** + * {@inheritdoc} + */ + public function getIterator() + { + return new service_collection_iterator($this->container, $this); + } + + // Because of a PHP issue we have to redefine offsetExists + // (even with a call to the parent): + // https://bugs.php.net/bug.php?id=66834 + // https://bugs.php.net/bug.php?id=67067 + // But it triggers a sniffer issue that we have to skip + // @codingStandardsIgnoreStart + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + return parent::offsetExists($index); + } + // @codingStandardsIgnoreEnd + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + $task = parent::offsetGet($index); + if ($task === null) + { + $task = $this->container->get($index); + $this->offsetSet($index, $task); + } + + return $task; + } + + /** * Add a service to the collection * * @param string $name The service name @@ -38,8 +81,6 @@ class service_collection extends \ArrayObject */ public function add($name) { - $task = $this->container->get($name); - - $this->offsetSet($name, $task); + $this->offsetSet($name, null); } } diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php new file mode 100644 index 0000000000..54aefca1f7 --- /dev/null +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -0,0 +1,87 @@ +<?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\di; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* Iterator which loads the services when they are requested +*/ +class service_collection_iterator extends \ArrayIterator +{ + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Construct an ArrayIterator for service_collection + * + * @param ContainerInterface $container Container object + * @param array $array The array or object to be iterated on. + * @param int $flags Flags to control the behaviour of the ArrayObject object. + * @see ArrayObject::setFlags() + */ + public function __construct(ContainerInterface $container, $array = array(), $flags = 0) + { + parent::__construct($array, $flags); + $this->container = $container; + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + $task = parent::offsetGet($index); + if ($task === null) + { + $task = $this->container->get($index); + $this->offsetSet($index, $task); + } + + return $task; + } + + // Because of a PHP issue we have to redefine offsetExists + // (even with a call to the parent): + // https://bugs.php.net/bug.php?id=66834 + // https://bugs.php.net/bug.php?id=67067 + // But it triggers a sniffer issue that we have to skip + // @codingStandardsIgnoreStart + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + parent::offsetExists($index); + } + // @codingStandardsIgnoreEnd + + /** + * {@inheritdoc} + */ + public function current() + { + $task = parent::current(); + if ($task === null) + { + $name = $this->key(); + $task = $this->container->get($name); + $this->offsetSet($name, $task); + } + + return $task; + } +} diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index c3539e76df..b787b624f6 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -574,6 +574,34 @@ class manager return $subscription_methods; } + + /** + * Get user's notification data + * + * @param int $user_id The user_id of the user to get the notifications for + * + * @return array User's notification + */ + protected function get_user_notifications($user_id) + { + $sql = 'SELECT method, notify, item_type + FROM ' . $this->user_notifications_table . ' + WHERE user_id = ' . (int) $user_id . ' + AND item_id = 0'; + + $result = $this->db->sql_query($sql); + $user_notifications = array(); + + while ($row = $this->db->sql_fetchrow($result)) + { + $user_notifications[$row['item_type']][] = $row; + } + + $this->db->sql_freeresult($result); + + return $user_notifications; + } + /** * Get global subscriptions (item_id = 0) * @@ -587,28 +615,23 @@ class manager $subscriptions = array(); - foreach ($this->get_subscription_types() as $group_name => $types) + $user_notifications = $this->get_user_notifications($user_id); + + foreach ($this->get_subscription_types() as $types) { foreach ($types as $id => $type) { - $sql = 'SELECT method, notify - FROM ' . $this->user_notifications_table . ' - WHERE user_id = ' . (int) $user_id . " - AND item_type = '" . $this->db->sql_escape($id) . "' - AND item_id = 0"; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - if (!$row) + + if (empty($user_notifications[$id])) { // No rows at all, default to '' $subscriptions[$id] = array(''); } else { - do + foreach ($user_notifications[$id] as $user_notification) { - if (!$row['notify']) + if (!$user_notification['notify']) { continue; } @@ -618,12 +641,9 @@ class manager $subscriptions[$id] = array(); } - $subscriptions[$id][] = $row['method']; + $subscriptions[$id][] = $user_notification['method']; } - while ($row = $this->db->sql_fetchrow($result)); } - - $this->db->sql_freeresult($result); } } diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 799dcc5e22..27ea8ddb44 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -71,6 +71,27 @@ class phpbb_notification_test extends phpbb_tests_notification_base public function test_subscriptions() { + $expected_subscriptions = array( + 'post' => array(''), + 'topic' => array(''), + 'quote' => array(''), + 'bookmark' => array(''), + 'test' => array(''), + 'pm' => array(''), + ); + + $subscriptions = $this->notifications->get_global_subscriptions(2); + + foreach ($expected_subscriptions as $item_type => $methods) + { + $this->assert_array_content_equals($methods, $subscriptions[$item_type]); + } + + foreach ($subscriptions as $item_type => $methods) + { + $this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]); + } + $this->notifications->delete_subscription('post', 0, '', 2); $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); |