From 4f65a003344a3aeec0c5f608e990c2860146d39e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 Aug 2012 18:40:23 +0200 Subject: [PATCH 001/244] [ticket/10875] Remove useless assignment from phpbb_cache_driver_memory. sql_save() no longer takes $query_result as a reference, thus this assignment is a no-op. PHPBB3-10875 --- phpBB/includes/cache/driver/memory.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index e0771ab1d3..bc08494c0c 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -334,8 +334,6 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); - $query_result = $query_id; - return $query_id; } From e28f0aa336e4b4d8965d1025d6e0d28e6b1fcde9 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 Aug 2012 18:42:21 +0200 Subject: [PATCH 002/244] [ticket/10875] Fix return value of phpbb_cache_driver_null::sql_save(). phpbb_cache_driver_null::sql_save() has to return $query_result as is instead of null. PHPBB3-10875 --- phpBB/includes/cache/driver/null.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php index df2c6c026f..687604d14f 100644 --- a/phpBB/includes/cache/driver/null.php +++ b/phpBB/includes/cache/driver/null.php @@ -109,6 +109,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base */ function sql_save($query, $query_result, $ttl) { + return $query_result; } /** From 59af4d68fc6f5455e156c5a192b35ca1ffe6872b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 Aug 2012 18:45:20 +0200 Subject: [PATCH 003/244] [ticket/10875] Fix phpbb_mock_cache::sql_save() to return $query_result. PHPBB3-10875 --- tests/mock/cache.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mock/cache.php b/tests/mock/cache.php index b64c92ea89..bc18ca066b 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -123,6 +123,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface } public function sql_save($query, $query_result, $ttl) { + return $query_result; } public function sql_exists($query_id) { From 4e83cd461ce2adb008889593abf352745d9adff6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 Aug 2012 18:46:08 +0200 Subject: [PATCH 004/244] [ticket/10875] Fix logic in phpbb_cache_driver_file::sql_save(). Previously (develop-olympus) $query_result was passed via reference into sql_save(). Now the (possibly changed) result is returned by value. Adjust logic to take this change into account correctly. PHPBB3-10875 --- phpBB/includes/cache/driver/file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index f64a9e3ea8..d45497af56 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -383,10 +383,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query)) { - $query_result = $query_id; + return $query_id; } - return $query_id; + return $query_result; } /** From 969369254f8860c7ab4cc5a1185f1e8ebf043b63 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 31 Oct 2012 18:14:24 -0400 Subject: [PATCH 005/244] [ticket/10875] Add comment about cache's sql_load() method. PHPBB3-10875 --- phpBB/includes/cache/driver/interface.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 847ba97262..669eb75f63 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -69,6 +69,12 @@ interface phpbb_cache_driver_interface /** * Load cached sql query + * + * @param string $query SQL query + * + * @return int|bool Query ID (integer) if cache contains a rowset + * for the specified query. + * False otherwise. */ public function sql_load($query); From 615d5ef628767ec127735fb4797171de3f886de2 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 11 Jun 2012 23:43:00 -0400 Subject: [PATCH 006/244] [ticket/10933] Add get_first_template_location. This localizes template_path to style resource locator. locate function on template will be removed in a subsequent commit. PHPBB3-10933 --- phpBB/includes/style/resource_locator.php | 27 +++++++++++++++++++++++ phpBB/includes/template/template.php | 16 +------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 8658fe4a36..e3bcf4d9c4 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -229,4 +229,31 @@ class phpbb_style_resource_locator implements phpbb_template_locator // search failed return $default_result; } + + /** + * Just like get_first_file_location but works on a list of templates, + * not files. + * + * The templates given in the first argument first are prepended with + * the template path (property in this class), then given to + * get_first_file_location for the rest of the processing. + */ + public function get_first_template_location($templates, $return_default = false, $return_full_path = true) + { + // add template path prefix + $files = array(); + if (is_string($templates)) + { + $files[] = $this->template_path . $templates; + } + else + { + foreach ($templates as $template) + { + $files[] = $this->template_path . $template; + } + } + + return $this->get_first_file_location($files, $return_default, $return_full_path); + } } diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 5d3ce4c82b..9e44c5609b 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -508,22 +508,8 @@ class phpbb_template */ public function locate($files, $return_default = false, $return_full_path = true) { - // add template path prefix - $templates = array(); - if (is_string($files)) - { - $templates[] = $this->template_path . $files; - } - else - { - foreach ($files as $file) - { - $templates[] = $this->template_path . $file; - } - } - // use resource locator to find files - return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + return $this->locator->get_first_template_location($files, $return_default, $return_full_path); } /** From 97e53103c3bb873389ea3046a3cd451ab5542ae1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 11 Jun 2012 23:49:10 -0400 Subject: [PATCH 007/244] [ticket/10933] Delete template_path from template class. template_path is now only present in style resource locator. PHPBB3-10933 --- phpBB/includes/template/template.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 9e44c5609b..6a4db1cf41 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -74,12 +74,6 @@ class phpbb_template */ private $locator; - /** - * Location of templates directory within style directories - * @var string - */ - public $template_path = 'template/'; - /** * Constructor. * @@ -95,7 +89,6 @@ class phpbb_template $this->config = $config; $this->user = $user; $this->locator = $locator; - $this->template_path = $this->locator->template_path; $this->context = $context; } From 6295b014d35890d60ccf422f5bb8228569e8ca3a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 11 Jun 2012 23:50:33 -0400 Subject: [PATCH 008/244] [ticket/10933] Delete template_path assignment. template_path is now only present in style resource locator and should not be assigned to. PHPBB3-10933 --- phpBB/includes/style/style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 36298b49ec..d8974bc516 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -126,7 +126,7 @@ class phpbb_style if ($template_path !== false) { - $this->template->template_path = $this->locator->template_path = $template_path; + $this->locator->template_path = $template_path; } return true; From 09794c6821a93023c19d6b74e8e5d0e835e37be6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 12 Jun 2012 00:02:30 -0400 Subject: [PATCH 009/244] [ticket/10933] Add mutators for template_path to style resource locator. template_path is now private. Change semantics of passing false for template path - now this resets template path to default which I think makes sense. PHPBB3-10933 --- phpBB/includes/style/resource_locator.php | 20 +++++++++++++++++++- phpBB/includes/style/style.php | 12 ++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index e3bcf4d9c4..a5bf595671 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -44,7 +44,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * style directory, such as admin control panel templates. * @var string */ - public $template_path = 'template/'; + private $template_path; /** * Map from root index to handles to source template file paths. @@ -63,6 +63,11 @@ class phpbb_style_resource_locator implements phpbb_template_locator */ private $filenames = array(); + public function __construct() + { + $this->set_default_template_path(); + } + /** * Sets the list of style paths * @@ -93,6 +98,19 @@ class phpbb_style_resource_locator implements phpbb_template_locator } } + /** + * Sets the location of templates directory within style directories. + */ + public function set_template_path($template_path) + { + $this->template_path = $template_path; + } + + public function set_default_template_path() + { + $this->template_path = 'template/'; + } + /** * {@inheritDoc} */ diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index d8974bc516..effd496fb9 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -110,7 +110,7 @@ class phpbb_style * * @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver" * @param array or string $paths Array of style paths, relative to current root directory - * @param string $template_path Path to templates, relative to style directory. False if path should not be changed. + * @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/). */ public function set_custom_style($name, $paths, $template_path = false) { @@ -122,12 +122,16 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; - if ($template_path !== false) { - $this->locator->template_path = $template_path; + $this->locator->set_template_path($template_path); } + else + { + $this->locator->set_default_template_path(); + } + + $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; return true; } From 0dd981071bd4a39480759db130ea9c6d80c37065 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 12 Jun 2012 00:06:13 -0400 Subject: [PATCH 010/244] [ticket/10933] Dispose of locate function in template class. It had no callers other than the test suite. PHPBB3-10933 --- phpBB/includes/style/resource_locator.php | 47 ++++++++++++++++++++ phpBB/includes/template/template.php | 54 ----------------------- 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index a5bf595671..37ea2fed40 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -249,12 +249,59 @@ class phpbb_style_resource_locator implements phpbb_template_locator } /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists, provided different file names are + * used for different templates. + * * Just like get_first_file_location but works on a list of templates, * not files. * * The templates given in the first argument first are prepended with * the template path (property in this class), then given to * get_first_file_location for the rest of the processing. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false */ public function get_first_template_location($templates, $return_default = false, $return_full_path = true) { diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 6a4db1cf41..f79c565e5c 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -451,60 +451,6 @@ class phpbb_template include($file); } - /** - * Obtains filesystem path for a template file. - * - * The simplest use is specifying a single template file as a string - * in the first argument. This template file should be a basename - * of a template file in the selected style, or its parent styles - * if template inheritance is being utilized. - * - * Note: "selected style" is whatever style the style resource locator - * is configured for. - * - * The return value then will be a path, relative to the current - * directory or absolute, to the template file in the selected style - * or its closest parent. - * - * If the selected style does not have the template file being searched, - * (and if inheritance is involved, none of the parents have it either), - * false will be returned. - * - * Specifying true for $return_default will cause the function to - * return the first path which was checked for existence in the event - * that the template file was not found, instead of false. - * This is the path in the selected style itself, not any of its - * parents. - * - * $files can be given an array of templates instead of a single - * template. When given an array, the function will try to resolve - * each template in the array to a path, and will return the first - * path that exists, or false if none exist. - * - * If $return_full_path is false, then instead of returning a usable - * path (when the template is found) only the template's basename - * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. - * - * @param string or array $files List of templates to locate. If there is only - * one template, $files can be a string to make code easier to read. - * @param bool $return_default Determines what to return if template does not - * exist. If true, function will return location where template is - * supposed to be. If false, function will return false. - * @param bool $return_full_path If true, function will return full path - * to template. If false, function will return template file name. - * This parameter can be used to check which one of set of template - * files is available. - * @return string or boolean Source template path if template exists or $return_default is - * true. False if template does not exist and $return_default is false - */ - public function locate($files, $return_default = false, $return_full_path = true) - { - // use resource locator to find files - return $this->locator->get_first_template_location($files, $return_default, $return_full_path); - } - /** * Include JS file * From b878d5daa9e7210c35b2d06e1680f22eb6701c6f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 12 Jun 2012 00:35:45 -0400 Subject: [PATCH 011/244] [ticket/10933] Update template locator test to use style resource locator. There is no reason for it to go through a template instance to test resource locator functionality. PHPBB3-10933 --- tests/template/template_locate_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index be9ae06809..851dcae8ea 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -62,7 +62,7 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c $this->setup_engine(); // Locate template - $result = $this->template->locate($files, $return_default, $return_full_path); + $result = $this->style_resource_locator->get_first_template_location($files, $return_default, $return_full_path); $this->assertSame($expected, $result); } } From bf66c47650682331454487c9db3999265f06df78 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 12 Jun 2012 01:32:49 -0400 Subject: [PATCH 012/244] [ticket/10933] Remaining documentation for added functions in resource locator PHPBB3-10933 --- phpBB/includes/style/resource_locator.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 37ea2fed40..6181653d4e 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -63,6 +63,11 @@ class phpbb_style_resource_locator implements phpbb_template_locator */ private $filenames = array(); + /** + * Constructor. + * + * Sets default template path to template/. + */ public function __construct() { $this->set_default_template_path(); @@ -100,12 +105,24 @@ class phpbb_style_resource_locator implements phpbb_template_locator /** * Sets the location of templates directory within style directories. + * + * The location must be a relative path, with a trailing slash. + * Typically it is one directory level deep, e.g. "template/". + * + * @param string $template_path Relative path to templates directory within style directories + * @return void */ public function set_template_path($template_path) { $this->template_path = $template_path; } + /** + * Sets the location of templates directory within style directories + * to the default, which is "template/". + * + * @return void + */ public function set_default_template_path() { $this->template_path = 'template/'; From 7fdab9c5d7d212f206cfdd79f5ccef097070a7f5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 12 Jun 2012 01:50:22 -0400 Subject: [PATCH 013/244] [ticket/10933] Prose for get_first_file_location. Also rewrite get_first_template_location prose a little to be less repetitive with get_first_file_location. PHPBB3-10933 --- phpBB/includes/style/resource_locator.php | 19 ++++++--- phpBB/includes/template/locator.php | 52 ++++++++++++++++++++--- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 6181653d4e..04beddb434 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -295,19 +295,26 @@ class phpbb_style_resource_locator implements phpbb_template_locator * each template in the array to a path, and will return the first * path that exists, or false if none exist. * + * If $files is an array and template inheritance is involved, first + * each of the files will be checked in the selected style, then each + * of the files will be checked in the immediate parent, and so on. + * * If $return_full_path is false, then instead of returning a usable * path (when the template is found) only the template's basename * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. + * specified in $files exists. Naturally more than one template must + * be given in $files. * - * Just like get_first_file_location but works on a list of templates, - * not files. - * - * The templates given in the first argument first are prepended with + * This function works identically to get_first_file_location except + * it operates on a list of templates, not files. Practically speaking, + * the templates given in the first argument first are prepended with * the template path (property in this class), then given to * get_first_file_location for the rest of the processing. * + * Templates given to this function can be relative paths for templates + * located in subdirectories of the template directories. The paths + * should be relative to the templates directory (template/ by default). + * * @param string or array $files List of templates to locate. If there is only * one template, $files can be a string to make code easier to read. * @param bool $return_default Determines what to return if template does not diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/template/locator.php index 01c79eec4e..42db91efb2 100644 --- a/phpBB/includes/template/locator.php +++ b/phpBB/includes/template/locator.php @@ -99,12 +99,54 @@ interface phpbb_template_locator public function get_source_file_for_handle($handle, $find_all = false); /** - * Locates source file path, accounting for styles tree and verifying that - * the path exists. + * Obtains a complete filesystem path for a file in a style. * - * Unlike previous functions, this function works without template handle - * and it can search for more than one file. If more than one file name is - * specified, it will return location of file that it finds first. + * This function traverses the style tree (selected style and + * its parents in order, if inheritance is being used) and finds + * the first file on the filesystem matching specified relative path, + * or the first of the specified paths if more than one path is given. + * + * This function can be used to determine filesystem path of any + * file under any style, with the consequence being that complete + * relative to the style directory path must be provided as an argument. + * + * In particular, this function can be used to locate templates + * and javascript files. + * + * For locating templates get_first_template_location should be used + * as it prepends the configured template path to the template basename. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the first existing file in the selected + * style or its closest parent. + * + * If the selected style does not have the file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Multiple files can be specified, in which case the first file in + * the list that can be found on the filesystem is returned. + * + * If multiple files are specified and inheritance is involved, + * first each of the specified files is checked in the selected style, + * then each of the specified files is checked in the immediate parent, + * etc. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is always a path in the selected style itself, not any of its + * parents. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the file is found) the file's path relative to the style + * directory will be returned. This is the same path as was given to + * the function as a parameter. This can be used to check which of the + * files specified in $files exists. Naturally this requires passing + * more than one file in $files. * * @param array $files List of files to locate. * @param bool $return_default Determines what to return if file does not From f7f21fa6927eab5fcff7d51d3618d2c48bd4e29d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 Nov 2012 14:34:52 +0100 Subject: [PATCH 014/244] [ticket/11186] Database unit tests fail on windows using sqlite2 The problem is, that we try to recreate the db and reconnect to it, while the old connection is still hold. To resolve this, we just drop all tables and recreate the tables instead of the hole db. PHPBB3-11186 --- .../phpbb_database_test_connection_manager.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 25e0972f42..a43215bcf2 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -166,12 +166,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { case 'sqlite': - if (file_exists($this->config['dbhost'])) - { - unlink($this->config['dbhost']); - } - break; - case 'firebird': $this->connect(); // Drop all of the tables From 9b2024a48e5607e2a9473546916663bb27cb43cc Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 11 Nov 2012 11:11:47 +0100 Subject: [PATCH 015/244] [ticket/11175] Add microdata to subsilver2 Add breadcrumb data to subsilver2 PHPBB3-11175 --- phpBB/styles/subsilver2/template/breadcrumbs.html | 3 ++- phpBB/styles/subsilver2/template/overall_header.html | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/phpBB/styles/subsilver2/template/breadcrumbs.html b/phpBB/styles/subsilver2/template/breadcrumbs.html index 73386ed851..49e31c0749 100644 --- a/phpBB/styles/subsilver2/template/breadcrumbs.html +++ b/phpBB/styles/subsilver2/template/breadcrumbs.html @@ -1,7 +1,8 @@ + diff --git a/phpBB/styles/subsilver2/template/overall_header.html b/phpBB/styles/subsilver2/template/overall_header.html index 8bedec4c9e..1c212969a4 100644 --- a/phpBB/styles/subsilver2/template/overall_header.html +++ b/phpBB/styles/subsilver2/template/overall_header.html @@ -195,6 +195,8 @@ function marklist(id, name, state)
+ +
From f72eaa0d95edf399df2c021303ecdb7566308606 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 11 Nov 2012 11:15:48 +0100 Subject: [PATCH 016/244] [ticket/11175] Add microdata to prosilver Add breadcrumb microdata to prosilver PHPBB3-11175 --- phpBB/styles/prosilver/template/overall_header.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 0900222d09..291b67812b 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -120,7 +120,8 @@
- {L_NEXT} - {L_PREVIOUS} + {L_NEXT} + {L_PREVIOUS} diff --git a/phpBB/styles/prosilver/template/mcp_reports.html b/phpBB/styles/prosilver/template/mcp_reports.html index f9a0ec4bd6..ea9a4edd6f 100644 --- a/phpBB/styles/prosilver/template/mcp_reports.html +++ b/phpBB/styles/prosilver/template/mcp_reports.html @@ -68,8 +68,8 @@
- {L_NEXT} - {L_PREVIOUS} + {L_NEXT} + {L_PREVIOUS} diff --git a/phpBB/styles/prosilver/template/mcp_whois.html b/phpBB/styles/prosilver/template/mcp_whois.html index 88d3269a71..41a825458d 100644 --- a/phpBB/styles/prosilver/template/mcp_whois.html +++ b/phpBB/styles/prosilver/template/mcp_whois.html @@ -4,11 +4,11 @@ diff --git a/phpBB/styles/prosilver/template/memberlist_body.html b/phpBB/styles/prosilver/template/memberlist_body.html index 273182ec3f..4ba0c5cb2a 100644 --- a/phpBB/styles/prosilver/template/memberlist_body.html +++ b/phpBB/styles/prosilver/template/memberlist_body.html @@ -143,8 +143,8 @@
- {L_PREVIOUS} - {L_NEXT} + {L_PREVIOUS} + {L_NEXT}
diff --git a/phpBB/styles/prosilver/template/message_body.html b/phpBB/styles/prosilver/template/message_body.html index fb6dfce35f..a844246055 100644 --- a/phpBB/styles/prosilver/template/message_body.html +++ b/phpBB/styles/prosilver/template/message_body.html @@ -8,7 +8,7 @@

{MESSAGE_TITLE}

{MESSAGE_TEXT}

-

{L_RETURN_TO_SEARCH_ADV}

+

{L_RETURN_TO_SEARCH_ADV}

diff --git a/phpBB/styles/prosilver/template/search_results.html b/phpBB/styles/prosilver/template/search_results.html index 136ca991b1..62b7c61eb3 100644 --- a/phpBB/styles/prosilver/template/search_results.html +++ b/phpBB/styles/prosilver/template/search_results.html @@ -6,9 +6,9 @@

{L_PHRASE_SEARCH_DISABLED}

-

{L_RETURN_TO}{L_COLON} {SEARCH_TOPIC}

+

{L_RETURN_TO}{L_COLON} {SEARCH_TOPIC}

-

{L_RETURN_TO_SEARCH_ADV}

+

{L_RETURN_TO_SEARCH_ADV}

@@ -131,7 +131,7 @@ @@ -150,8 +150,8 @@
- {L_PREVIOUS} - {L_NEXT} + {L_PREVIOUS} + {L_NEXT} diff --git a/phpBB/styles/prosilver/template/ucp_attachments.html b/phpBB/styles/prosilver/template/ucp_attachments.html index 8c93547388..478b14ab86 100644 --- a/phpBB/styles/prosilver/template/ucp_attachments.html +++ b/phpBB/styles/prosilver/template/ucp_attachments.html @@ -47,8 +47,8 @@
- {L_NEXT} - {L_PREVIOUS} + {L_NEXT} + {L_PREVIOUS} diff --git a/phpBB/styles/prosilver/template/ucp_pm_message_header.html b/phpBB/styles/prosilver/template/ucp_pm_message_header.html index 29e6a5a46b..c47f93f739 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_message_header.html +++ b/phpBB/styles/prosilver/template/ucp_pm_message_header.html @@ -18,7 +18,7 @@
- +

{S_TIMEZONE}

{ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} + {ICON_MOVE_UP} {ICON_MOVE_DOWN_DISABLED} {ICON_MOVE_UP_DISABLED} diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 12541cb057..4dfe00c5dd 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -10,12 +10,12 @@ var img_templates = { }; /** - * The following callbacks are for reording forums in acp_forums. forum_down - * is triggered when a forum is moved down, and forum_up is triggered when - * a forum is moved up. It moves the row up or down, and deactivates / + * The following callbacks are for reording items. row_down + * is triggered when a forum is moved down, and row_up is triggered when + * an item is moved up. It moves the row up or down, and deactivates / * activates any up / down icons that require it (the ones at the top or bottom). */ -phpbb.add_ajax_callback('forum_down', function() { +phpbb.add_ajax_callback('row_down', function() { var el = $(this), tr = el.parents('tr'); @@ -26,16 +26,19 @@ phpbb.add_ajax_callback('forum_down', function() { tr.next().find('.up').html(img_templates.up_disabled); + var down_img = img_templates.down.clone().attr('href', tr.next().attr('data-down')); + tr.next().find('.down').html(down_img); + phpbb.ajaxify({ selector: el.parents('span').siblings('.up').children('a'), - callback: 'forum_up', + callback: 'row_up', overlay: false }); } tr.insertAfter(tr.next()); - if (tr.is(':last-child')) + if (!tr.prev().is(':first-child') && tr.is(':last-child')) { el.replaceWith(img_templates.down_disabled); @@ -44,13 +47,17 @@ phpbb.add_ajax_callback('forum_down', function() { phpbb.ajaxify({ selector: tr.prev().find('.down').children('a'), - callback: 'forum_down', + callback: 'row_down', overlay: false }); } + else if (tr.is(':last-child')) + { + el.replaceWith(img_templates.down_disabled); + } }); -phpbb.add_ajax_callback('forum_up', function() { +phpbb.add_ajax_callback('row_up', function() { var el = $(this), tr = el.parents('tr'); @@ -61,16 +68,19 @@ phpbb.add_ajax_callback('forum_up', function() { tr.prev().find('.down').html(img_templates.down_disabled); + var up_img = img_templates.down.clone().attr('href', tr.prev().attr('data-up')); + tr.prev().find('.up').html(up_img); + phpbb.ajaxify({ selector: el.parents('span').siblings('.down').children('a'), - callback: 'forum_down', + callback: 'row_down', overlay: false }); } tr.insertBefore(tr.prev()); - if (tr.is(':first-child')) + if (!tr.next().is(':last-child') && tr.is(':first-child')) { el.replaceWith(img_templates.up_disabled); @@ -79,10 +89,14 @@ phpbb.add_ajax_callback('forum_up', function() { phpbb.ajaxify({ selector: tr.next().find('.up').children('a'), - callback: 'forum_up', + callback: 'row_up', overlay: false }); } + else if (tr.is(':first-child')) + { + el.replaceWith(img_templates.up_disabled); + } }); /** From e39947e57e8b39319bb34597d2fb0a706bd1bc44 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 23:30:29 +0100 Subject: [PATCH 025/244] [ticket/11198] Store the swapping partners in vars and simplify the logic PHPBB3-11198 --- phpBB/adm/style/ajax.js | 82 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 4dfe00c5dd..d780196173 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -11,92 +11,100 @@ var img_templates = { /** * The following callbacks are for reording items. row_down - * is triggered when a forum is moved down, and row_up is triggered when + * is triggered when an item is moved down, and row_up is triggered when * an item is moved up. It moves the row up or down, and deactivates / * activates any up / down icons that require it (the ones at the top or bottom). */ phpbb.add_ajax_callback('row_down', function() { var el = $(this), - tr = el.parents('tr'); + tr = el.parents('tr'), + tr_swap = tr.next(); + /** + * If the element was the first one, we have to: + * - Add the up-link to the row we moved + * - Remove the up-link on the next row + */ if (tr.is(':first-child')) { var up_img = img_templates.up.clone().attr('href', tr.attr('data-up')); - el.parents('span').siblings('.up').html(up_img); - - tr.next().find('.up').html(img_templates.up_disabled); - - var down_img = img_templates.down.clone().attr('href', tr.next().attr('data-down')); - tr.next().find('.down').html(down_img); + tr.find('.up').html(up_img); phpbb.ajaxify({ - selector: el.parents('span').siblings('.up').children('a'), + selector: tr.find('.up').children('a'), callback: 'row_up', overlay: false }); + + tr_swap.find('.up').html(img_templates.up_disabled); } - tr.insertAfter(tr.next()); + tr.insertAfter(tr_swap); - if (!tr.prev().is(':first-child') && tr.is(':last-child')) + /** + * As well as: + * - Remove the down-link on the moved row, if it is now the last row + * - Add the down-link to the next row, if it was the last row + */ + if (tr.is(':last-child')) { - el.replaceWith(img_templates.down_disabled); + tr.find('.down').html(img_templates.down_disabled); - var down_img = img_templates.down.clone().attr('href', tr.attr('data-down')); - tr.prev().find('.down').html(down_img); + var down_img = img_templates.down.clone().attr('href', tr_swap.attr('data-down')); + tr_swap.find('.down').html(down_img); phpbb.ajaxify({ - selector: tr.prev().find('.down').children('a'), + selector: tr_swap.find('.down').children('a'), callback: 'row_down', overlay: false }); } - else if (tr.is(':last-child')) - { - el.replaceWith(img_templates.down_disabled); - } }); phpbb.add_ajax_callback('row_up', function() { var el = $(this), - tr = el.parents('tr'); + tr = el.parents('tr'), + tr_swap = tr.prev(); + /** + * If the element was the last one, we have to: + * - Add the down-link to the row we moved + * - Remove the down-link on the next row + */ if (tr.is(':last-child')) { var down_img = img_templates.down.clone().attr('href', tr.attr('data-down')); - el.parents('span').siblings('.down').html(down_img); - - tr.prev().find('.down').html(img_templates.down_disabled); - - var up_img = img_templates.down.clone().attr('href', tr.prev().attr('data-up')); - tr.prev().find('.up').html(up_img); + tr.find('.down').html(down_img); phpbb.ajaxify({ - selector: el.parents('span').siblings('.down').children('a'), + selector: tr.find('.down').children('a'), callback: 'row_down', overlay: false }); + + tr_swap.find('.down').html(img_templates.down_disabled); } - tr.insertBefore(tr.prev()); + tr.insertBefore(tr_swap); - if (!tr.next().is(':last-child') && tr.is(':first-child')) + /** + * As well as: + * - Remove the up-link on the moved row, if it is now the first row + * - Add the up-link to the previous row, if it was the first row + */ + if (tr.is(':first-child')) { - el.replaceWith(img_templates.up_disabled); + tr.find('.up').html(img_templates.up_disabled); - var up_img = img_templates.up.clone().attr('href', tr.attr('data-up')); - tr.next().find('.up').html(up_img); + var up_img = img_templates.up.clone().attr('href', tr_swap.attr('data-up')); + tr_swap.find('.up').html(up_img); phpbb.ajaxify({ - selector: tr.next().find('.up').children('a'), + selector: tr_swap.find('.up').children('a'), callback: 'row_up', overlay: false }); } - else if (tr.is(':first-child')) - { - el.replaceWith(img_templates.up_disabled); - } }); /** From d982d432eb3bef8040b04d0514bc80c346faf618 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 14 Nov 2012 23:34:28 +0100 Subject: [PATCH 026/244] [ticket/11199] Cache purge does not remove dumped container PHPBB3-11199 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index b20c0064ea..699402af84 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -214,7 +214,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && + if (strpos($entry, 'container') === false && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 98ac02b161..8b4ecb6cbf 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -162,7 +162,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && + if (strpos($entry, 'container') === false && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && From 30e9d2d6009eac0fb6bde1c7de3325dcc3527d6c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 14 Nov 2012 19:06:32 -0500 Subject: [PATCH 027/244] [ticket/11199] Revert merge of 'marc1706/ticket/11199' into develop This reverts commit 303fc646adf9104d7c82cf8bcebbc8fc0d328624, reversing changes made to 9c28470ad7b45c10ce3a32065650e4b17f9f27ea. The correct fix should be to alter the container file name to start with container_ prefix. PHPBB3-11199 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 699402af84..b20c0064ea 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -214,7 +214,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') === false && + if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 8b4ecb6cbf..98ac02b161 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -162,7 +162,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') === false && + if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && From 73ce1a5a976f3f1634e9aeffa8fbe79378870c71 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 15 Nov 2012 01:56:33 +0100 Subject: [PATCH 028/244] [ticket/11199] Purge dumped container correctly on cache purge. This patch changes the dumped container suffix to a prefix instead which makes the existing code for purging 'cache/container_*' files work as intended. PHPBB3-11199 --- phpBB/includes/functions_container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 1763d1082a..9f84511439 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -133,5 +133,5 @@ function phpbb_create_dumped_container_unless_debug(array $extensions, array $pa function phpbb_container_filename($phpbb_root_path, $php_ext) { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); - return $phpbb_root_path . 'cache/' . $filename . '_container.' . $php_ext; + return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; } From a0cc2878a365e2f36728f3b102c131cd055f6874 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 15 Nov 2012 02:30:43 +0100 Subject: [PATCH 029/244] [ticket/11199] Match cache purge container files against container_* Previously it was matching against only container*, checking for the underscore is consistent with the other checks. PHPBB3-11199 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index b20c0064ea..32bdb1918a 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -214,7 +214,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && + if (strpos($entry, 'container_') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 98ac02b161..1ea9a3e9e7 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -162,7 +162,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && + if (strpos($entry, 'container_') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && From 31843ecd8c5b5d3b95d9d1775213fe22a93c8d2b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 15 Nov 2012 05:00:24 +0100 Subject: [PATCH 030/244] [ticket/11200] Make cache available during container construction Fixes fatal errors in the dbal. PHPBB3-11200 --- phpBB/includes/functions_container.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 1763d1082a..cbd0fe15b0 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -84,8 +84,11 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); + $GLOBALS['cache'] = $tmp_container->get('cache'); + $installed_exts = $tmp_container->get('ext.manager')->all_enabled(); + // Now pass the enabled extension paths into the ext compiler extension - $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); + $extensions[] = new phpbb_di_extension_ext($installed_exts); // Create the final container to be compiled and cached $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); From 4ab178f3efd2ec497081bc1b3e57e4566d2eee6d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:19:40 -0500 Subject: [PATCH 031/244] [ticket/11202] Add a heuristic function to check for response success. This tries to account for php sending fatal errors with 200 status code. PHPBB3-11202 --- .../phpbb_functional_test_case.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index d35913e415..09f52effec 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -182,7 +182,7 @@ class phpbb_functional_test_case extends phpbb_test_case $login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin')); $cookies = $this->cookieJar->all(); - + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); { @@ -229,4 +229,19 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + + /** + * Heuristic function to check that the response is success. + * + * When php decides to die with a fatal error, it still sends 200 OK + * status code. This assertion tries to catch that. + * + * @param string $message Optional failure message + */ + public function assert_response_success($message = null) + { + $this->assertEquals(200, $this->client->getResponse()->getStatus()); + $content = $this->client->getResponse()->getContent(); + $this->assertNotContains('Fatal error:', $content); + } } From dc61fd1091d7cf7994eb1559691c4dfabec740f5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:20:07 -0500 Subject: [PATCH 032/244] [ticket/11202] Check response success before content assertions. This does not change tests that perform requests which are either clearly not supposed to succeed or are a gray area. PHPBB3-11202 --- tests/functional/browse_test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 26c18c4c1f..b5748059c6 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -15,18 +15,21 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case public function test_index() { $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { $crawler = $this->request('GET', 'viewforum.php?f=2'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } From af7ab2d3ac287db1a2c9ed623e21393cb429203f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:40:29 -0500 Subject: [PATCH 033/244] [ticket/11202] Custom message does not make sense here, delete it. PHPBB3-11202 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 09f52effec..de04783bce 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -236,9 +236,9 @@ class phpbb_functional_test_case extends phpbb_test_case * When php decides to die with a fatal error, it still sends 200 OK * status code. This assertion tries to catch that. * - * @param string $message Optional failure message + * @return null */ - public function assert_response_success($message = null) + public function assert_response_success() { $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); From f2cffd6a6ce72fd5d3a60c734623ea3c1f051071 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:50:04 -0500 Subject: [PATCH 034/244] [ticket/11200] Add a reminder comment. PHPBB3-11200 --- phpBB/includes/functions_container.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index cbd0fe15b0..843207db84 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -84,6 +84,8 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); + // XXX stop writing to global $cache when + // http://tracker.phpbb.com/browse/PHPBB3-11203 is fixed $GLOBALS['cache'] = $tmp_container->get('cache'); $installed_exts = $tmp_container->get('ext.manager')->all_enabled(); From 132163d4ec2c7758afb82071af2b3c68965e2c4d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Nov 2012 16:26:36 +0100 Subject: [PATCH 035/244] [ticket/11198] Remove additional asterix as /** is doc-block only PHPBB3-11198 --- phpBB/adm/style/ajax.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index d780196173..a3a77df89b 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -20,7 +20,7 @@ phpbb.add_ajax_callback('row_down', function() { tr = el.parents('tr'), tr_swap = tr.next(); - /** + /* * If the element was the first one, we have to: * - Add the up-link to the row we moved * - Remove the up-link on the next row @@ -41,7 +41,7 @@ phpbb.add_ajax_callback('row_down', function() { tr.insertAfter(tr_swap); - /** + /* * As well as: * - Remove the down-link on the moved row, if it is now the last row * - Add the down-link to the next row, if it was the last row @@ -66,7 +66,7 @@ phpbb.add_ajax_callback('row_up', function() { tr = el.parents('tr'), tr_swap = tr.prev(); - /** + /* * If the element was the last one, we have to: * - Add the down-link to the row we moved * - Remove the down-link on the next row @@ -87,7 +87,7 @@ phpbb.add_ajax_callback('row_up', function() { tr.insertBefore(tr_swap); - /** + /* * As well as: * - Remove the up-link on the moved row, if it is now the first row * - Add the up-link to the previous row, if it was the first row From ec06d5c5d9f23b6419f048b885b689aa0ab4b351 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:18:55 -0500 Subject: [PATCH 036/244] [ticket/11204] Reindent. PHPBB3-11204 --- .../phpbb_functional_test_case.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8a329d43b1..16e1ccaff9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -332,17 +332,17 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } - /** - * assertContains for language strings - * - * @param string $needle Search string - * @param string $haystack Search this - * @param string $message Optional failure message - */ - public function assertContainsLang($needle, $haystack, $message = null) - { - $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); - } + /** + * assertContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertContainsLang($needle, $haystack, $message = null) + { + $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } /** * Heuristic function to check that the response is success. From 8917b31e31e117e9ded9558a065986bfb4a672ac Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 08:20:07 -0500 Subject: [PATCH 037/244] [ticket/11202] Check response success before content assertions. This does not change tests that perform requests which are either clearly not supposed to succeed or are a gray area. PHPBB3-11202 --- tests/functional/extension_controller_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index e9409d9d3f..d92a830365 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -82,6 +82,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foobar'); $crawler = $this->request('GET', 'index.php?ext=foobar'); + $this->assert_response_success(); $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); $this->phpbb_extension_manager->purge('foobar'); } @@ -94,6 +95,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'index.php?ext=foo/bar'); + $this->assert_response_success(); $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } From 5d0796624f6bb88e6e57551158e911703ac6f62c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 17:45:00 -0500 Subject: [PATCH 038/244] [ticket/11205] Fix merge conflict in readme.html. PHPBB3-11205 --- phpBB/docs/README.html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index 0e0d3b14fd..164c4a2f55 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -324,11 +324,7 @@

Please remember that running any application on a developmental version of PHP can lead to strange/unexpected results which may appear to be bugs in the application (which may not be true). Therefore we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a developmental version of PHP please check any bugs you find on a system running a stable release before submitting.

-<<<<<<< HEAD -

This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.

-======= -

This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 7.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 4.3.3 to 5.4.x without problem.

->>>>>>> develop-olympus +

This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.

7.i. Notice on PHP security issues

From d061a5abf844713f6d648ea66454c29667e21c93 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 16 Nov 2012 00:34:08 +0100 Subject: [PATCH 039/244] [ticket/11206] Remove includes to non-existent files from download/file.php This makes avatars work again. PHPBB3-11206 --- phpBB/download/file.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 79f53245b9..85f5d11504 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -42,8 +42,6 @@ if (isset($_GET['avatar'])) } require($phpbb_root_path . 'includes/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); - require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); From c15b98999ef1ba26531e3d6e20695a8f2672f5a4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 15 Nov 2012 23:57:55 -0500 Subject: [PATCH 040/244] [ticket/11192] Add tests. PHPBB3-11192 --- .../functions/get_formatted_filesize_test.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/functions/get_formatted_filesize_test.php diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php new file mode 100644 index 0000000000..1cc7ddf9ec --- /dev/null +++ b/tests/functions/get_formatted_filesize_test.php @@ -0,0 +1,50 @@ +assertEquals($expected, $output); + } +} From b7ec639945a4667508e4a3d1f8ac73da94809b21 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 07:43:24 +0100 Subject: [PATCH 041/244] [ticket/11192] Also test powers of 10 / 1000. PHPBB3-11192 --- tests/functions/get_formatted_filesize_test.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index 1cc7ddf9ec..802f82d126 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -21,6 +21,13 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case array(1073741824, '1 GIB'), array(1099511627776, '1 TIB'), + // exact powers of 10 + array(1000, '1000 BYTES'), + array(1000000, '976.56 KIB'), + array(1000000000, '953.67 MIB'), + array(1000000000000, '931.32 GIB'), + array(100000000000000, '90.95 TIB'), + array(0, '0 BYTES'), array(2, '2 BYTES'), array(-2, '-2 BYTES'), From 09c8c58a5c9602a665519586b75ae3e9831367c8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 08:00:12 +0100 Subject: [PATCH 042/244] [ticket/11192] Also test strings, e.g. sums returned by the database. PHPBB3-11192 --- tests/functions/get_formatted_filesize_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index 802f82d126..85b06b723d 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -54,4 +54,14 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case $this->assertEquals($expected, $output); } + + /** + * @dataProvider get_formatted_filesize_test_data + */ + public function test_get_formatted_filesize_string($input, $expected) + { + $output = get_formatted_filesize("$input"); + + $this->assertEquals($expected, $output); + } } From c7f701c1e71caa416217b5438274785f3ab0c2af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Nov 2012 11:41:39 +0100 Subject: [PATCH 043/244] [ticket/11209] Clone disable moving images to allow multiple per page The disable images need to be clone rather then moved, in order to allow multiple disable images per page. We do not have such a case at the moment but it will be required for the new teampage/legend ACP section. PHPBB3-11209 --- phpBB/adm/style/ajax.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index a3a77df89b..3ccb368665 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -36,7 +36,7 @@ phpbb.add_ajax_callback('row_down', function() { overlay: false }); - tr_swap.find('.up').html(img_templates.up_disabled); + tr_swap.find('.up').html(img_templates.up_disabled.clone()); } tr.insertAfter(tr_swap); @@ -48,7 +48,7 @@ phpbb.add_ajax_callback('row_down', function() { */ if (tr.is(':last-child')) { - tr.find('.down').html(img_templates.down_disabled); + tr.find('.down').html(img_templates.down_disabled.clone()); var down_img = img_templates.down.clone().attr('href', tr_swap.attr('data-down')); tr_swap.find('.down').html(down_img); @@ -82,7 +82,7 @@ phpbb.add_ajax_callback('row_up', function() { overlay: false }); - tr_swap.find('.down').html(img_templates.down_disabled); + tr_swap.find('.down').html(img_templates.down_disabled.clone()); } tr.insertBefore(tr_swap); @@ -94,7 +94,7 @@ phpbb.add_ajax_callback('row_up', function() { */ if (tr.is(':first-child')) { - tr.find('.up').html(img_templates.up_disabled); + tr.find('.up').html(img_templates.up_disabled.clone()); var up_img = img_templates.up.clone().attr('href', tr_swap.attr('data-up')); tr_swap.find('.up').html(up_img); From 4e3a42f59fa32fb1a3e14cff959b19576e5ba7cf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 08:20:58 +0100 Subject: [PATCH 044/244] [ticket/11192] Test strings not converted to int/float before. PHPBB3-11192 --- .../functions/get_formatted_filesize_test.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index 85b06b723d..88866f90ac 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -45,6 +45,40 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case ); } + public function get_formatted_filesize_test_data_string() + { + return array( + // exact powers of 2 + array('1', '1 BYTES'), + array('1024', '1 KIB'), + array('1048576', '1 MIB'), + array('1073741824', '1 GIB'), + array('1099511627776', '1 TIB'), + + // exact powers of 10 + array('1000', '1000 BYTES'), + array('1000000', '976.56 KIB'), + array('1000000000', '953.67 MIB'), + array('1000000000000', '931.32 GIB'), + array('100000000000000', '90.95 TIB'), + + array('0', '0 BYTES'), + array('2', '2 BYTES'), + array('-2', '-2 BYTES'), + + array('1023', '1023 BYTES'), + array('1025', '1 KIB'), + array('-1023', '-1023 BYTES'), + array('-1025', '-1025 BYTES'), + + array('1048575', '1024 KIB'), + + // large negatives + array('-1073741824', '-1073741824 BYTES'), + array('-1099511627776', '-1099511627776 BYTES'), + ); + } + /** * @dataProvider get_formatted_filesize_test_data */ @@ -56,11 +90,11 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case } /** - * @dataProvider get_formatted_filesize_test_data + * @dataProvider get_formatted_filesize_test_data_string */ public function test_get_formatted_filesize_string($input, $expected) { - $output = get_formatted_filesize("$input"); + $output = get_formatted_filesize($input); $this->assertEquals($expected, $output); } From 7cbd440e7a69eb836eb9d58800f1c535d41b83ab Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 08:28:35 +0100 Subject: [PATCH 045/244] [ticket/11192] Mark negative byte numbers as unsupported. PHPBB3-11192 --- phpBB/includes/functions.php | 2 +- tests/functions/get_formatted_filesize_test.php | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 33545ab845..8688ba3f7e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -289,7 +289,7 @@ function phpbb_gmgetdate($time = false) /** * Return formatted string for filesizes * -* @param int $value filesize in bytes +* @param int $value filesize in bytes (non-negative number) * @param bool $string_only true if language string should be returned * @param array $allowed_units only allow these units (data array indexes) * diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index 88866f90ac..c4793e8073 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -30,18 +30,10 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case array(0, '0 BYTES'), array(2, '2 BYTES'), - array(-2, '-2 BYTES'), array(1023, '1023 BYTES'), array(1025, '1 KIB'), - array(-1023, '-1023 BYTES'), - array(-1025, '-1025 BYTES'), - array(1048575, '1024 KIB'), - - // large negatives - array(-1073741824, '-1073741824 BYTES'), - array(-1099511627776, '-1099511627776 BYTES'), ); } @@ -64,18 +56,10 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case array('0', '0 BYTES'), array('2', '2 BYTES'), - array('-2', '-2 BYTES'), array('1023', '1023 BYTES'), array('1025', '1 KIB'), - array('-1023', '-1023 BYTES'), - array('-1025', '-1025 BYTES'), - array('1048575', '1024 KIB'), - - // large negatives - array('-1073741824', '-1073741824 BYTES'), - array('-1099511627776', '-1099511627776 BYTES'), ); } From efd6f1df63c24ed2947bccb863bb92c2346bf697 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 08:29:57 +0100 Subject: [PATCH 046/244] [ticket/11192] Update $value parameter description to support other types. PHPBB3-11192 --- phpBB/includes/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8688ba3f7e..6e661228b7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -289,7 +289,8 @@ function phpbb_gmgetdate($time = false) /** * Return formatted string for filesizes * -* @param int $value filesize in bytes (non-negative number) +* @param mixed $value filesize in bytes +* (non-negative number; int, float or string) * @param bool $string_only true if language string should be returned * @param array $allowed_units only allow these units (data array indexes) * From 8851f9589a5295d569316e76b366f1b16f1a9a96 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 16 Nov 2012 16:20:55 +0100 Subject: [PATCH 047/244] [ticket/11192] Merge dataProvider arrays because the test is the same now. PHPBB3-11192 --- tests/functions/get_formatted_filesize_test.php | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php index c4793e8073..96ea2be132 100644 --- a/tests/functions/get_formatted_filesize_test.php +++ b/tests/functions/get_formatted_filesize_test.php @@ -34,12 +34,8 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case array(1023, '1023 BYTES'), array(1025, '1 KIB'), array(1048575, '1024 KIB'), - ); - } - public function get_formatted_filesize_test_data_string() - { - return array( + // String values // exact powers of 2 array('1', '1 BYTES'), array('1024', '1 KIB'), @@ -72,14 +68,4 @@ class phpbb_get_formatted_filesize_test extends phpbb_test_case $this->assertEquals($expected, $output); } - - /** - * @dataProvider get_formatted_filesize_test_data_string - */ - public function test_get_formatted_filesize_string($input, $expected) - { - $output = get_formatted_filesize($input); - - $this->assertEquals($expected, $output); - } } From ca09eb94e3e79ecae848e22b175f9a77b2e083af Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 14:38:53 -0500 Subject: [PATCH 048/244] [ticket/11211] Fix typo in phpbb_realpath() method name PHPBB3-11211 --- phpBB/includes/di/extension/ext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php index e76c543ee1..7d9b433751 100644 --- a/phpBB/includes/di/extension/ext.php +++ b/phpBB/includes/di/extension/ext.php @@ -49,7 +49,7 @@ class phpbb_di_extension_ext extends Extension { if (file_exists($path . '/config/services.yml')) { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_real_path($path . '/config'))); + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($path . '/config'))); $loader->load('services.yml'); } } From 06158693c7b846518abfe9d72491fc7376e457f3 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 19 Oct 2012 19:54:19 -0400 Subject: [PATCH 049/244] [feature/controller] Implement a front controller PHPBB3-10864 --- phpBB/.htaccess | 11 +- phpBB/app.php | 29 ++++ phpBB/common.php | 9 +- phpBB/composer.json | 1 + phpBB/composer.lock | 62 +++++++- phpBB/config/routing.yml | 9 ++ phpBB/config/services.yml | 63 ++++++++ phpBB/includes/controller/helper.php | 142 ++++++++++++++++++ phpBB/includes/controller/provider.php | 94 ++++++++++++ phpBB/includes/controller/resolver.php | 123 +++++++++++++++ .../includes/controller/route_collection.php | 36 +++++ phpBB/includes/functions.php | 35 ++++- phpBB/includes/template/template.php | 19 ++- phpBB/index.php | 40 +---- phpBB/language/en/app.php | 59 ++++++++ phpBB/web.config | 12 ++ tests/controller/config/routing.yml | 3 + tests/controller/config/services.yml | 3 + tests/controller/controller_test.php | 75 +++++++++ tests/controller/ext/foo/config/routing.yml | 3 + tests/controller/ext/foo/config/services.yml | 3 + tests/controller/ext/foo/controller.php | 23 +++ tests/controller/includes/controller/foo.php | 23 +++ 23 files changed, 818 insertions(+), 59 deletions(-) create mode 100644 phpBB/app.php create mode 100644 phpBB/config/routing.yml create mode 100644 phpBB/includes/controller/helper.php create mode 100644 phpBB/includes/controller/provider.php create mode 100644 phpBB/includes/controller/resolver.php create mode 100644 phpBB/includes/controller/route_collection.php create mode 100644 phpBB/language/en/app.php create mode 100644 tests/controller/config/routing.yml create mode 100644 tests/controller/config/services.yml create mode 100644 tests/controller/controller_test.php create mode 100644 tests/controller/ext/foo/config/routing.yml create mode 100644 tests/controller/ext/foo/config/services.yml create mode 100644 tests/controller/ext/foo/controller.php create mode 100644 tests/controller/includes/controller/foo.php diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 474f9774c2..61bd4249e3 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,12 +1,17 @@ + +RewriteEngine on + # # Uncomment the statement below if you want to make use of # HTTP authentication and it does not already work. # This could be required if you are for example using PHP via Apache CGI. # -# -#RewriteEngine on #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] -# + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ app.php [QSA,L] + Order Allow,Deny diff --git a/phpBB/app.php b/phpBB/app.php new file mode 100644 index 0000000000..9ff9069104 --- /dev/null +++ b/phpBB/app.php @@ -0,0 +1,29 @@ +session_begin(); +$auth->acl($user->data); +$user->setup('app'); + +$http_kernel = $phpbb_container->get('http_kernel'); +$response = $http_kernel->handle($symfony_request); +$response->send(); +$http_kernel->terminate($symfony_request, $response); diff --git a/phpBB/common.php b/phpBB/common.php index c4237dfcf5..986f0a8839 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,9 +8,7 @@ * Minimum Requirement: PHP 5.3.3 */ -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\HttpFoundation\Request; /** */ @@ -106,6 +104,11 @@ $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); +// Instantiate the Symfony Request object +// This must be done before phpbb_request +// because otherwise globals are disabled +$symfony_request = Request::createFromGlobals(); + // Instantiate some basic classes $phpbb_dispatcher = $phpbb_container->get('dispatcher'); $request = $phpbb_container->get('request'); diff --git a/phpBB/composer.json b/phpBB/composer.json index 380bdc367c..5a03e68f73 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -5,6 +5,7 @@ "symfony/dependency-injection": "2.1.*", "symfony/event-dispatcher": "2.1.*", "symfony/http-kernel": "2.1.*", + "symfony/routing": "2.1.*", "symfony/yaml": "2.1.*" }, "require-dev": { diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 69e4a2b4b8..62ece6d505 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,5 +1,5 @@ { - "hash": "407cc89f4bb0e409146c863dee51b0ae", + "hash": "efb4768ba71d7cd2c84baa0610d84067", "packages": [ { "name": "symfony/config", @@ -272,6 +272,64 @@ "description": "Symfony HttpKernel Component", "homepage": "http://symfony.com" }, + { + "name": "symfony/routing", + "version": "v2.1.3", + "target-dir": "Symfony/Component/Routing", + "source": { + "type": "git", + "url": "https://github.com/symfony/Routing", + "reference": "v2.1.3" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Routing/zipball/v2.1.3", + "reference": "v2.1.3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/config": "2.1.*", + "symfony/yaml": "2.1.*", + "symfony/http-kernel": "2.1.*", + "doctrine/common": ">=2.2,<2.4-dev" + }, + "suggest": { + "symfony/config": "2.1.*", + "symfony/yaml": "2.1.*", + "doctrine/common": ">=2.2,<2.4-dev" + }, + "time": "2012-10-26 02:26:42", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Routing": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Routing Component", + "homepage": "http://symfony.com" + }, { "name": "symfony/yaml", "version": "v2.1.3", @@ -331,7 +389,7 @@ }, "dist": { "type": "zip", - "url": "https://github.com/fabpot/Goutte/zipball/f2940f9c7c1f409159f5e9f512e575946c5cff48", + "url": "https://github.com/fabpot/Goutte/archive/f2940f9c7c1f409159f5e9f512e575946c5cff48.zip", "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48", "shasum": "" }, diff --git a/phpBB/config/routing.yml b/phpBB/config/routing.yml new file mode 100644 index 0000000000..f6f728fa47 --- /dev/null +++ b/phpBB/config/routing.yml @@ -0,0 +1,9 @@ +# Structure: +# +# foo_controller: +# pattern: /foo +# defaults: { _controller: foo_sevice:method } +# +# The above will be accessed via app.php/foo and it will instantiate the +# "foo_service" service and call the "method" method. +# diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 20aa0546d5..650869d1e6 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -44,6 +44,27 @@ services: - @cache.driver - %tables.config% + controller.helper: + class: phpbb_controller_helper + arguments: + - @service_container + + controller.resolver: + class: phpbb_controller_resolver + arguments: + - @user + - @service_container + - @ext.finder + + controller.route_collection: + class: phpbb_controller_route_collection + arguments: + - @ext.finder + - @controller.provider + + controller.provider: + class: phpbb_controller_provider + cron.task_collection: class: phpbb_di_service_collection arguments: @@ -92,10 +113,46 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver +<<<<<<< HEAD +======= + + ext.finder: + class: phpbb_extension_finder + arguments: + - @ext.manager + - %core.root_path% + - @cache.driver + - .%core.php_ext% + - _ext_finder + + http_kernel: + class: Symfony\Component\HttpKernel\HttpKernel + arguments: + - @dispatcher + - @controller.resolver + + kernel_event_subscriber: + class: phpbb_event_kernel_subscriber + arguments: + - @template + - @user + tags: + - { name: kernel.event_subscriber } +>>>>>>> 719171f... [feature/controller] Implement a front controller request: class: phpbb_request + request.context: + class: Symfony\Component\Routing\RequestContext + + router_listener: + class: Symfony\Component\HttpKernel\EventListener\RouterListener + arguments: + - @url_matcher + tags: + - { name: kernel.event_subscriber } + style: class: phpbb_style arguments: @@ -132,5 +189,11 @@ services: template_context: class: phpbb_template_context + url_matcher: + class: Symfony\Component\Routing\Matcher\UrlMatcher + arguments: + - @controller.route_collection + - @request.context + user: class: phpbb_user diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php new file mode 100644 index 0000000000..1998ea6733 --- /dev/null +++ b/phpBB/includes/controller/helper.php @@ -0,0 +1,142 @@ +container = $container; + + $this->template = $this->container->get('template'); + $this->phpbb_root_path = $this->container->getParameter('core.root_path'); + $this->php_ext = $this->container->getParameter('core.php_ext'); + } + + /** + * Automate setting up the page and creating the response object. + * + * @param string $handle The template handle to render + * @param string $page_title The title of the page to output + * @param int $status_code The status code to be sent to the page header + * @return Response object containing rendered page + */ + public function render($template_file, $page_title = '', $status_code = 200) + { + if (!function_exists('page_header')) + { + include("{$this->phpbb_root_path}includes/functions.{$this->php_ext}"); + } + + page_header($page_title); + + $this->template->set_filenames(array( + 'body' => $template_file, + )); + + page_footer(true, false, false); + + return new Response($this->template->return_display('body'), $status_code); + } + + /** + * Easily generate a URL + * + * @param array $url_parts Each array element is a 'folder' + * i.e. array('my', 'ext') maps to ./app.php/my/ext + * @param mixed $query The Query string, passed directly into the second + * argument of append_sid() + * @return string A URL that has already been run through append_sid() + */ + public function url(array $url_parts, $query = '') + { + return append_sid($this->phpbb_root_path . $this->url_base . implode('/', $url_parts), $query); + } + + /** + * Set base to prepend to urls generated by url() + * This allows extensions to have a certain 'directory' under which + * all their pages are served, but not have to type it every time + * + * @param array $url_parts Each array element is a 'folder' + * i.e. array('my', 'ext') maps to ./app.php/my/ext + * @return null + */ + public function set_url_base(array $url_parts) + { + $this->url_base = !empty($url_parts) ? implode('/', $url_parts) . '/' : ''; + } + + /** + * Output an error, effectively the same thing as trigger_error + * + * @param string $code The error code (e.g. 404, 500, 503, etc.) + * @param string $message The error message + * @return Response A Reponse instance + */ + public function error($code = 500, $message = '') + { + $this->template->assign_vars(array( + 'MESSAGE_TEXT' => $message, + 'MESSAGE_TITLE' => $this->container->get('user')->lang('INFORMATION'), + )); + + return $this->render('message_body.html', $this->container->get('user')->lang('INFORMATION'), $code); + } +} diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php new file mode 100644 index 0000000000..25deedb5d1 --- /dev/null +++ b/phpBB/includes/controller/provider.php @@ -0,0 +1,94 @@ +set_paths($routing_paths); + } + + /** + * Locate paths containing routing files + * This sets an internal property but does not return the paths. + * + * @return The current instance of this object for method chaining + */ + public function get_paths(phpbb_extension_finder $finder) + { + // We hardcode the path to the core config directory + // because the finder cannot find it + $this->set_paths(array_merge(array('config'), array_map('dirname', array_keys($finder + ->directory('config') + ->prefix('routing') + ->suffix('yml') + ->find() + )))); + + return $this; + } + + /** + * Set the $routing_paths property with a given list of paths + * + * @return The current instance of this object for method chaining + */ + public function set_paths(array $paths) + { + $this->routing_paths = $paths; + + return $this; + } + + /** + * Get a list of controllers and return it + * + * @param string $base_path Base path to prepend to file paths + * @return array Array of controllers and their route information + */ + public function find($base_path = '') + { + $routes = new RouteCollection; + foreach ($this->routing_paths as $path) + { + $loader = new YamlFileLoader(new FileLocator($base_path . $path)); + $routes->addCollection($loader->load('routing.yml')); + } + + return $routes; + } +} diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php new file mode 100644 index 0000000000..bf9ce3330d --- /dev/null +++ b/phpBB/includes/controller/resolver.php @@ -0,0 +1,123 @@ +user = $user; + $this->container = $container; + } + + /** + * Load a controller callable + * + * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object + * @return bool|Callable Callable or false + * @throws RuntimeException + */ + public function getController(Request $request) + { + $controller = $request->attributes->get('_controller'); + + if (!$controller) + { + throw new RuntimeException($this->user->lang['CONTROLLER_NOT_SPECIFIED']); + } + + // Require a method name along with the service name + if (stripos($controller, ':') === false) + { + throw new RuntimeException($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); + } + + list($service, $method) = explode(':', $controller); + + if (!$this->container->has($service)) + { + throw new RuntimeException($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); + } + + $controller_object = $this->container->get($service); + + return array($controller_object, $method); + } + + /** + * Dependencies should be specified in the service definition and can be + * then accessed in __construct(). Arguments are sent through the URL path + * and should match the parameters of the method you are using as your + * controller. + * + * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object + * @param string $controller Controller class name + * @return bool False + */ + public function getArguments(Request $request, $controller) + { + // At this point, $controller contains the object and method name + list($object, $method) = $controller; + $mirror = new ReflectionMethod($object, $method); + + $arguments = array(); + $parameters = $mirror->getParameters(); + $attributes = $request->attributes->all(); + foreach ($parameters as $param) + { + if (array_key_exists($param->name, $attributes)) + { + $arguments[] = $attributes[$param->name]; + } + else if ($param->isDefaultValueAvailable()) + { + $arguments[] = $param->getDefaultValue(); + } + else + { + throw new RuntimeException($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + } + } + + return $arguments; + } +} diff --git a/phpBB/includes/controller/route_collection.php b/phpBB/includes/controller/route_collection.php new file mode 100644 index 0000000000..e6c7d3b543 --- /dev/null +++ b/phpBB/includes/controller/route_collection.php @@ -0,0 +1,36 @@ +addCollection($provider->get_paths($finder)->find()); + } +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3a5b100515..fb05b74cd3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2335,7 +2335,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_root_path, $config, $symfony_request; if ($params === '' || (is_array($params) && empty($params))) { @@ -2343,6 +2343,20 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } + // Make sure we have a Symfony Request object; tests do not have one + // unless they need it. + if ($symfony_request) + { + // Correct the path when we are accessing it through a controller + // This simply rewrites the value given by $phpbb_root_path to the + // script_path in config. + $path_info = $symfony_request->getPathInfo(); + if (!empty($path_info) && $path_info != '/') + { + $url = $config['script_path'] . '/' . substr($url, strlen($phpbb_root_path)); + } + } + $append_sid_overwrite = false; /** @@ -5039,7 +5053,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // Determine board url - we may need it later $board_url = generate_board_url() . '/'; - $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; + $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $config['script_path'] . '/'; // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; @@ -5216,8 +5230,12 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 /** * Generate page footer +* +* @param bool $run_cron Whether or not to run the cron +* @param bool $display_template Whether or not to display the template +* @param bool $exit_handler Whether or not to run the exit_handler() */ -function page_footer($run_cron = true) +function page_footer($run_cron = true, $display_template = true, $exit_handler = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; global $request, $phpbb_dispatcher; @@ -5312,10 +5330,17 @@ function page_footer($run_cron = true) } } - $template->display('body'); + if ($display_template) + { + $template->display('body'); + } garbage_collection(); - exit_handler(); + + if ($exit_handler) + { + exit_handler(); + } } /** diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 8a7dc6b2f3..a48e8459d5 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -224,15 +224,9 @@ class phpbb_template */ public function assign_display($handle, $template_var = '', $return_content = true) { - ob_start(); - $result = $this->display($handle); - $contents = ob_get_clean(); - if ($result === false) - { - return false; - } + $contents = $this->return_display($handle); - if ($return_content) + if ($return_content === true || empty($template_var) || $contents === false) { return $contents; } @@ -242,6 +236,15 @@ class phpbb_template return true; } + public function return_display($handle) + { + ob_start(); + $result = $this->display($handle); + $contents = ob_get_clean(); + + return $result === false ? $result : $contents; + } + /** * Obtains a template renderer for a template identified by specified * handle. The template renderer can display the template later. diff --git a/phpBB/index.php b/phpBB/index.php index 66e1b2114b..845d0f0c02 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -17,48 +17,12 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); +include($phpbb_root_path . 'includes/functions_display.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); -$user->setup(); - -// Handle the display of extension front pages -if ($ext = $request->variable('ext', '')) -{ - $class = 'phpbb_ext_' . str_replace('/', '_', $ext) . '_controller'; - - if (!$phpbb_extension_manager->available($ext)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_DOES_NOT_EXIST', $ext)); - } - else if (!$phpbb_extension_manager->enabled($ext)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_DISABLED', $ext)); - } - else if (!class_exists($class)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_CONTROLLER_MISSING', $ext)); - } - - $controller = new $class; - - if (!($controller instanceof phpbb_extension_controller_interface)) - { - send_status_line(500, 'Internal Server Error'); - trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); - } - - $controller->handle(); - exit_handler(); -} - -include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - -$user->add_lang('viewforum'); +$user->setup('viewforum'); display_forums('', $config['load_moderators']); diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php new file mode 100644 index 0000000000..db7f3164d0 --- /dev/null +++ b/phpBB/language/en/app.php @@ -0,0 +1,59 @@ + 'Missing value for argument #%1$s: %3$s in class %2$s', + 'CONTROLLER_NOT_SPECIFIED' => 'No controller has been specified.', + 'CONTROLLER_NOT_FOUND' => 'The requested page could not be found.', + 'CONTROLLER_METHOD_NOT_SPECIFIED' => 'No method was specified for the controller.', + 'CONTROLLER_SERVICE_NOT_GIVEN' => 'The controller "%s" must have a service specified in ./config/routing.yml.', + 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "%s" is not defined in ./config/services.yml.', + 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object %s must return a Symfony\Component\HttpFoundation\Response object.', + + // Event Listener/Subscriber error messages + 'NO_EVENT_ATTRIBUTE' => 'Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', + 'SUBSCRIBER_WRONG_TYPE' => 'Service "%1$s" must implement interface "%2$s".', + + // Core error controller messages + 'PAGE_NOT_FOUND_ERROR' => 'The page you have requested does not exist.', + 'NOT_AUTHORISED_ERROR' => 'You do not have permission to access this page.', + 'NOT_AUTHENTICATED_ERROR' => 'You must log in to access this page.', + 'INTERNAL_SERVER_ERROR_ERROR' => 'An unknown error occured.', +)); diff --git a/phpBB/web.config b/phpBB/web.config index a73c328626..e31a48b991 100644 --- a/phpBB/web.config +++ b/phpBB/web.config @@ -12,6 +12,18 @@ + + + + + + + + + + + + diff --git a/tests/controller/config/routing.yml b/tests/controller/config/routing.yml new file mode 100644 index 0000000000..175b11f130 --- /dev/null +++ b/tests/controller/config/routing.yml @@ -0,0 +1,3 @@ +core_controller: + pattern: /core_foo + defaults: { _controller: core_foo.controller:bar } diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml new file mode 100644 index 0000000000..f1bd047489 --- /dev/null +++ b/tests/controller/config/services.yml @@ -0,0 +1,3 @@ +services: + core_foo.controller: + class: phpbb_controller_foo diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php new file mode 100644 index 0000000000..38f58c80a0 --- /dev/null +++ b/tests/controller/controller_test.php @@ -0,0 +1,75 @@ +extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + )); + } + + public function test_provider() + { + $provider = new phpbb_controller_provider; + $routes = $provider + ->get_paths($this->extension_manager->get_finder()) + ->find('./tests/controller/'); + + // This will need to be updated if any new routes are defined + $this->assertEquals(2, count($routes)); + } + + public function test_controller_resolver() + { + $container = new ContainerBuilder(); + // For some reason, I cannot get it to load more than one services + // file at a time, even when givein multiple paths + // So instead, I am looping through all of the paths + foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path) + { + $loader = new YamlFileLoader($container, new FileLocator($path)); + $loader->load('services.yml'); + } + + // Autoloading classes within the tests folder does not work + // so I'll include them manually + if (!class_exists('phpbb_ext_foo_controller')) + { + include(__DIR__.'/ext/foo/controller.php'); + } + if (!class_exists('phpbb_controller_foo')) + { + include(__DIR__.'/includes/controller/foo.php'); + } + + $resolver = new phpbb_controller_resolver(new phpbb_user, $container); + $symfony_request = new Request(array(), array(), array('_controller' => 'foo.controller:handle')); + + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle')); + + $symfony_request = new Request(array(), array(), array('_controller' => 'core_foo.controller:bar')); + + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar')); + } +} diff --git a/tests/controller/ext/foo/config/routing.yml b/tests/controller/ext/foo/config/routing.yml new file mode 100644 index 0000000000..4799fec37d --- /dev/null +++ b/tests/controller/ext/foo/config/routing.yml @@ -0,0 +1,3 @@ +controller1: + pattern: /foo + defaults: { _controller: foo.controller:handle } diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml new file mode 100644 index 0000000000..ce0e18c610 --- /dev/null +++ b/tests/controller/ext/foo/config/services.yml @@ -0,0 +1,3 @@ +services: + foo.controller: + class: phpbb_ext_foo_controller diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php new file mode 100644 index 0000000000..72b8560c20 --- /dev/null +++ b/tests/controller/ext/foo/controller.php @@ -0,0 +1,23 @@ + Date: Sat, 20 Oct 2012 17:06:04 -0400 Subject: [PATCH 050/244] [feature/controller] Transfer kernel-related stuff from container PR PHPBB3-10864 --- phpBB/includes/event/kernel_compiler_pass.php | 72 ++++++++++++++ phpBB/includes/event/kernel_subscriber.php | 94 +++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 phpBB/includes/event/kernel_compiler_pass.php create mode 100644 phpBB/includes/event/kernel_subscriber.php diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/event/kernel_compiler_pass.php new file mode 100644 index 0000000000..18b6661cd4 --- /dev/null +++ b/phpBB/includes/event/kernel_compiler_pass.php @@ -0,0 +1,72 @@ +getDefinition('dispatcher'); + $user = $container->get('user'); + + foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) + { + foreach ($events as $event) + { + $priority = isset($event['priority']) ? $event['priority'] : 0; + + if (!isset($event['event'])) + { + throw new InvalidArgumentException($user->lang('NO_EVENT_ATTRIBUTE', $id)); + } + + if (!isset($event['method'])) + { + $event['method'] = 'on'.preg_replace(array( + '/(?<=\b)[a-z]/ie', + '/[^a-z0-9]/i' + ), array('strtoupper("\\0")', ''), $event['event']); + } + + $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); + } + } + + foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) + { + // We must assume that the class value has been correctly filled, even if the service is created by a factory + $class = $container->getDefinition($id)->getClass(); + + $refClass = new ReflectionClass($class); + $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; + if (!$refClass->implementsInterface($interface)) + { + throw new InvalidArgumentException($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); + } + + $definition->addMethodCall('addSubscriberService', array($id, $class)); + } + } +} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_subscriber.php new file mode 100644 index 0000000000..9737d9bc23 --- /dev/null +++ b/phpBB/includes/event/kernel_subscriber.php @@ -0,0 +1,94 @@ +template = $template; + $this->user = $user; + } + + /** + * This listener is run when the KernelEvents::TERMINATE event is triggered + * This comes after a Response has been sent to the server; this is + * primarily cleanup stuff. + * + * @param PostResponseEvent $event + * @return null + */ + public function on_kernel_terminate(PostResponseEvent $event) + { + exit_handler(); + } + + /** + * This listener is run when the KernelEvents::EXCEPTION event is triggered + * + * @param GetResponseForExceptionEvent $event + * @return null + */ + public function on_kernel_exception(GetResponseForExceptionEvent $event) + { + page_header($this->user->lang('INFORMATION')); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $event->getException()->getMessage(), + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + $event->setResponse(new Response($this->template->return_display('body'), 404)); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::TERMINATE => 'on_kernel_terminate', + KernelEvents::EXCEPTION => 'on_kernel_exception', + ); + } +} From 5c86a1660d436cf16448ae6c978237833e3e86b7 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 17:16:14 -0400 Subject: [PATCH 051/244] [feature/controller] Don't allow a kernel listener to be added with no method PHPBB3-10864 --- phpBB/includes/event/kernel_compiler_pass.php | 5 +---- phpBB/language/en/app.php | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/event/kernel_compiler_pass.php index 18b6661cd4..9a650bc404 100644 --- a/phpBB/includes/event/kernel_compiler_pass.php +++ b/phpBB/includes/event/kernel_compiler_pass.php @@ -44,10 +44,7 @@ class phpbb_event_kernel_compiler_pass implements CompilerPassInterface if (!isset($event['method'])) { - $event['method'] = 'on'.preg_replace(array( - '/(?<=\b)[a-z]/ie', - '/[^a-z0-9]/i' - ), array('strtoupper("\\0")', ''), $event['event']); + throw new InvalidArgumentException($user->lang('NO_METHOD_ATTRIBUTE', $id)); } $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php index db7f3164d0..2cbeaa2cba 100644 --- a/phpBB/language/en/app.php +++ b/phpBB/language/en/app.php @@ -49,6 +49,7 @@ $lang = array_merge($lang, array( // Event Listener/Subscriber error messages 'NO_EVENT_ATTRIBUTE' => 'Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', + 'NO_METHOD_ATTRIBUTE' => 'Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', 'SUBSCRIBER_WRONG_TYPE' => 'Service "%1$s" must implement interface "%2$s".', // Core error controller messages From 97957d679250c642969a09b002f4125889a5f4fa Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 21 Oct 2012 16:37:03 -0400 Subject: [PATCH 052/244] [feature/controller-new] Rename kernel compiler pass class PHPBB3-10864 --- phpBB/common.php | 1 + .../{event/kernel_compiler_pass.php => di/pass/kernel.php} | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename phpBB/includes/{event/kernel_compiler_pass.php => di/pass/kernel.php} (96%) diff --git a/phpBB/common.php b/phpBB/common.php index 986f0a8839..b0bc281b45 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -93,6 +93,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/di/pass/kernel.php similarity index 96% rename from phpBB/includes/event/kernel_compiler_pass.php rename to phpBB/includes/di/pass/kernel.php index 9a650bc404..7b190a6236 100644 --- a/phpBB/includes/event/kernel_compiler_pass.php +++ b/phpBB/includes/di/pass/kernel.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class phpbb_event_kernel_compiler_pass implements CompilerPassInterface +class phpbb_di_pass_kernel implements CompilerPassInterface { /** * Modify the container before it is passed to the rest of the code From 4e1f17a87dc6fefa30becc594a7f41e7f6293cad Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 11 Nov 2012 14:17:31 -0500 Subject: [PATCH 053/244] [feature/controller] includes/functions.php is included by default PHPBB3-10864 --- phpBB/includes/controller/helper.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 1998ea6733..f3127fd1fc 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -79,11 +79,6 @@ class phpbb_controller_helper */ public function render($template_file, $page_title = '', $status_code = 200) { - if (!function_exists('page_header')) - { - include("{$this->phpbb_root_path}includes/functions.{$this->php_ext}"); - } - page_header($page_title); $this->template->set_filenames(array( From cba0be96a9d21d6927ab998b9a880c469b64fb24 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 11 Nov 2012 14:35:59 -0500 Subject: [PATCH 054/244] [feature/controller] Fix 403 Forbidden error --- phpBB/.htaccess | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 61bd4249e3..68021177f2 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,3 +1,5 @@ +Options +FollowSymLinks + RewriteEngine on From dd1f8a0e554cc7c7fd975089cfd01acc88c656a6 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 11 Nov 2012 19:41:45 -0500 Subject: [PATCH 055/244] [feature/controller-new] Call pass to subscribe the Kernel event listener PHPBB3-10864 --- phpBB/download/file.php | 1 + phpBB/install/database_update.php | 1 + 2 files changed, 2 insertions(+) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 85f5d11504..eed713b891 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -64,6 +64,7 @@ if (isset($_GET['avatar'])) ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 297802c210..b8f5021dfd 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -113,6 +113,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel(), ), $phpbb_root_path, $phpEx From 6e647cf6e142da3ddf304275803e708501daeb82 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 15:48:53 -0500 Subject: [PATCH 056/244] [feature/controller] Resolve trivial conflict I missed during rebase PHPBB3-10864 --- phpBB/config/services.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 650869d1e6..54d347debe 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -113,8 +113,6 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver -<<<<<<< HEAD -======= ext.finder: class: phpbb_extension_finder @@ -138,7 +136,6 @@ services: - @user tags: - { name: kernel.event_subscriber } ->>>>>>> 719171f... [feature/controller] Implement a front controller request: class: phpbb_request From 7687f069611b35f81c6d0fc87e46b9bb0821d616 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:26:31 -0500 Subject: [PATCH 057/244] [feature/controller] Inject dependencies instead of container PHPBB3-10864 --- phpBB/includes/controller/helper.php | 44 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index f3127fd1fc..0fc3ba0c67 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -15,9 +15,7 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Controller helper class, contains methods that do things for controllers @@ -25,12 +23,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; */ class phpbb_controller_helper { - /** - * Container - * @var ContainerBuilder - */ - protected $container; - /** * Template object * @var phpbb_template @@ -38,13 +30,19 @@ class phpbb_controller_helper protected $template; /** - * phpBB Root Path - * @var string + * User object + * @var phpbb_user */ - protected $phpbb_root_path; + protected $user; /** - * PHP Extension + * phpBB root path + * @var string + */ + protected $root_path; + + /** + * PHP extension * @var string */ protected $php_ext; @@ -58,15 +56,17 @@ class phpbb_controller_helper /** * Constructor * - * @param ContainerBuilder $container DI Container + * @param phpbb_template $template Template object + * @param phpbb_user $user User object + * @param string $root_path phpBB root path + * @param string $php_ext PHP extension */ - public function __construct(ContainerBuilder $container) + public function __construct(phpbb_template $template, phpbb_user $user, $root_path, $php_ext) { - $this->container = $container; - - $this->template = $this->container->get('template'); - $this->phpbb_root_path = $this->container->getParameter('core.root_path'); - $this->php_ext = $this->container->getParameter('core.php_ext'); + $this->template = $template; + $this->user = $user; + $this->root_path = $root_path; + $this->php_ext = $php_ext; } /** @@ -101,7 +101,7 @@ class phpbb_controller_helper */ public function url(array $url_parts, $query = '') { - return append_sid($this->phpbb_root_path . $this->url_base . implode('/', $url_parts), $query); + return append_sid($this->root_path . $this->url_base . implode('/', $url_parts), $query); } /** @@ -129,9 +129,9 @@ class phpbb_controller_helper { $this->template->assign_vars(array( 'MESSAGE_TEXT' => $message, - 'MESSAGE_TITLE' => $this->container->get('user')->lang('INFORMATION'), + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), )); - return $this->render('message_body.html', $this->container->get('user')->lang('INFORMATION'), $code); + return $this->render('message_body.html', $this->user->lang('INFORMATION'), $code); } } From 4b6d538b062a56f55ba221ac8437b4bfc712a475 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:28:56 -0500 Subject: [PATCH 058/244] [feature/controller] Rename kernel pass class properly PHPBB3-10864 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/includes/di/pass/{kernel.php => kernel_pass.php} | 2 +- phpBB/install/database_update.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename phpBB/includes/di/pass/{kernel.php => kernel_pass.php} (96%) diff --git a/phpBB/common.php b/phpBB/common.php index b0bc281b45..a5ffcea8e4 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -93,7 +93,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), - new phpbb_di_pass_kernel(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/download/file.php b/phpBB/download/file.php index eed713b891..73b9e0a9f2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -64,7 +64,7 @@ if (isset($_GET['avatar'])) ), array( new phpbb_di_pass_collection_pass(), - new phpbb_di_pass_kernel(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/includes/di/pass/kernel.php b/phpBB/includes/di/pass/kernel_pass.php similarity index 96% rename from phpBB/includes/di/pass/kernel.php rename to phpBB/includes/di/pass/kernel_pass.php index 7b190a6236..d186ff2767 100644 --- a/phpBB/includes/di/pass/kernel.php +++ b/phpBB/includes/di/pass/kernel_pass.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class phpbb_di_pass_kernel implements CompilerPassInterface +class phpbb_di_pass_kernel_pass implements CompilerPassInterface { /** * Modify the container before it is passed to the rest of the code diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index b8f5021dfd..377e38c423 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -113,7 +113,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), - new phpbb_di_pass_kernel(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx From ac29c7e9d982648ed64e0ef73bbebd67567c2d89 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:43:53 -0500 Subject: [PATCH 059/244] [feature/controller] Rework assign_display(), use exceptions instead of return PHPBB3-10864 --- phpBB/includes/template/template.php | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index a48e8459d5..a6ae44969b 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -219,30 +219,45 @@ class phpbb_template * * @param string $handle Handle to operate on * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_content If true return compiled handle, otherwise assign to $template_var - * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + * @param bool $return_contents If true return compiled handle, otherwise assign to $template_var + * @return bool|string If $return_content is true return string of the compiled handle, otherwise return true + * @throws RuntimeException */ - public function assign_display($handle, $template_var = '', $return_content = true) + public function assign_display($handle, $template_var = '', $return_contents = true) { $contents = $this->return_display($handle); - if ($return_content === true || empty($template_var) || $contents === false) + if (!$template_var) { - return $contents; + throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED') } $this->assign_var($template_var, $contents); - return true; + // If !$return_content evaluates to true, true will be returned + // Otherwise, the value of $contents will be returned + return !$return_contents ?: $contents; } + /** + * Return the compiled template code as a string + * + * @param string $handle Handle to operate on + * @return string Compiled template code; can be output directly to page + * @throws RuntimeException + */ public function return_display($handle) { ob_start(); $result = $this->display($handle); $contents = ob_get_clean(); - return $result === false ? $result : $contents; + if ($result === false) + { + throw new RuntimeException($user->lang('TEMPLATE_HANDLE_NOT_FOUND')); + } + + return $contents; } /** From 79bcbd3691a91e213a860dbcd1b11330752bd076 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:48:12 -0500 Subject: [PATCH 060/244] [feature/controller] Add _controller attribute to Request after instantiation PHPBB3-10864 --- tests/controller/controller_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 38f58c80a0..b73019a6a0 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -64,11 +64,13 @@ class phpbb_controller_test extends phpbb_test_case } $resolver = new phpbb_controller_resolver(new phpbb_user, $container); - $symfony_request = new Request(array(), array(), array('_controller' => 'foo.controller:handle')); + $symfony_request = new Request(); + $symfony_request->attributes->set('_controller', 'foo.controller:handle'); $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle')); - $symfony_request = new Request(array(), array(), array('_controller' => 'core_foo.controller:bar')); + $symfony_request = new Request(); + $symfony_request->attributes->set('_controller', 'core_foo.controller:bar'); $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar')); } From 1c5a82c4110cfbc328281d832bb38387df95c39d Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:48:42 -0500 Subject: [PATCH 061/244] [feature/controller] Remove empty __construct() method PHPBB3-10864 --- tests/controller/ext/foo/controller.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php index 72b8560c20..cfc5c20622 100644 --- a/tests/controller/ext/foo/controller.php +++ b/tests/controller/ext/foo/controller.php @@ -4,13 +4,6 @@ use Symfony\Component\HttpFoundation\Response; class phpbb_ext_foo_controller { - /** - * Constructor - */ - public function __construct() - { - } - /** * Handle method * From b5255d4ea4f9e5e1d8c2783555891a0d5a63aca2 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:51:23 -0500 Subject: [PATCH 062/244] [feature/controller] Fix syntax error in template code PHPBB3-10864 --- phpBB/includes/template/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index a6ae44969b..75bbbe2ef3 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -229,7 +229,7 @@ class phpbb_template if (!$template_var) { - throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED') + throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED')); } $this->assign_var($template_var, $contents); From ef46af8298e18c64b662375adb7eaa40342900a8 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 09:57:51 -0500 Subject: [PATCH 063/244] [feature/controller] Don't attempt to assign if no variable is give PHPBB3-10864 --- phpBB/includes/template/template.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 75bbbe2ef3..11d226d705 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -227,12 +227,15 @@ class phpbb_template { $contents = $this->return_display($handle); - if (!$template_var) + if (!$template_var && !$return_contents) { throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED')); } - $this->assign_var($template_var, $contents); + if ($template_var) + { + $this->assign_var($template_var, $contents); + } // If !$return_content evaluates to true, true will be returned // Otherwise, the value of $contents will be returned From 6900456e903a01c3df8d717de711480d347d287c Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:41:11 -0500 Subject: [PATCH 064/244] [feature/controller] Revert changes to template class As per IRC, assign_display() effectively does what return_display() was added to do, so no change was needed. PHPBB3-10864 --- phpBB/includes/template/template.php | 1139 +++++++++++++------------- 1 file changed, 559 insertions(+), 580 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 11d226d705..00fe26b9b1 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -1,580 +1,559 @@ - $user->img('icon_contact', 'CONTACT', 'full'); -* -* More in-depth... -* yadayada -*/ - -/** -* Base Template class. -* @package phpBB3 -*/ -class phpbb_template -{ - /** - * Template context. - * Stores template data used during template rendering. - * @var phpbb_template_context - */ - private $context; - - /** - * Path of the cache directory for the template - * @var string - */ - public $cachepath = ''; - - /** - * phpBB root path - * @var string - */ - private $phpbb_root_path; - - /** - * PHP file extension - * @var string - */ - private $php_ext; - - /** - * phpBB config instance - * @var phpbb_config - */ - private $config; - - /** - * Current user - * @var phpbb_user - */ - private $user; - - /** - * Template locator - * @var phpbb_template_locator - */ - private $locator; - - /** - * Location of templates directory within style directories - * @var string - */ - public $template_path = 'template/'; - - /** - * Constructor. - * - * @param string $phpbb_root_path phpBB root path - * @param user $user current user - * @param phpbb_template_locator $locator template locator - * @param phpbb_template_context $context template context - */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) - { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->config = $config; - $this->user = $user; - $this->locator = $locator; - $this->template_path = $this->locator->template_path; - $this->context = $context; - } - - /** - * Sets the template filenames for handles. - * - * @param array $filname_array Should be a hash of handle => filename pairs. - */ - public function set_filenames(array $filename_array) - { - $this->locator->set_filenames($filename_array); - - return true; - } - - /** - * Clears all variables and blocks assigned to this template. - */ - public function destroy() - { - $this->context->clear(); - } - - /** - * Reset/empty complete block - * - * @param string $blockname Name of block to destroy - */ - public function destroy_block_vars($blockname) - { - $this->context->destroy_block_vars($blockname); - } - - /** - * Display a template for provided handle. - * - * The template will be loaded and compiled, if necessary, first. - * - * This function calls hooks. - * - * @param string $handle Handle to display - * @return bool True on success, false on failure - */ - public function display($handle) - { - $result = $this->call_hook($handle, __FUNCTION__); - if ($result !== false) - { - return $result[0]; - } - - return $this->load_and_render($handle); - } - - /** - * Loads a template for $handle, compiling it if necessary, and - * renders the template. - * - * @param string $handle Template handle to render - * @return bool True on success, false on failure - */ - private function load_and_render($handle) - { - $renderer = $this->_tpl_load($handle); - - if ($renderer) - { - $renderer->render($this->context, $this->get_lang()); - return true; - } - else - { - return false; - } - } - - /** - * Calls hook if any is defined. - * - * @param string $handle Template handle being displayed. - * @param string $method Method name of the caller. - */ - private function call_hook($handle, $method) - { - global $phpbb_hook; - - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) - { - if ($phpbb_hook->hook_return(array(__CLASS__, $method))) - { - $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); - return array($result); - } - } - - return false; - } - - /** - * Obtains language array. - * This is either lang property of $user property, or if - * it is not set an empty array. - * @return array language entries - */ - public function get_lang() - { - if (isset($this->user->lang)) - { - $lang = $this->user->lang; - } - else - { - $lang = array(); - } - return $lang; - } - - /** - * Display the handle and assign the output to a template variable - * or return the compiled result. - * - * @param string $handle Handle to operate on - * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_contents If true return compiled handle, otherwise assign to $template_var - * @return bool|string If $return_content is true return string of the compiled handle, otherwise return true - * @throws RuntimeException - */ - public function assign_display($handle, $template_var = '', $return_contents = true) - { - $contents = $this->return_display($handle); - - if (!$template_var && !$return_contents) - { - throw new RuntimeException($this->user->lang('TEMPLATE_CANNOT_BE_ASSIGNED')); - } - - if ($template_var) - { - $this->assign_var($template_var, $contents); - } - - // If !$return_content evaluates to true, true will be returned - // Otherwise, the value of $contents will be returned - return !$return_contents ?: $contents; - } - - /** - * Return the compiled template code as a string - * - * @param string $handle Handle to operate on - * @return string Compiled template code; can be output directly to page - * @throws RuntimeException - */ - public function return_display($handle) - { - ob_start(); - $result = $this->display($handle); - $contents = ob_get_clean(); - - if ($result === false) - { - throw new RuntimeException($user->lang('TEMPLATE_HANDLE_NOT_FOUND')); - } - - return $contents; - } - - /** - * Obtains a template renderer for a template identified by specified - * handle. The template renderer can display the template later. - * - * Template source will first be compiled into php code. - * If template cache is writable the compiled php code will be stored - * on filesystem and template will not be subsequently recompiled. - * If template cache is not writable template source will be recompiled - * every time it is needed. DEBUG define and load_tplcompile - * configuration setting may be used to force templates to be always - * recompiled. - * - * Returns an object implementing phpbb_template_renderer, or null - * if template loading or compilation failed. Call render() on the - * renderer to display the template. This will result in template - * contents sent to the output stream (unless, of course, output - * buffering is in effect). - * - * @param string $handle Handle of the template to load - * @return phpbb_template_renderer Template renderer object, or null on failure - * @uses phpbb_template_compile is used to compile template source - */ - private function _tpl_load($handle) - { - $output_file = $this->_compiled_file_for_handle($handle); - - $recompile = defined('DEBUG') || - !file_exists($output_file) || - @filesize($output_file) === 0; - - if ($recompile || $this->config['load_tplcompile']) - { - // Set only if a recompile or an mtime check are required. - $source_file = $this->locator->get_source_file_for_handle($handle); - - if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) - { - $recompile = true; - } - } - - // Recompile page if the original template is newer, otherwise load the compiled version - if (!$recompile) - { - return new phpbb_template_renderer_include($output_file, $this); - } - - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); - - if ($compile->compile_file_to_file($source_file, $output_file) !== false) - { - $renderer = new phpbb_template_renderer_include($output_file, $this); - } - else if (($code = $compile->compile_file($source_file)) !== false) - { - $renderer = new phpbb_template_renderer_eval($code, $this); - } - else - { - $renderer = null; - } - - return $renderer; - } - - /** - * Determines compiled file path for handle $handle. - * - * @param string $handle Template handle (i.e. "friendly" template name) - * @return string Compiled file path - */ - private function _compiled_file_for_handle($handle) - { - $source_file = $this->locator->get_filename_for_handle($handle); - $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; - return $compiled_file; - } - - /** - * Assign key variable pairs from an array - * - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_vars(array $vararray) - { - foreach ($vararray as $key => $val) - { - $this->assign_var($key, $val); - } - } - - /** - * Assign a single scalar value to a single key. - * - * Value can be a string, an integer or a boolean. - * - * @param string $varname Variable name - * @param string $varval Value to assign to variable - */ - public function assign_var($varname, $varval) - { - $this->context->assign_var($varname, $varval); - } - - /** - * Append text to the string value stored in a key. - * - * Text is appended using the string concatenation operator (.). - * - * @param string $varname Variable name - * @param string $varval Value to append to variable - */ - public function append_var($varname, $varval) - { - $this->context->append_var($varname, $varval); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Assign key variable pairs from an array to a specified block - * @param string $blockname Name of block to assign $vararray to - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_block_vars($blockname, array $vararray) - { - return $this->context->assign_block_vars($blockname, $vararray); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Change already assigned key variable pair (one-dimensional - single loop entry) - * - * An example of how to use this function: - * {@example alter_block_array.php} - * - * @param string $blockname the blockname, for example 'loop' - * @param array $vararray the var array to insert/add or merge - * @param mixed $key Key to search for - * - * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] - * - * int: Position [the position to change or insert at directly given] - * - * If key is false the position is set to 0 - * If key is true the position is set to the last entry - * - * @param string $mode Mode to execute (valid modes are 'insert' and 'change') - * - * If insert, the vararray is inserted at the given position (position counting from zero). - * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). - * - * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) - * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) - * - * @return bool false on error, true on success - */ - public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') - { - return $this->context->alter_block_array($blockname, $vararray, $key, $mode); - } - - /** - * Include a separate template. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Template filename to include - * @param bool $include True to include the file, false to just load it - * @uses template_compile is used to compile uncached templates - */ - public function _tpl_include($filename, $include = true) - { - $this->locator->set_filenames(array($filename => $filename)); - - if (!$this->load_and_render($filename)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; - } - } - - /** - * Include a PHP file. - * - * If a relative path is passed in $filename, it is considered to be - * relative to board root ($phpbb_root_path). Absolute paths are - * also allowed. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Path to PHP file to include - */ - public function _php_include($filename) - { - if (phpbb_is_absolute($filename)) - { - $file = $filename; - } - else - { - $file = $this->phpbb_root_path . $filename; - } - - if (!file_exists($file)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; - return; - } - include($file); - } - - /** - * Obtains filesystem path for a template file. - * - * The simplest use is specifying a single template file as a string - * in the first argument. This template file should be a basename - * of a template file in the selected style, or its parent styles - * if template inheritance is being utilized. - * - * Note: "selected style" is whatever style the style resource locator - * is configured for. - * - * The return value then will be a path, relative to the current - * directory or absolute, to the template file in the selected style - * or its closest parent. - * - * If the selected style does not have the template file being searched, - * (and if inheritance is involved, none of the parents have it either), - * false will be returned. - * - * Specifying true for $return_default will cause the function to - * return the first path which was checked for existence in the event - * that the template file was not found, instead of false. - * This is the path in the selected style itself, not any of its - * parents. - * - * $files can be given an array of templates instead of a single - * template. When given an array, the function will try to resolve - * each template in the array to a path, and will return the first - * path that exists, or false if none exist. - * - * If $return_full_path is false, then instead of returning a usable - * path (when the template is found) only the template's basename - * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. - * - * @param string or array $files List of templates to locate. If there is only - * one template, $files can be a string to make code easier to read. - * @param bool $return_default Determines what to return if template does not - * exist. If true, function will return location where template is - * supposed to be. If false, function will return false. - * @param bool $return_full_path If true, function will return full path - * to template. If false, function will return template file name. - * This parameter can be used to check which one of set of template - * files is available. - * @return string or boolean Source template path if template exists or $return_default is - * true. False if template does not exist and $return_default is false - */ - public function locate($files, $return_default = false, $return_full_path = true) - { - // add template path prefix - $templates = array(); - if (is_string($files)) - { - $templates[] = $this->template_path . $files; - } - else - { - foreach ($files as $file) - { - $templates[] = $this->template_path . $file; - } - } - - // use resource locator to find files - return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); - } - - /** - * Include JS file - * - * @param string $file file name - * @param bool $locate True if file needs to be located - * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true - */ - public function _js_include($file, $locate = false, $relative = false) - { - // Locate file - if ($locate) - { - $located = $this->locator->get_first_file_location(array($file), false, true); - if ($located) - { - $file = $located; - } - } - else if ($relative) - { - $file = $this->phpbb_root_path . $file; - } - - $file .= (strpos($file, '?') === false) ? '?' : '&'; - $file .= 'assets_version=' . $this->config['assets_version']; - - // Add HTML code - $code = ''; - $this->context->append_var('SCRIPTS', $code); - } -} + $user->img('icon_contact', 'CONTACT', 'full'); +* +* More in-depth... +* yadayada +*/ + +/** +* Base Template class. +* @package phpBB3 +*/ +class phpbb_template +{ + /** + * Template context. + * Stores template data used during template rendering. + * @var phpbb_template_context + */ + private $context; + + /** + * Path of the cache directory for the template + * @var string + */ + public $cachepath = ''; + + /** + * phpBB root path + * @var string + */ + private $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + private $php_ext; + + /** + * phpBB config instance + * @var phpbb_config + */ + private $config; + + /** + * Current user + * @var phpbb_user + */ + private $user; + + /** + * Template locator + * @var phpbb_template_locator + */ + private $locator; + + /** + * Location of templates directory within style directories + * @var string + */ + public $template_path = 'template/'; + + /** + * Constructor. + * + * @param string $phpbb_root_path phpBB root path + * @param user $user current user + * @param phpbb_template_locator $locator template locator + * @param phpbb_template_context $context template context + */ + public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->user = $user; + $this->locator = $locator; + $this->template_path = $this->locator->template_path; + $this->context = $context; + } + + /** + * Sets the template filenames for handles. + * + * @param array $filname_array Should be a hash of handle => filename pairs. + */ + public function set_filenames(array $filename_array) + { + $this->locator->set_filenames($filename_array); + + return true; + } + + /** + * Clears all variables and blocks assigned to this template. + */ + public function destroy() + { + $this->context->clear(); + } + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + */ + public function destroy_block_vars($blockname) + { + $this->context->destroy_block_vars($blockname); + } + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return bool True on success, false on failure + */ + public function display($handle) + { + $result = $this->call_hook($handle, __FUNCTION__); + if ($result !== false) + { + return $result[0]; + } + + return $this->load_and_render($handle); + } + + /** + * Loads a template for $handle, compiling it if necessary, and + * renders the template. + * + * @param string $handle Template handle to render + * @return bool True on success, false on failure + */ + private function load_and_render($handle) + { + $renderer = $this->_tpl_load($handle); + + if ($renderer) + { + $renderer->render($this->context, $this->get_lang()); + return true; + } + else + { + return false; + } + } + + /** + * Calls hook if any is defined. + * + * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. + */ + private function call_hook($handle, $method) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); + return array($result); + } + } + + return false; + } + + /** + * Obtains language array. + * This is either lang property of $user property, or if + * it is not set an empty array. + * @return array language entries + */ + public function get_lang() + { + if (isset($this->user->lang)) + { + $lang = $this->user->lang; + } + else + { + $lang = array(); + } + return $lang; + } + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + */ + public function assign_display($handle, $template_var = '', $return_content = true) + { + ob_start(); + $result = $this->display($handle); + $contents = ob_get_clean(); + if ($result === false) + { + return false; + } + + if ($return_content) + { + return $contents; + } + + $this->assign_var($template_var, $contents); + + return true; + } + + /** + * Obtains a template renderer for a template identified by specified + * handle. The template renderer can display the template later. + * + * Template source will first be compiled into php code. + * If template cache is writable the compiled php code will be stored + * on filesystem and template will not be subsequently recompiled. + * If template cache is not writable template source will be recompiled + * every time it is needed. DEBUG define and load_tplcompile + * configuration setting may be used to force templates to be always + * recompiled. + * + * Returns an object implementing phpbb_template_renderer, or null + * if template loading or compilation failed. Call render() on the + * renderer to display the template. This will result in template + * contents sent to the output stream (unless, of course, output + * buffering is in effect). + * + * @param string $handle Handle of the template to load + * @return phpbb_template_renderer Template renderer object, or null on failure + * @uses phpbb_template_compile is used to compile template source + */ + private function _tpl_load($handle) + { + $output_file = $this->_compiled_file_for_handle($handle); + + $recompile = defined('DEBUG') || + !file_exists($output_file) || + @filesize($output_file) === 0; + + if ($recompile || $this->config['load_tplcompile']) + { + // Set only if a recompile or an mtime check are required. + $source_file = $this->locator->get_source_file_for_handle($handle); + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } + } + + // Recompile page if the original template is newer, otherwise load the compiled version + if (!$recompile) + { + return new phpbb_template_renderer_include($output_file, $this); + } + + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); + + if ($compile->compile_file_to_file($source_file, $output_file) !== false) + { + $renderer = new phpbb_template_renderer_include($output_file, $this); + } + else if (($code = $compile->compile_file($source_file)) !== false) + { + $renderer = new phpbb_template_renderer_eval($code, $this); + } + else + { + $renderer = null; + } + + return $renderer; + } + + /** + * Determines compiled file path for handle $handle. + * + * @param string $handle Template handle (i.e. "friendly" template name) + * @return string Compiled file path + */ + private function _compiled_file_for_handle($handle) + { + $source_file = $this->locator->get_filename_for_handle($handle); + $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; + return $compiled_file; + } + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_vars(array $vararray) + { + foreach ($vararray as $key => $val) + { + $this->assign_var($key, $val); + } + } + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + */ + public function assign_var($varname, $varval) + { + $this->context->assign_var($varname, $varval); + } + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + */ + public function append_var($varname, $varval) + { + $this->context->append_var($varname, $varval); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_block_vars($blockname, array $vararray) + { + return $this->context->assign_block_vars($blockname, $vararray); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') + { + return $this->context->alter_block_array($blockname, $vararray, $key, $mode); + } + + /** + * Include a separate template. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Template filename to include + * @param bool $include True to include the file, false to just load it + * @uses template_compile is used to compile uncached templates + */ + public function _tpl_include($filename, $include = true) + { + $this->locator->set_filenames(array($filename => $filename)); + + if (!$this->load_and_render($filename)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; + } + } + + /** + * Include a PHP file. + * + * If a relative path is passed in $filename, it is considered to be + * relative to board root ($phpbb_root_path). Absolute paths are + * also allowed. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Path to PHP file to include + */ + public function _php_include($filename) + { + if (phpbb_is_absolute($filename)) + { + $file = $filename; + } + else + { + $file = $this->phpbb_root_path . $filename; + } + + if (!file_exists($file)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; + return; + } + include($file); + } + + /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists, provided different file names are + * used for different templates. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add template path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true + */ + public function _js_include($file, $locate = false, $relative = false) + { + // Locate file + if ($locate) + { + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } + } + else if ($relative) + { + $file = $this->phpbb_root_path . $file; + } + + $file .= (strpos($file, '?') === false) ? '?' : '&'; + $file .= 'assets_version=' . $this->config['assets_version']; + + // Add HTML code + $code = ''; + $this->context->append_var('SCRIPTS', $code); + } +} From 2e594504596eaf6ab758240a1cd012dfea79fe77 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:42:20 -0500 Subject: [PATCH 065/244] [feature/controller] Use assign_display() instead of return_display() The latter was deemed unnecessary at the moment. PHPBB3-10864 --- phpBB/includes/controller/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 0fc3ba0c67..8bb4427382 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -87,7 +87,7 @@ class phpbb_controller_helper page_footer(true, false, false); - return new Response($this->template->return_display('body'), $status_code); + return new Response($this->template->assign_display('body'), $status_code); } /** From c6a5699325171ca12c540772ed4e6c0c55318ec5 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:46:46 -0500 Subject: [PATCH 066/244] [feature/controller-new] Fix line endings PHPBB3-10864 --- phpBB/includes/template/template.php | 1118 +++++++++++++------------- 1 file changed, 559 insertions(+), 559 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 00fe26b9b1..8a7dc6b2f3 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -1,559 +1,559 @@ - $user->img('icon_contact', 'CONTACT', 'full'); -* -* More in-depth... -* yadayada -*/ - -/** -* Base Template class. -* @package phpBB3 -*/ -class phpbb_template -{ - /** - * Template context. - * Stores template data used during template rendering. - * @var phpbb_template_context - */ - private $context; - - /** - * Path of the cache directory for the template - * @var string - */ - public $cachepath = ''; - - /** - * phpBB root path - * @var string - */ - private $phpbb_root_path; - - /** - * PHP file extension - * @var string - */ - private $php_ext; - - /** - * phpBB config instance - * @var phpbb_config - */ - private $config; - - /** - * Current user - * @var phpbb_user - */ - private $user; - - /** - * Template locator - * @var phpbb_template_locator - */ - private $locator; - - /** - * Location of templates directory within style directories - * @var string - */ - public $template_path = 'template/'; - - /** - * Constructor. - * - * @param string $phpbb_root_path phpBB root path - * @param user $user current user - * @param phpbb_template_locator $locator template locator - * @param phpbb_template_context $context template context - */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) - { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->config = $config; - $this->user = $user; - $this->locator = $locator; - $this->template_path = $this->locator->template_path; - $this->context = $context; - } - - /** - * Sets the template filenames for handles. - * - * @param array $filname_array Should be a hash of handle => filename pairs. - */ - public function set_filenames(array $filename_array) - { - $this->locator->set_filenames($filename_array); - - return true; - } - - /** - * Clears all variables and blocks assigned to this template. - */ - public function destroy() - { - $this->context->clear(); - } - - /** - * Reset/empty complete block - * - * @param string $blockname Name of block to destroy - */ - public function destroy_block_vars($blockname) - { - $this->context->destroy_block_vars($blockname); - } - - /** - * Display a template for provided handle. - * - * The template will be loaded and compiled, if necessary, first. - * - * This function calls hooks. - * - * @param string $handle Handle to display - * @return bool True on success, false on failure - */ - public function display($handle) - { - $result = $this->call_hook($handle, __FUNCTION__); - if ($result !== false) - { - return $result[0]; - } - - return $this->load_and_render($handle); - } - - /** - * Loads a template for $handle, compiling it if necessary, and - * renders the template. - * - * @param string $handle Template handle to render - * @return bool True on success, false on failure - */ - private function load_and_render($handle) - { - $renderer = $this->_tpl_load($handle); - - if ($renderer) - { - $renderer->render($this->context, $this->get_lang()); - return true; - } - else - { - return false; - } - } - - /** - * Calls hook if any is defined. - * - * @param string $handle Template handle being displayed. - * @param string $method Method name of the caller. - */ - private function call_hook($handle, $method) - { - global $phpbb_hook; - - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) - { - if ($phpbb_hook->hook_return(array(__CLASS__, $method))) - { - $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); - return array($result); - } - } - - return false; - } - - /** - * Obtains language array. - * This is either lang property of $user property, or if - * it is not set an empty array. - * @return array language entries - */ - public function get_lang() - { - if (isset($this->user->lang)) - { - $lang = $this->user->lang; - } - else - { - $lang = array(); - } - return $lang; - } - - /** - * Display the handle and assign the output to a template variable - * or return the compiled result. - * - * @param string $handle Handle to operate on - * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_content If true return compiled handle, otherwise assign to $template_var - * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true - */ - public function assign_display($handle, $template_var = '', $return_content = true) - { - ob_start(); - $result = $this->display($handle); - $contents = ob_get_clean(); - if ($result === false) - { - return false; - } - - if ($return_content) - { - return $contents; - } - - $this->assign_var($template_var, $contents); - - return true; - } - - /** - * Obtains a template renderer for a template identified by specified - * handle. The template renderer can display the template later. - * - * Template source will first be compiled into php code. - * If template cache is writable the compiled php code will be stored - * on filesystem and template will not be subsequently recompiled. - * If template cache is not writable template source will be recompiled - * every time it is needed. DEBUG define and load_tplcompile - * configuration setting may be used to force templates to be always - * recompiled. - * - * Returns an object implementing phpbb_template_renderer, or null - * if template loading or compilation failed. Call render() on the - * renderer to display the template. This will result in template - * contents sent to the output stream (unless, of course, output - * buffering is in effect). - * - * @param string $handle Handle of the template to load - * @return phpbb_template_renderer Template renderer object, or null on failure - * @uses phpbb_template_compile is used to compile template source - */ - private function _tpl_load($handle) - { - $output_file = $this->_compiled_file_for_handle($handle); - - $recompile = defined('DEBUG') || - !file_exists($output_file) || - @filesize($output_file) === 0; - - if ($recompile || $this->config['load_tplcompile']) - { - // Set only if a recompile or an mtime check are required. - $source_file = $this->locator->get_source_file_for_handle($handle); - - if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) - { - $recompile = true; - } - } - - // Recompile page if the original template is newer, otherwise load the compiled version - if (!$recompile) - { - return new phpbb_template_renderer_include($output_file, $this); - } - - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); - - if ($compile->compile_file_to_file($source_file, $output_file) !== false) - { - $renderer = new phpbb_template_renderer_include($output_file, $this); - } - else if (($code = $compile->compile_file($source_file)) !== false) - { - $renderer = new phpbb_template_renderer_eval($code, $this); - } - else - { - $renderer = null; - } - - return $renderer; - } - - /** - * Determines compiled file path for handle $handle. - * - * @param string $handle Template handle (i.e. "friendly" template name) - * @return string Compiled file path - */ - private function _compiled_file_for_handle($handle) - { - $source_file = $this->locator->get_filename_for_handle($handle); - $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; - return $compiled_file; - } - - /** - * Assign key variable pairs from an array - * - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_vars(array $vararray) - { - foreach ($vararray as $key => $val) - { - $this->assign_var($key, $val); - } - } - - /** - * Assign a single scalar value to a single key. - * - * Value can be a string, an integer or a boolean. - * - * @param string $varname Variable name - * @param string $varval Value to assign to variable - */ - public function assign_var($varname, $varval) - { - $this->context->assign_var($varname, $varval); - } - - /** - * Append text to the string value stored in a key. - * - * Text is appended using the string concatenation operator (.). - * - * @param string $varname Variable name - * @param string $varval Value to append to variable - */ - public function append_var($varname, $varval) - { - $this->context->append_var($varname, $varval); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Assign key variable pairs from an array to a specified block - * @param string $blockname Name of block to assign $vararray to - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_block_vars($blockname, array $vararray) - { - return $this->context->assign_block_vars($blockname, $vararray); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Change already assigned key variable pair (one-dimensional - single loop entry) - * - * An example of how to use this function: - * {@example alter_block_array.php} - * - * @param string $blockname the blockname, for example 'loop' - * @param array $vararray the var array to insert/add or merge - * @param mixed $key Key to search for - * - * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] - * - * int: Position [the position to change or insert at directly given] - * - * If key is false the position is set to 0 - * If key is true the position is set to the last entry - * - * @param string $mode Mode to execute (valid modes are 'insert' and 'change') - * - * If insert, the vararray is inserted at the given position (position counting from zero). - * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). - * - * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) - * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) - * - * @return bool false on error, true on success - */ - public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') - { - return $this->context->alter_block_array($blockname, $vararray, $key, $mode); - } - - /** - * Include a separate template. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Template filename to include - * @param bool $include True to include the file, false to just load it - * @uses template_compile is used to compile uncached templates - */ - public function _tpl_include($filename, $include = true) - { - $this->locator->set_filenames(array($filename => $filename)); - - if (!$this->load_and_render($filename)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; - } - } - - /** - * Include a PHP file. - * - * If a relative path is passed in $filename, it is considered to be - * relative to board root ($phpbb_root_path). Absolute paths are - * also allowed. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Path to PHP file to include - */ - public function _php_include($filename) - { - if (phpbb_is_absolute($filename)) - { - $file = $filename; - } - else - { - $file = $this->phpbb_root_path . $filename; - } - - if (!file_exists($file)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; - return; - } - include($file); - } - - /** - * Obtains filesystem path for a template file. - * - * The simplest use is specifying a single template file as a string - * in the first argument. This template file should be a basename - * of a template file in the selected style, or its parent styles - * if template inheritance is being utilized. - * - * Note: "selected style" is whatever style the style resource locator - * is configured for. - * - * The return value then will be a path, relative to the current - * directory or absolute, to the template file in the selected style - * or its closest parent. - * - * If the selected style does not have the template file being searched, - * (and if inheritance is involved, none of the parents have it either), - * false will be returned. - * - * Specifying true for $return_default will cause the function to - * return the first path which was checked for existence in the event - * that the template file was not found, instead of false. - * This is the path in the selected style itself, not any of its - * parents. - * - * $files can be given an array of templates instead of a single - * template. When given an array, the function will try to resolve - * each template in the array to a path, and will return the first - * path that exists, or false if none exist. - * - * If $return_full_path is false, then instead of returning a usable - * path (when the template is found) only the template's basename - * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. - * - * @param string or array $files List of templates to locate. If there is only - * one template, $files can be a string to make code easier to read. - * @param bool $return_default Determines what to return if template does not - * exist. If true, function will return location where template is - * supposed to be. If false, function will return false. - * @param bool $return_full_path If true, function will return full path - * to template. If false, function will return template file name. - * This parameter can be used to check which one of set of template - * files is available. - * @return string or boolean Source template path if template exists or $return_default is - * true. False if template does not exist and $return_default is false - */ - public function locate($files, $return_default = false, $return_full_path = true) - { - // add template path prefix - $templates = array(); - if (is_string($files)) - { - $templates[] = $this->template_path . $files; - } - else - { - foreach ($files as $file) - { - $templates[] = $this->template_path . $file; - } - } - - // use resource locator to find files - return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); - } - - /** - * Include JS file - * - * @param string $file file name - * @param bool $locate True if file needs to be located - * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true - */ - public function _js_include($file, $locate = false, $relative = false) - { - // Locate file - if ($locate) - { - $located = $this->locator->get_first_file_location(array($file), false, true); - if ($located) - { - $file = $located; - } - } - else if ($relative) - { - $file = $this->phpbb_root_path . $file; - } - - $file .= (strpos($file, '?') === false) ? '?' : '&'; - $file .= 'assets_version=' . $this->config['assets_version']; - - // Add HTML code - $code = ''; - $this->context->append_var('SCRIPTS', $code); - } -} + $user->img('icon_contact', 'CONTACT', 'full'); +* +* More in-depth... +* yadayada +*/ + +/** +* Base Template class. +* @package phpBB3 +*/ +class phpbb_template +{ + /** + * Template context. + * Stores template data used during template rendering. + * @var phpbb_template_context + */ + private $context; + + /** + * Path of the cache directory for the template + * @var string + */ + public $cachepath = ''; + + /** + * phpBB root path + * @var string + */ + private $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + private $php_ext; + + /** + * phpBB config instance + * @var phpbb_config + */ + private $config; + + /** + * Current user + * @var phpbb_user + */ + private $user; + + /** + * Template locator + * @var phpbb_template_locator + */ + private $locator; + + /** + * Location of templates directory within style directories + * @var string + */ + public $template_path = 'template/'; + + /** + * Constructor. + * + * @param string $phpbb_root_path phpBB root path + * @param user $user current user + * @param phpbb_template_locator $locator template locator + * @param phpbb_template_context $context template context + */ + public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->user = $user; + $this->locator = $locator; + $this->template_path = $this->locator->template_path; + $this->context = $context; + } + + /** + * Sets the template filenames for handles. + * + * @param array $filname_array Should be a hash of handle => filename pairs. + */ + public function set_filenames(array $filename_array) + { + $this->locator->set_filenames($filename_array); + + return true; + } + + /** + * Clears all variables and blocks assigned to this template. + */ + public function destroy() + { + $this->context->clear(); + } + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + */ + public function destroy_block_vars($blockname) + { + $this->context->destroy_block_vars($blockname); + } + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return bool True on success, false on failure + */ + public function display($handle) + { + $result = $this->call_hook($handle, __FUNCTION__); + if ($result !== false) + { + return $result[0]; + } + + return $this->load_and_render($handle); + } + + /** + * Loads a template for $handle, compiling it if necessary, and + * renders the template. + * + * @param string $handle Template handle to render + * @return bool True on success, false on failure + */ + private function load_and_render($handle) + { + $renderer = $this->_tpl_load($handle); + + if ($renderer) + { + $renderer->render($this->context, $this->get_lang()); + return true; + } + else + { + return false; + } + } + + /** + * Calls hook if any is defined. + * + * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. + */ + private function call_hook($handle, $method) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); + return array($result); + } + } + + return false; + } + + /** + * Obtains language array. + * This is either lang property of $user property, or if + * it is not set an empty array. + * @return array language entries + */ + public function get_lang() + { + if (isset($this->user->lang)) + { + $lang = $this->user->lang; + } + else + { + $lang = array(); + } + return $lang; + } + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + */ + public function assign_display($handle, $template_var = '', $return_content = true) + { + ob_start(); + $result = $this->display($handle); + $contents = ob_get_clean(); + if ($result === false) + { + return false; + } + + if ($return_content) + { + return $contents; + } + + $this->assign_var($template_var, $contents); + + return true; + } + + /** + * Obtains a template renderer for a template identified by specified + * handle. The template renderer can display the template later. + * + * Template source will first be compiled into php code. + * If template cache is writable the compiled php code will be stored + * on filesystem and template will not be subsequently recompiled. + * If template cache is not writable template source will be recompiled + * every time it is needed. DEBUG define and load_tplcompile + * configuration setting may be used to force templates to be always + * recompiled. + * + * Returns an object implementing phpbb_template_renderer, or null + * if template loading or compilation failed. Call render() on the + * renderer to display the template. This will result in template + * contents sent to the output stream (unless, of course, output + * buffering is in effect). + * + * @param string $handle Handle of the template to load + * @return phpbb_template_renderer Template renderer object, or null on failure + * @uses phpbb_template_compile is used to compile template source + */ + private function _tpl_load($handle) + { + $output_file = $this->_compiled_file_for_handle($handle); + + $recompile = defined('DEBUG') || + !file_exists($output_file) || + @filesize($output_file) === 0; + + if ($recompile || $this->config['load_tplcompile']) + { + // Set only if a recompile or an mtime check are required. + $source_file = $this->locator->get_source_file_for_handle($handle); + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } + } + + // Recompile page if the original template is newer, otherwise load the compiled version + if (!$recompile) + { + return new phpbb_template_renderer_include($output_file, $this); + } + + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); + + if ($compile->compile_file_to_file($source_file, $output_file) !== false) + { + $renderer = new phpbb_template_renderer_include($output_file, $this); + } + else if (($code = $compile->compile_file($source_file)) !== false) + { + $renderer = new phpbb_template_renderer_eval($code, $this); + } + else + { + $renderer = null; + } + + return $renderer; + } + + /** + * Determines compiled file path for handle $handle. + * + * @param string $handle Template handle (i.e. "friendly" template name) + * @return string Compiled file path + */ + private function _compiled_file_for_handle($handle) + { + $source_file = $this->locator->get_filename_for_handle($handle); + $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; + return $compiled_file; + } + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_vars(array $vararray) + { + foreach ($vararray as $key => $val) + { + $this->assign_var($key, $val); + } + } + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + */ + public function assign_var($varname, $varval) + { + $this->context->assign_var($varname, $varval); + } + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + */ + public function append_var($varname, $varval) + { + $this->context->append_var($varname, $varval); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_block_vars($blockname, array $vararray) + { + return $this->context->assign_block_vars($blockname, $vararray); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') + { + return $this->context->alter_block_array($blockname, $vararray, $key, $mode); + } + + /** + * Include a separate template. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Template filename to include + * @param bool $include True to include the file, false to just load it + * @uses template_compile is used to compile uncached templates + */ + public function _tpl_include($filename, $include = true) + { + $this->locator->set_filenames(array($filename => $filename)); + + if (!$this->load_and_render($filename)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; + } + } + + /** + * Include a PHP file. + * + * If a relative path is passed in $filename, it is considered to be + * relative to board root ($phpbb_root_path). Absolute paths are + * also allowed. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Path to PHP file to include + */ + public function _php_include($filename) + { + if (phpbb_is_absolute($filename)) + { + $file = $filename; + } + else + { + $file = $this->phpbb_root_path . $filename; + } + + if (!file_exists($file)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; + return; + } + include($file); + } + + /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists, provided different file names are + * used for different templates. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add template path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true + */ + public function _js_include($file, $locate = false, $relative = false) + { + // Locate file + if ($locate) + { + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } + } + else if ($relative) + { + $file = $this->phpbb_root_path . $file; + } + + $file .= (strpos($file, '?') === false) ? '?' : '&'; + $file .= 'assets_version=' . $this->config['assets_version']; + + // Add HTML code + $code = ''; + $this->context->append_var('SCRIPTS', $code); + } +} From 46cb0fb068feeb89c939d8b145808d2a786de8dd Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:57:24 -0500 Subject: [PATCH 067/244] [feature/controller] Removed another empty construct method PHPBB3-10864 --- tests/controller/includes/controller/foo.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/includes/controller/foo.php index cd1c4849cb..04576e16c4 100644 --- a/tests/controller/includes/controller/foo.php +++ b/tests/controller/includes/controller/foo.php @@ -4,13 +4,6 @@ use Symfony\Component\HttpFoundation\Response; class phpbb_controller_foo { - /** - * Constructor - */ - public function __construct() - { - } - /** * Bar method * From 5877bf1b1b3dc2899543d99859e3bde6e70d8647 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 11:02:01 -0500 Subject: [PATCH 068/244] [feature/controller] Update helper service given constructor change PHPBB3-10864 --- phpBB/config/services.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 54d347debe..184ebb80ee 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -47,7 +47,10 @@ services: controller.helper: class: phpbb_controller_helper arguments: - - @service_container + - @template + - @user + - %core.root_path% + - .%core.php_ext% controller.resolver: class: phpbb_controller_resolver @@ -64,7 +67,7 @@ services: controller.provider: class: phpbb_controller_provider - + cron.task_collection: class: phpbb_di_service_collection arguments: @@ -113,7 +116,7 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver - + ext.finder: class: phpbb_extension_finder arguments: From d3aa8823b21990634f8b74676ac301739ddfc58b Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:42:13 -0500 Subject: [PATCH 069/244] [feature/controller] Use a dumped url matcher class to improve performance PHPBB3-10864 --- phpBB/config/services.yml | 21 ++------ .../includes/controller/route_collection.php | 36 ------------- phpBB/includes/event/kernel_subscriber.php | 52 ++++++++++++++++++- phpBB/includes/functions.php | 52 +++++++++++++++++++ 4 files changed, 106 insertions(+), 55 deletions(-) delete mode 100644 phpBB/includes/controller/route_collection.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 184ebb80ee..4fe9fa52eb 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -123,7 +123,7 @@ services: - @ext.manager - %core.root_path% - @cache.driver - - .%core.php_ext% + - %core.php_ext% - _ext_finder http_kernel: @@ -137,22 +137,15 @@ services: arguments: - @template - @user + - @ext.finder + - %core.root_path% + - .%core.php_ext% tags: - { name: kernel.event_subscriber } request: class: phpbb_request - request.context: - class: Symfony\Component\Routing\RequestContext - - router_listener: - class: Symfony\Component\HttpKernel\EventListener\RouterListener - arguments: - - @url_matcher - tags: - - { name: kernel.event_subscriber } - style: class: phpbb_style arguments: @@ -189,11 +182,5 @@ services: template_context: class: phpbb_template_context - url_matcher: - class: Symfony\Component\Routing\Matcher\UrlMatcher - arguments: - - @controller.route_collection - - @request.context - user: class: phpbb_user diff --git a/phpBB/includes/controller/route_collection.php b/phpBB/includes/controller/route_collection.php deleted file mode 100644 index e6c7d3b543..0000000000 --- a/phpBB/includes/controller/route_collection.php +++ /dev/null @@ -1,36 +0,0 @@ -addCollection($provider->get_paths($finder)->find()); - } -} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_subscriber.php index 9737d9bc23..79ee4f4dc5 100644 --- a/phpBB/includes/event/kernel_subscriber.php +++ b/phpBB/includes/event/kernel_subscriber.php @@ -18,8 +18,11 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\EventListener\RouterListener; +use Symfony\Component\Routing\RequestContext; class phpbb_event_kernel_subscriber implements EventSubscriberInterface { @@ -35,16 +38,40 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface */ protected $user; + /** + * Extension finder object + * @var phpbb_extension_finder + */ + protected $finder; + + /** + * PHP extension + * @var string + */ + protected $php_ext; + + /** + * Root path + * @var string + */ + protected $root_path; + /** * Construct method * * @param phpbb_template $template Template object * @param phpbb_user $user User object + * @param phpbb_extension_finder $finder Extension finder object + * @param string $root_path Root path + * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user) + public function __construct(phpbb_template $template, phpbb_user $user, phpbb_extension_finder $finder, $root_path, $php_ext) { $this->template = $template; $this->user = $user; + $this->finder = $finder; + $this->root_path = $root_path; + $this->php_ext = $php_ext; } /** @@ -81,12 +108,33 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface page_footer(true, false, false); - $event->setResponse(new Response($this->template->return_display('body'), 404)); + $event->setResponse(new Response($this->template->assign_display('body'), 404)); + } + + /** + * This listener is run when the KernelEvents::REQUEST event is triggered + * + * This is responsible for setting up the routing information + * + * @param GetResponseEvent $event + * @return null + */ + public function on_kernel_request(GetResponseEvent $event) + { + $request = $event->getRequest(); + $context = new RequestContext(); + $context->fromRequest($request); + + $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); + + $router_listener = new RouterListener($matcher, $context); + $router_listener->onKernelRequest($event); } public static function getSubscribedEvents() { return array( + KernelEvents::REQUEST => 'on_kernel_request', KernelEvents::TERMINATE => 'on_kernel_terminate', KernelEvents::EXCEPTION => 'on_kernel_exception', ); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index fb05b74cd3..7cf5611dca 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,6 +7,9 @@ * */ +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\RequestContext; + /** * @ignore */ @@ -5444,3 +5447,52 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create and/or return the cached phpbb_url_matcher class +* +* If the class already exists, it instantiates it +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher +*/ +function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + if ($matcher === false) + { + $provider = new phpbb_controller_provider(); + $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); + return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + } + + return $matcher; +} + +/** +* Load the cached phpbb_url_matcher class +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher|bool False if the file doesn't exist +*/ +function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) + { + include($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); + } + + return false; +} From 269a56e2c3817cc27f2b21b9eb864c4f2452bc13 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:52:41 -0500 Subject: [PATCH 070/244] [feature/controller] Undo removal of period in ext.finder service definition PHPBB3-10864 --- phpBB/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 4fe9fa52eb..91610a3527 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -123,7 +123,7 @@ services: - @ext.manager - %core.root_path% - @cache.driver - - %core.php_ext% + - .%core.php_ext% - _ext_finder http_kernel: From 196c2d4bc346ab6a31fd0b752c788e37cf39459d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:56:07 -0500 Subject: [PATCH 071/244] [feature/controller] Move new functions to their own file PHPBB3-10864 --- phpBB/includes/functions.php | 49 ----------------- phpBB/includes/functions_url_matcher.php | 68 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 phpBB/includes/functions_url_matcher.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7cf5611dca..88ce142195 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5447,52 +5447,3 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } - -/** -* Create and/or return the cached phpbb_url_matcher class -* -* If the class already exists, it instantiates it -* -* @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP extension -* @return phpbb_url_matcher -*/ -function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) -{ - $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - if ($matcher === false) - { - $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); - $cached_url_matcher_dump = $dumper->dump(array( - 'class' => 'phpbb_url_matcher', - )); - - file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); - return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - } - - return $matcher; -} - -/** -* Load the cached phpbb_url_matcher class -* -* @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP extension -* @return phpbb_url_matcher|bool False if the file doesn't exist -*/ -function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) -{ - if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) - { - include($root_path . 'cache/url_matcher' . $php_ext); - return new phpbb_url_matcher($context); - } - - return false; -} diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php new file mode 100644 index 0000000000..0a6e90703c --- /dev/null +++ b/phpBB/includes/functions_url_matcher.php @@ -0,0 +1,68 @@ +get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); + return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + } + + return $matcher; +} + +/** +* Load the cached phpbb_url_matcher class +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher|bool False if the file doesn't exist +*/ +function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) + { + include($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); + } + + return false; +} From 4cb9ec522c7007b99eb5ef44cb1bfdb369478aff Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 16:06:12 -0500 Subject: [PATCH 072/244] [feature/controller] Separate Kernel listeners into their own classes PHPBB3-10864 --- phpBB/config/services.yml | 19 ++++- .../event/kernel_exception_subscriber.php | 79 +++++++++++++++++++ ...iber.php => kernel_request_subscriber.php} | 64 ++------------- .../event/kernel_terminate_subscriber.php | 43 ++++++++++ 4 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 phpBB/includes/event/kernel_exception_subscriber.php rename phpBB/includes/event/{kernel_subscriber.php => kernel_request_subscriber.php} (50%) create mode 100644 phpBB/includes/event/kernel_terminate_subscriber.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 91610a3527..37e6c0b5df 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -132,17 +132,28 @@ services: - @dispatcher - @controller.resolver - kernel_event_subscriber: - class: phpbb_event_kernel_subscriber + kernel_request_subscriber: + class: phpbb_event_kernel_request_subscriber arguments: - - @template - - @user - @ext.finder - %core.root_path% - .%core.php_ext% tags: - { name: kernel.event_subscriber } + kernel_exception_subscriber: + class: phpbb_event_kernel_exception_subscriber + arguments: + - @template + - @user + tags: + - { name: kernel.event_subscriber } + + kernel_terminate_subscriber: + class: phpbb_event_kernel_terminate_subscriber + tags: + - { name: kernel.event_subscriber } + request: class: phpbb_request diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php new file mode 100644 index 0000000000..cd6ea40c70 --- /dev/null +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -0,0 +1,79 @@ +template = $template; + $this->user = $user; + } + + /** + * This listener is run when the KernelEvents::EXCEPTION event is triggered + * + * @param GetResponseForExceptionEvent $event + * @return null + */ + public function on_kernel_exception(GetResponseForExceptionEvent $event) + { + page_header($this->user->lang('INFORMATION')); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $event->getException()->getMessage(), + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + $event->setResponse(new Response($this->template->assign_display('body'), 404)); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::EXCEPTION => 'on_kernel_exception', + ); + } +} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php similarity index 50% rename from phpBB/includes/event/kernel_subscriber.php rename to phpBB/includes/event/kernel_request_subscriber.php index 79ee4f4dc5..98079acabb 100644 --- a/phpBB/includes/event/kernel_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -17,27 +17,12 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\Routing\RequestContext; -class phpbb_event_kernel_subscriber implements EventSubscriberInterface +class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface { - /** - * Template object - * @var phpbb_template - */ - protected $template; - - /** - * User object - * @var phpbb_user - */ - protected $user; - /** * Extension finder object * @var phpbb_extension_finder @@ -59,13 +44,11 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface /** * Construct method * - * @param phpbb_template $template Template object - * @param phpbb_user $user User object * @param phpbb_extension_finder $finder Extension finder object * @param string $root_path Root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user, phpbb_extension_finder $finder, $root_path, $php_ext) + public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) { $this->template = $template; $this->user = $user; @@ -74,43 +57,6 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface $this->php_ext = $php_ext; } - /** - * This listener is run when the KernelEvents::TERMINATE event is triggered - * This comes after a Response has been sent to the server; this is - * primarily cleanup stuff. - * - * @param PostResponseEvent $event - * @return null - */ - public function on_kernel_terminate(PostResponseEvent $event) - { - exit_handler(); - } - - /** - * This listener is run when the KernelEvents::EXCEPTION event is triggered - * - * @param GetResponseForExceptionEvent $event - * @return null - */ - public function on_kernel_exception(GetResponseForExceptionEvent $event) - { - page_header($this->user->lang('INFORMATION')); - - $this->template->assign_vars(array( - 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $event->getException()->getMessage(), - )); - - $this->template->set_filenames(array( - 'body' => 'message_body.html', - )); - - page_footer(true, false, false); - - $event->setResponse(new Response($this->template->assign_display('body'), 404)); - } - /** * This listener is run when the KernelEvents::REQUEST event is triggered * @@ -125,6 +71,10 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); + if (!function_exists('phpbb_create_url_matcher')) + { + include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); + } $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); $router_listener = new RouterListener($matcher, $context); @@ -135,8 +85,6 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface { return array( KernelEvents::REQUEST => 'on_kernel_request', - KernelEvents::TERMINATE => 'on_kernel_terminate', - KernelEvents::EXCEPTION => 'on_kernel_exception', ); } } diff --git a/phpBB/includes/event/kernel_terminate_subscriber.php b/phpBB/includes/event/kernel_terminate_subscriber.php new file mode 100644 index 0000000000..1eaf890e42 --- /dev/null +++ b/phpBB/includes/event/kernel_terminate_subscriber.php @@ -0,0 +1,43 @@ + 'on_kernel_terminate', + ); + } +} From fa43edd8778dffd21146350f1749fad5c0755fb7 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 16:42:52 -0500 Subject: [PATCH 073/244] [feature/controller] Further separate url matcher functionality PHPBB3-10864 --- .../event/kernel_request_subscriber.php | 6 +- phpBB/includes/functions_url_matcher.php | 89 +++++++++++++------ 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php index 98079acabb..85c8c5b173 100644 --- a/phpBB/includes/event/kernel_request_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -50,8 +50,6 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface */ public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) { - $this->template = $template; - $this->user = $user; $this->finder = $finder; $this->root_path = $root_path; $this->php_ext = $php_ext; @@ -71,11 +69,11 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); - if (!function_exists('phpbb_create_url_matcher')) + if (!function_exists('phpbb_load_url_matcher')) { include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); } - $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); + $matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); $router_listener = new RouterListener($matcher, $context); $router_listener->onKernelRequest($event); diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index 0a6e90703c..f628337dee 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -8,6 +8,7 @@ */ use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; /** @@ -19,50 +20,86 @@ if (!defined('IN_PHPBB')) } /** -* Create and/or return the cached phpbb_url_matcher class -* -* If the class already exists, it instantiates it +* Create a new UrlMatcher class and dump it into the cache file * * @param phpbb_extension_finder $finder Extension finder * @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension -* @return phpbb_url_matcher +* @return null */ -function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) { - $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - if ($matcher === false) + if (defined('DEBUG')) { - $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); - $cached_url_matcher_dump = $dumper->dump(array( - 'class' => 'phpbb_url_matcher', - )); - - file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); - return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + return phpbb_create_url_matcher($finder, $context); } - return $matcher; + if (phpbb_url_matcher_dumped($root_path, $php_ext) === false) + { + phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); + } + + return phpbb_load_url_matcher($context, $root_path, $php_ext); +} + +/** +* Create a new UrlMatcher class and dump it into the cache file +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return null +*/ +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + $provider = new phpbb_controller_provider(); + $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); +} + +/** +* Create a non-cached UrlMatcher +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @return UrlMatcher +*/ +function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context) +{ + $provider = new phpbb_controller_provider(); + return new UrlMatcher($provider->get_paths($finder)->find(), $context); } /** * Load the cached phpbb_url_matcher class * -* @param phpbb_extension_finder $finder Extension finder * @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension -* @return phpbb_url_matcher|bool False if the file doesn't exist +* @return phpbb_url_matcher */ -function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext) { - if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) - { - include($root_path . 'cache/url_matcher' . $php_ext); - return new phpbb_url_matcher($context); - } - - return false; + require($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); +} + +/** +* Determine whether we have our dumped URL matcher +* +* The class is automatically dumped to the cache directory +* +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return bool True if it exists, false if not +*/ +function phpbb_url_matcher_dumped($root_path, $php_ext) +{ + return file_exists($root_path . 'cache/url_matcher' . $php_ext); } From c54c3ee422a9bfb0878aecf80cbb298e230e4fd4 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 17:04:45 -0500 Subject: [PATCH 074/244] [feature/controller] A few minor nitpickings PHPBB3-10864 --- phpBB/includes/functions_url_matcher.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index f628337dee..782acc4c20 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -35,7 +35,7 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c return phpbb_create_url_matcher($finder, $context); } - if (phpbb_url_matcher_dumped($root_path, $php_ext) === false) + if (!phpbb_url_matcher_dumped($root_path, $php_ext)) { phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); } @@ -55,7 +55,8 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) { $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $routes = $provider->get_paths($finder)->find(); + $dumper = new PhpMatcherDumper($routes); $cached_url_matcher_dump = $dumper->dump(array( 'class' => 'phpbb_url_matcher', )); From aead33432ae67857009f9570a5ec720d86f7575b Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 17:14:21 -0500 Subject: [PATCH 075/244] [feature/controller] Remove dumped container when cache is purged PHPBB3-10864 --- phpBB/includes/cache/driver/file.php | 1 + phpBB/includes/cache/driver/memory.php | 1 + 2 files changed, 2 insertions(+) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 32bdb1918a..5014ba18af 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -215,6 +215,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 1ea9a3e9e7..f6c42c0ea6 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -163,6 +163,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && From b4eff4f06acce78536a392b733f2438f4d1d1c52 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 13:54:41 -0500 Subject: [PATCH 076/244] [feature/controller] Remove URL Base from helper class I had forgotten that the container sends the same instance of objects to all services that request it, so in this case all controllers would share the same base url path, which is not desired. PHPBB3-10864 --- phpBB/includes/controller/helper.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 8bb4427382..6b697c7e46 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -47,12 +47,6 @@ class phpbb_controller_helper */ protected $php_ext; - /** - * Base URL - * @var array - */ - protected $url_base; - /** * Constructor * @@ -101,21 +95,7 @@ class phpbb_controller_helper */ public function url(array $url_parts, $query = '') { - return append_sid($this->root_path . $this->url_base . implode('/', $url_parts), $query); - } - - /** - * Set base to prepend to urls generated by url() - * This allows extensions to have a certain 'directory' under which - * all their pages are served, but not have to type it every time - * - * @param array $url_parts Each array element is a 'folder' - * i.e. array('my', 'ext') maps to ./app.php/my/ext - * @return null - */ - public function set_url_base(array $url_parts) - { - $this->url_base = !empty($url_parts) ? implode('/', $url_parts) . '/' : ''; + return append_sid($this->root_path . implode('/', $url_parts), $query); } /** From db1d49d559a337f7266a9e9f0cfaf3eb025b0ed1 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 13:59:30 -0500 Subject: [PATCH 077/244] [feature/controller] Rename get_paths to import_paths_from_finder Also removed unused variable from url_matcher function PHPBB3-10864 --- phpBB/includes/controller/provider.php | 20 ++++---------------- phpBB/includes/functions_url_matcher.php | 10 +++++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php index 25deedb5d1..b2a5b9f6b2 100644 --- a/phpBB/includes/controller/provider.php +++ b/phpBB/includes/controller/provider.php @@ -39,7 +39,7 @@ class phpbb_controller_provider */ public function __construct($routing_paths = array()) { - $this->set_paths($routing_paths); + $this->routing_paths = $routing_paths; } /** @@ -48,28 +48,16 @@ class phpbb_controller_provider * * @return The current instance of this object for method chaining */ - public function get_paths(phpbb_extension_finder $finder) + public function import_paths_from_finder(phpbb_extension_finder $finder) { // We hardcode the path to the core config directory // because the finder cannot find it - $this->set_paths(array_merge(array('config'), array_map('dirname', array_keys($finder + $this->routing_paths = array_merge(array('config'), array_map('dirname', array_keys($finder ->directory('config') ->prefix('routing') ->suffix('yml') ->find() - )))); - - return $this; - } - - /** - * Set the $routing_paths property with a given list of paths - * - * @return The current instance of this object for method chaining - */ - public function set_paths(array $paths) - { - $this->routing_paths = $paths; + ))); return $this; } diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index 782acc4c20..7280cb74eb 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -37,7 +37,7 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c if (!phpbb_url_matcher_dumped($root_path, $php_ext)) { - phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); + phpbb_create_dumped_url_matcher($finder, $root_path, $php_ext); } return phpbb_load_url_matcher($context, $root_path, $php_ext); @@ -47,15 +47,14 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c * Create a new UrlMatcher class and dump it into the cache file * * @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension * @return null */ -function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, $root_path, $php_ext) { $provider = new phpbb_controller_provider(); - $routes = $provider->get_paths($finder)->find(); + $routes = $provider->import_paths_from_finder($finder)->find(); $dumper = new PhpMatcherDumper($routes); $cached_url_matcher_dump = $dumper->dump(array( 'class' => 'phpbb_url_matcher', @@ -74,7 +73,8 @@ function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, Request function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context) { $provider = new phpbb_controller_provider(); - return new UrlMatcher($provider->get_paths($finder)->find(), $context); + $routes = $provider->import_paths_from_finder($finder)->find(); + return new UrlMatcher($routes, $context); } /** From 8e480a87253fd2e42af3fc4daaed2f49b9ae65c5 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 14:48:45 -0500 Subject: [PATCH 078/244] [feature/controller] Move include to app.php PHPBB3-10864 --- phpBB/app.php | 1 + phpBB/includes/event/kernel_request_subscriber.php | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index 9ff9069104..a2dbb1ae5b 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,6 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); +include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); // Start session management $user->session_begin(); diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php index 85c8c5b173..afb8464f80 100644 --- a/phpBB/includes/event/kernel_request_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -69,12 +69,7 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); - if (!function_exists('phpbb_load_url_matcher')) - { - include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); - } $matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); - $router_listener = new RouterListener($matcher, $context); $router_listener->onKernelRequest($event); } From 91ce6e8b16abb831e1e18b73cf857a257a59e432 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 14:59:14 -0500 Subject: [PATCH 079/244] [feature/controller] Turn off URL rewriting by default, add comments for usage PHPBB3-10864 --- phpBB/.htaccess | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 68021177f2..1713f8e522 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,7 +1,11 @@ Options +FollowSymLinks -RewriteEngine on +# +# Uncomment the following line if you will be using any of the URL +# rewriting below. +# +#RewriteEngine on # # Uncomment the statement below if you want to make use of @@ -10,9 +14,15 @@ RewriteEngine on # #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^(.*)$ app.php [QSA,L] +# +# Uncomment the following 3 lines if you want to rewrite URLs passed through +# the front controller to not use app.php in the actual URL. In other words, +# an controller that would by default be accessed at /app.php/my/controller +# can now be accessed at /my/controller directly. +# +#RewriteCond %{REQUEST_FILENAME} !-f +#RewriteCond %{REQUEST_FILENAME} !-d +#RewriteRule ^(.*)$ app.php [QSA,L] From db071d68541d132f5b06da652a2214b664552b1e Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 15:05:52 -0500 Subject: [PATCH 080/244] [feature/controller] Fix use of $this in global scope PHPBB3-10864 --- phpBB/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/app.php b/phpBB/app.php index a2dbb1ae5b..a7d645cb09 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,7 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); +include($phpbb_root_path . 'includes/functions_url_matcher' . $phpEx); // Start session management $user->session_begin(); From d0269629dcee2dda176807bdd944415d1713db7b Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 15:20:47 -0500 Subject: [PATCH 081/244] [feature/controller] Documentation about Symlinks in .htaccess PHPBB3-10864 --- phpBB/.htaccess | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 1713f8e522..9f635dba57 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,5 +1,3 @@ -Options +FollowSymLinks - # # Uncomment the following line if you will be using any of the URL @@ -23,6 +21,12 @@ Options +FollowSymLinks #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^(.*)$ app.php [QSA,L] + +# +# On Windows, you must also uncomment the following line so that SymLinks +# are followed. +# +#Options +FollowSymLinks From 14f44c17ad76878ed540cd5dd56a3a62b30dbd15 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:14:11 -0500 Subject: [PATCH 082/244] [feature/controller] phpbb_controller_exception instead of RuntimeException PHPBB3-10864 --- phpBB/includes/controller/exception.php | 24 ++++++++++++++++++++++++ phpBB/includes/controller/resolver.php | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 phpBB/includes/controller/exception.php diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php new file mode 100644 index 0000000000..da2fefc600 --- /dev/null +++ b/phpBB/includes/controller/exception.php @@ -0,0 +1,24 @@ +user->lang['CONTROLLER_NOT_SPECIFIED']); + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); } // Require a method name along with the service name if (stripos($controller, ':') === false) { - throw new RuntimeException($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); } list($service, $method) = explode(':', $controller); if (!$this->container->has($service)) { - throw new RuntimeException($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); } $controller_object = $this->container->get($service); @@ -92,6 +92,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object * @param string $controller Controller class name * @return bool False + * @throws phpbb_controller_exception */ public function getArguments(Request $request, $controller) { @@ -114,7 +115,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface } else { - throw new RuntimeException($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + throw new phpbb_controller_exception($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); } } From 235b0194f140a369137bd4d92bfd1b10d5e08787 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:16:25 -0500 Subject: [PATCH 083/244] [feature/controller] Update wording in .htaccess documentation comments PHPBB3-10864 --- phpBB/.htaccess | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 9f635dba57..d61ef7b893 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -15,8 +15,8 @@ # # Uncomment the following 3 lines if you want to rewrite URLs passed through # the front controller to not use app.php in the actual URL. In other words, -# an controller that would by default be accessed at /app.php/my/controller -# can now be accessed at /my/controller directly. +# a controller is by default accessed at /app.php/my/controller, but will then +# be accessed at /my/controller directly. # #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d From 45b3ab8e81a3cffae4d0ada8785620ea4209c207 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:18:02 -0500 Subject: [PATCH 084/244] [feature/controller] Move Response definition into a variable PHPBB3-10864 --- phpBB/includes/event/kernel_exception_subscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index cd6ea40c70..e2668d4560 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -67,7 +67,8 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $event->setResponse(new Response($this->template->assign_display('body'), 404)); + $response = new Response($this->template->assign_display('body'), 404); + $event->setResponse($response); } public static function getSubscribedEvents() From f42b36185c86dfe19974c866ce7e284263aff371 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:24:32 -0500 Subject: [PATCH 085/244] [feature/controller] Better explanation of the Options +FollowSymLinks line PHPBB3-10864 --- phpBB/.htaccess | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index d61ef7b893..3283b9beb8 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -23,8 +23,9 @@ #RewriteRule ^(.*)$ app.php [QSA,L] # -# On Windows, you must also uncomment the following line so that SymLinks -# are followed. +# If symbolic links are not already being followed, +# uncomment the line below. +# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/ # #Options +FollowSymLinks From b2598662af0b3a37b228cee03cbbf7d7160c7a11 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:26:00 -0500 Subject: [PATCH 086/244] [feature/controller] Clarify working paths after enabling rewriting PHPBB3-10864 --- phpBB/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 3283b9beb8..d0f65e345c 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -16,7 +16,7 @@ # Uncomment the following 3 lines if you want to rewrite URLs passed through # the front controller to not use app.php in the actual URL. In other words, # a controller is by default accessed at /app.php/my/controller, but will then -# be accessed at /my/controller directly. +# be accessible at either /app.php/my/controller or just /my/controller # #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d From a87a5dd566bd4b9481cdca86fa6f4bc3363d58de Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:31:32 -0500 Subject: [PATCH 087/244] [feature/controller] Fix tests PHPBB3-10864 --- tests/controller/controller_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index b73019a6a0..577feee517 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -33,7 +33,7 @@ class phpbb_controller_test extends phpbb_test_case { $provider = new phpbb_controller_provider; $routes = $provider - ->get_paths($this->extension_manager->get_finder()) + ->import_paths_from_finder($this->extension_manager->get_finder()) ->find('./tests/controller/'); // This will need to be updated if any new routes are defined From c9588572c9f40223de3445a211ca85b18f5294a4 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:20:15 -0500 Subject: [PATCH 088/244] [feature/controller] Add period before $phpEx PHPBB3-10864 --- phpBB/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/app.php b/phpBB/app.php index a7d645cb09..f1023ff1b5 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,7 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($phpbb_root_path . 'includes/functions_url_matcher' . $phpEx); +include($phpbb_root_path . 'includes/functions_url_matcher.' . $phpEx); // Start session management $user->session_begin(); From 76917558832b0102716448770f365585aac224e9 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:23:57 -0500 Subject: [PATCH 089/244] [feature/controller] Adapt functional tests given new controller framework PHPBB3-10864 --- .../functional/extension_controller_test.php | 129 +++++++----------- .../fixtures/ext/error/class/controller.php | 14 -- .../fixtures/ext/error/class/ext.php | 6 - .../ext/error/classtype/controller.php | 15 -- .../fixtures/ext/error/classtype/ext.php | 6 - .../ext/error/disabled/controller.php | 14 -- .../fixtures/ext/error/disabled/ext.php | 6 - .../fixtures/ext/foo/bar/config/routing.yml | 3 + .../fixtures/ext/foo/bar/config/services.yml | 3 + .../fixtures/ext/foo/bar/controller.php | 14 -- .../ext/foo/bar/controller/controller.php | 10 ++ tests/functional/fixtures/ext/foo/bar/ext.php | 12 +- .../prosilver/template/foobar_body.html | 5 - .../fixtures/ext/foobar/controller.php | 14 -- tests/functional/fixtures/ext/foobar/ext.php | 6 - .../prosilver/template/foobar_body.html | 5 - 16 files changed, 69 insertions(+), 193 deletions(-) delete mode 100644 tests/functional/fixtures/ext/error/class/controller.php delete mode 100644 tests/functional/fixtures/ext/error/class/ext.php delete mode 100644 tests/functional/fixtures/ext/error/classtype/controller.php delete mode 100644 tests/functional/fixtures/ext/error/classtype/ext.php delete mode 100644 tests/functional/fixtures/ext/error/disabled/controller.php delete mode 100644 tests/functional/fixtures/ext/error/disabled/ext.php create mode 100755 tests/functional/fixtures/ext/foo/bar/config/routing.yml create mode 100755 tests/functional/fixtures/ext/foo/bar/config/services.yml delete mode 100644 tests/functional/fixtures/ext/foo/bar/controller.php create mode 100755 tests/functional/fixtures/ext/foo/bar/controller/controller.php mode change 100644 => 100755 tests/functional/fixtures/ext/foo/bar/ext.php delete mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html delete mode 100644 tests/functional/fixtures/ext/foobar/controller.php delete mode 100644 tests/functional/fixtures/ext/foobar/ext.php delete mode 100644 tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index d92a830365..2f07c8a70f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -13,6 +13,14 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; + + static protected $fixtures = array( + 'foo/bar/config/routing.yml', + 'foo/bar/config/services.yml', + 'foo/bar/controller/controller.php', + 'foo/bar/ext.php', + ); + /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -22,15 +30,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c global $phpbb_root_path; parent::setUpBeforeClass(); - // these directories need to be created before the files can be copied $directories = array( - $phpbb_root_path . 'ext/error/class/', - $phpbb_root_path . 'ext/error/classtype/', - $phpbb_root_path . 'ext/error/disabled/', $phpbb_root_path . 'ext/foo/bar/', - $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/', - $phpbb_root_path . 'ext/foobar/', - $phpbb_root_path . 'ext/foobar/styles/prosilver/template/', + $phpbb_root_path . 'ext/foo/bar/config/', + $phpbb_root_path . 'ext/foo/bar/controller/', ); foreach ($directories as $dir) @@ -40,23 +43,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c mkdir($dir, 0777, true); } } - - $fixtures = array( - 'error/class/controller.php', - 'error/class/ext.php', - 'error/classtype/controller.php', - 'error/classtype/ext.php', - 'error/disabled/controller.php', - 'error/disabled/ext.php', - 'foo/bar/controller.php', - 'foo/bar/ext.php', - 'foo/bar/styles/prosilver/template/foobar_body.html', - 'foobar/controller.php', - 'foobar/ext.php', - 'foobar/styles/prosilver/template/foobar_body.html', - ); - - foreach ($fixtures as $fixture) + + foreach (self::$fixtures as $fixture) { if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) { @@ -65,6 +53,27 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + foreach (self::$fixtures as $fixture) + { + if (!unlink("{$phpbb_root_path}ext/$fixture")) + { + echo 'Could not delete file ' . $fixture; + } + } + + rmdir("{$phpbb_root_path}ext/foo/bar/config"); + rmdir("{$phpbb_root_path}ext/foo/bar/controller"); + rmdir("{$phpbb_root_path}ext/foo/bar"); + rmdir("{$phpbb_root_path}ext/foo"); + } + public function setUp() { parent::setUp(); @@ -75,72 +84,28 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check an extension at ./ext/foobar/ which should have the class - * phpbb_ext_foobar_controller - */ - public function test_foobar() - { - $this->phpbb_extension_manager->enable('foobar'); - $crawler = $this->request('GET', 'index.php?ext=foobar'); - $this->assert_response_success(); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $this->phpbb_extension_manager->purge('foobar'); - } - - /** - * Check an extension at ./ext/foo/bar/ which should have the class - * phpbb_ext_foo_bar_controller + * Check a controller for extension foo/bar */ public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'index.php?ext=foo/bar'); - $this->assert_response_success(); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/bar'); + $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foobar'); } /** - * Check the error produced by extension at ./ext/error/class which has class - * phpbb_ext_foobar_controller + * Check the error produced by extension at ./ext/does/not/exist + * + * If an extension is disabled, its routes are not loaded. Because we + * are not looking for a controller based on a specified extension, + * we don't know the difference between a route in a disabled + * extension and a route that is not defined anyway; it is the same + * error message. */ - public function test_error_class_name() + public function test_error_ext_disabled_or_404() { - $this->phpbb_extension_manager->enable('error/class'); - $crawler = $this->request('GET', 'index.php?ext=error/class'); - $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/class'); - } - - /** - * Check the error produced by extension at ./ext/error/classtype which has class - * phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface - */ - public function test_error_class_type() - { - $this->phpbb_extension_manager->enable('error/classtype'); - $crawler = $this->request('GET', 'index.php?ext=error/classtype'); - $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/classtype'); - } - - /** - * Check the error produced by extension at ./ext/error/disabled that is (obviously) - * a disabled extension - */ - public function test_error_ext_disabled() - { - $crawler = $this->request('GET', 'index.php?ext=error/disabled'); - $this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text()); - } - - /** - * Check the error produced by extension at ./ext/error/404 that is (obviously) - * not existant - */ - public function test_error_ext_missing() - { - $crawler = $this->request('GET', 'index.php?ext=error/404'); - $this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text()); + $crawler = $this->request('GET', 'app.php/does/not/exist'); + $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php deleted file mode 100644 index 74bbbee540..0000000000 --- a/tests/functional/fixtures/ext/error/class/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/class/ext.php b/tests/functional/fixtures/ext/error/class/ext.php deleted file mode 100644 index f97ad2b838..0000000000 --- a/tests/functional/fixtures/ext/error/class/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/classtype/ext.php b/tests/functional/fixtures/ext/error/classtype/ext.php deleted file mode 100644 index 35b1cd15a2..0000000000 --- a/tests/functional/fixtures/ext/error/classtype/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/disabled/ext.php b/tests/functional/fixtures/ext/error/disabled/ext.php deleted file mode 100644 index aec8051848..0000000000 --- a/tests/functional/fixtures/ext/error/disabled/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php new file mode 100755 index 0000000000..4c5274951f --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -0,0 +1,10 @@ + - -
This is for testing purposes.
- - diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php deleted file mode 100644 index ff35f12ee0..0000000000 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php deleted file mode 100644 index 7cf443d369..0000000000 --- a/tests/functional/fixtures/ext/foobar/ext.php +++ /dev/null @@ -1,6 +0,0 @@ - - -
This is for testing purposes.
- - From 74bc46049303952e5f16f61e9f63fa2eeaffbadc Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:43:08 -0500 Subject: [PATCH 090/244] [feature/controller] Rename improperly named controller exception class PHPBB3-10864 --- phpBB/includes/controller/exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php index da2fefc600..faa8b6b584 100644 --- a/phpBB/includes/controller/exception.php +++ b/phpBB/includes/controller/exception.php @@ -19,6 +19,6 @@ if (!defined('IN_PHPBB')) * Controller exception class * @package phpBB3 */ -class phpbb_controller_provider extends RuntimeException +class phpbb_controller_exception extends RuntimeException { } From 120267e58030eb4b7184e0d54166dfc8d905c3f7 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:27:55 -0500 Subject: [PATCH 091/244] [feature/controller] Correctly access user object PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 0e724ec608..5674a65118 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -115,7 +115,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface } else { - throw new phpbb_controller_exception($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); } } From e516680859744e69b696ac0054ec3aefd94175b7 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:28:35 -0500 Subject: [PATCH 092/244] [feature/controller] Use sizeof() instead of count() as per guidelines PHPBB3-10864 --- tests/controller/controller_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 577feee517..5a4c65e109 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -37,7 +37,7 @@ class phpbb_controller_test extends phpbb_test_case ->find('./tests/controller/'); // This will need to be updated if any new routes are defined - $this->assertEquals(2, count($routes)); + $this->assertEquals(2, sizeof($routes)); } public function test_controller_resolver() From 230897723c9e5fc5534d9781b04ffd8dac70d51b Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:29:35 -0500 Subject: [PATCH 093/244] [feature/controller] Reword comment for clarification PHPBB3-10864 --- tests/controller/controller_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 5a4c65e109..198fb3c6dd 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -43,9 +43,8 @@ class phpbb_controller_test extends phpbb_test_case public function test_controller_resolver() { $container = new ContainerBuilder(); - // For some reason, I cannot get it to load more than one services - // file at a time, even when givein multiple paths - // So instead, I am looping through all of the paths + // YamlFileLoader only uses one path at a time, so we need to loop + // through all of the ones we are using. foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path) { $loader = new YamlFileLoader($container, new FileLocator($path)); @@ -53,7 +52,7 @@ class phpbb_controller_test extends phpbb_test_case } // Autoloading classes within the tests folder does not work - // so I'll include them manually + // so I'll include them manually. if (!class_exists('phpbb_ext_foo_controller')) { include(__DIR__.'/ext/foo/controller.php'); From 0c75d3d7da9c5fd7ee1560597db684c9d1704c22 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:30:50 -0500 Subject: [PATCH 094/244] [feature/controller] Add test for missing argument in controller class PHPBB3-10864 --- tests/functional/extension_controller_test.php | 10 +++++++++- .../functional/fixtures/ext/foo/bar/config/routing.yml | 4 ++++ .../fixtures/ext/foo/bar/controller/controller.php | 5 +++++ tests/functional/fixtures/ext/foo/bar/ext.php | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 2f07c8a70f..b1e910aeac 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -91,7 +91,15 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/bar'); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foobar'); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + public function test_missing_argument() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/baz'); + $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 7ecaba9e71..945ef51366 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -1,3 +1,7 @@ foo_bar_controller: pattern: /foo/bar defaults: { _controller: foo_bar.controller:handle } + +foo_baz_controller: + pattern: /foo/baz + defaults: { _controller: foo_bar.controller:baz } diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 4c5274951f..def5184e8c 100755 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -7,4 +7,9 @@ class phpbb_ext_foo_bar_controller { return new Response('foo/bar controller handle() method', 200); } + + public function baz($test) + { + return new Response('Value of "test" URL argument is: ' . $test); + } } diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php index b50f95990e..7170209d53 100755 --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -1,6 +1,6 @@ Date: Fri, 16 Nov 2012 10:35:55 -0500 Subject: [PATCH 095/244] [feature/controller] Fix param block for controller callable PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 5674a65118..901aa7eaa0 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -90,7 +90,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface * controller. * * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object - * @param string $controller Controller class name + * @param mixed $controller A callable (controller class, method) * @return bool False * @throws phpbb_controller_exception */ From d41b1146e8947919ed9bdd41e6a30ad15e91d262 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:37:07 -0500 Subject: [PATCH 096/244] [feature/controller] Rename $root_path class property to $phpbb_root_path PHPBB3-10864 --- phpBB/includes/controller/helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 6b697c7e46..6dc3ec4626 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -39,7 +39,7 @@ class phpbb_controller_helper * phpBB root path * @var string */ - protected $root_path; + protected $phpbb_root_path; /** * PHP extension @@ -52,14 +52,14 @@ class phpbb_controller_helper * * @param phpbb_template $template Template object * @param phpbb_user $user User object - * @param string $root_path phpBB root path + * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user, $root_path, $php_ext) + public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) { $this->template = $template; $this->user = $user; - $this->root_path = $root_path; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } @@ -95,7 +95,7 @@ class phpbb_controller_helper */ public function url(array $url_parts, $query = '') { - return append_sid($this->root_path . implode('/', $url_parts), $query); + return append_sid($this->phpbb_root_path . implode('/', $url_parts), $query); } /** From 1952a4f276930edd16ca51fd690ed3e7965071da Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:38:40 -0500 Subject: [PATCH 097/244] [feature/controller] Flip method parameters, require $message PHPBB3-10864 --- phpBB/includes/controller/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 6dc3ec4626..6cacc8fefa 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -101,11 +101,11 @@ class phpbb_controller_helper /** * Output an error, effectively the same thing as trigger_error * - * @param string $code The error code (e.g. 404, 500, 503, etc.) * @param string $message The error message + * @param string $code The error code (e.g. 404, 500, 503, etc.) * @return Response A Reponse instance */ - public function error($code = 500, $message = '') + public function error($message, $code = 500) { $this->template->assign_vars(array( 'MESSAGE_TEXT' => $message, From ba1acdca0364a9cd54c705d946fbae2144c59554 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:42:10 -0500 Subject: [PATCH 098/244] [feature/controller] Use warning instead of echo for copy() and unlink() PHPBB3-10864 --- tests/functional/extension_controller_test.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index b1e910aeac..65a9c80df6 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -46,10 +46,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c foreach (self::$fixtures as $fixture) { - if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) - { - echo 'Could not copy file ' . $fixture; - } + copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"); } } @@ -62,10 +59,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c global $phpbb_root_path; foreach (self::$fixtures as $fixture) { - if (!unlink("{$phpbb_root_path}ext/$fixture")) - { - echo 'Could not delete file ' . $fixture; - } + unlink("{$phpbb_root_path}ext/$fixture"); } rmdir("{$phpbb_root_path}ext/foo/bar/config"); From 5b013ddf5c48e71166dcefd6d384aea1d801698a Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 11:41:05 -0500 Subject: [PATCH 099/244] [feature/controller] Add controller functional test with template PHPBB3-10864 --- .../functional/extension_controller_test.php | 32 ++++++++++++++++--- .../fixtures/ext/foo/bar/config/routing.yml | 4 +++ .../fixtures/ext/foo/bar/config/services.yml | 3 ++ .../ext/foo/bar/controller/controller.php | 15 +++++++++ .../prosilver/template/foo_bar_body.html | 3 ++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 65a9c80df6..9cc2e0e32f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -18,7 +18,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'foo/bar/config/routing.yml', 'foo/bar/config/services.yml', 'foo/bar/controller/controller.php', - 'foo/bar/ext.php', + 'foo/bar/styles/prosilver/template/foo_bar_body.html', ); /** @@ -34,6 +34,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_root_path . 'ext/foo/bar/', $phpbb_root_path . 'ext/foo/bar/config/', $phpbb_root_path . 'ext/foo/bar/controller/', + $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template', ); foreach ($directories as $dir) @@ -43,10 +44,12 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c mkdir($dir, 0777, true); } } - + foreach (self::$fixtures as $fixture) { - copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"); + copy( + "tests/functional/fixtures/ext/$fixture", + "{$phpbb_root_path}ext/$fixture"); } } @@ -57,6 +60,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c static public function tearDownAfterClass() { global $phpbb_root_path; + foreach (self::$fixtures as $fixture) { unlink("{$phpbb_root_path}ext/$fixture"); @@ -64,6 +68,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c rmdir("{$phpbb_root_path}ext/foo/bar/config"); rmdir("{$phpbb_root_path}ext/foo/bar/controller"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles"); rmdir("{$phpbb_root_path}ext/foo/bar"); rmdir("{$phpbb_root_path}ext/foo"); } @@ -78,7 +85,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check a controller for extension foo/bar + * Check a controller for extension foo/bar. */ public function test_foo_bar() { @@ -88,6 +95,21 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->purge('foo/bar'); } + /** + * Check the output of a controller using the template system + */ + public function test_controller_with_template() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/template'); + $this->assertContains("I am a variable", $crawler->filter('#content')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the error produced by calling a controller without a required + * argument. + */ public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); @@ -97,7 +119,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check the error produced by extension at ./ext/does/not/exist + * Check the error produced by extension at ./ext/does/not/exist. * * If an extension is disabled, its routes are not loaded. Because we * are not looking for a controller based on a specified extension, diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 945ef51366..123f5f1b73 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -5,3 +5,7 @@ foo_bar_controller: foo_baz_controller: pattern: /foo/baz defaults: { _controller: foo_bar.controller:baz } + +foo_template_controller: + pattern: /foo/template + defaults: { _controller: foo_bar.controller:template } diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml index d1db6fcb1d..33ced55af9 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/services.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -1,3 +1,6 @@ services: foo_bar.controller: class: phpbb_ext_foo_bar_controller + arguments: + - @controller.helper + - @template diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index def5184e8c..50ea5d034b 100755 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -3,6 +3,14 @@ use Symfony\Component\HttpFoundation\Response; class phpbb_ext_foo_bar_controller { + protected $template; + + public function __construct(phpbb_controller_helper $helper, phpbb_template $template) + { + $this->template = $template; + $this->helper = $helper; + } + public function handle() { return new Response('foo/bar controller handle() method', 200); @@ -12,4 +20,11 @@ class phpbb_ext_foo_bar_controller { return new Response('Value of "test" URL argument is: ' . $test); } + + public function template() + { + $this->template->assign_var('A_VARIABLE', 'I am a variable'); + + return $this->helper->render('foo_bar_body.html'); + } } diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html new file mode 100644 index 0000000000..8fb6994d3d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html @@ -0,0 +1,3 @@ + +
{A_VARIABLE}
+ From abf2575bdbad84ca2d139290789852ee51efd31c Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 13:04:12 -0500 Subject: [PATCH 100/244] [feature/controller] Remove URL rewriting by default PHPBB3-10864 --- phpBB/web.config | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/phpBB/web.config b/phpBB/web.config index e31a48b991..a73c328626 100644 --- a/phpBB/web.config +++ b/phpBB/web.config @@ -12,18 +12,6 @@ - - - - - - - - - - - -
From 4efbb893b7b8ada8766847dc59724faef9c18142 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 17:36:39 -0500 Subject: [PATCH 101/244] [feature/controller] Fix line endings and permissions, and check responses PHPBB3-10864 --- tests/functional/extension_controller_test.php | 4 ++++ .../fixtures/ext/foo/bar/config/routing.yml | 0 .../fixtures/ext/foo/bar/config/services.yml | 0 .../fixtures/ext/foo/bar/controller/controller.php | 0 tests/functional/fixtures/ext/foo/bar/ext.php | 12 ++++++------ 5 files changed, 10 insertions(+), 6 deletions(-) mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/config/routing.yml mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/config/services.yml mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/controller/controller.php mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/ext.php diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 9cc2e0e32f..ba4a4e8ef0 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -91,6 +91,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/bar'); + $this->assert_response_success(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -102,6 +103,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/template'); + $this->assert_response_success(); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -114,6 +116,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/baz'); + $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -130,6 +133,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php/does/not/exist'); + $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php old mode 100755 new mode 100644 index 7170209d53..74359d51ab --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -1,6 +1,6 @@ - Date: Sat, 17 Nov 2012 01:15:50 +0100 Subject: [PATCH 102/244] [ticket/11212] Do not rely on $request in send_status_line() PHPBB3-11212 --- phpBB/includes/functions.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3a5b100515..dd82c9dc46 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2858,8 +2858,6 @@ function meta_refresh($time, $url, $disable_cd_check = false) */ function send_status_line($code, $message) { - global $request; - if (substr(strtolower(@php_sapi_name()), 0, 3) === 'cgi') { // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though @@ -2867,18 +2865,35 @@ function send_status_line($code, $message) } else { - if ($request->server('SERVER_PROTOCOL')) - { - $version = $request->server('SERVER_PROTOCOL'); - } - else - { - $version = 'HTTP/1.0'; - } + $version = get_http_version(); header("$version $code $message", true, $code); } } +/** +* Returns the HTTP version used in the current request. +* +* Handles the case of being called before `$request` is present, +* In which case it falls back to the $_SERVER superglobal. +* +* @return string HTTP version +*/ +function get_http_version() +{ + global $request; + + if ($request && $request->server('SERVER_PROTOCOL')) + { + return $request->server('SERVER_PROTOCOL'); + } + else if (isset($_SERVER['SERVER_PROTOCOL'])) + { + return $_SERVER['SERVER_PROTOCOL']; + } + + return 'HTTP/1.0'; +} + //Form validation From 9cdef7984f5162fa19ce36852331f79de3561f66 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:17:23 +0100 Subject: [PATCH 103/244] [ticket/11212] Allow dispatcher to be absent during garbage_collection() PHPBB3-11212 --- phpBB/includes/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index dd82c9dc46..4754d5194f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5348,7 +5348,9 @@ function garbage_collection() * @event core.garbage_collection * @since 3.1-A1 */ - $phpbb_dispatcher->dispatch('core.garbage_collection'); + if (!empty($phpbb_dispatcher)) { + $phpbb_dispatcher->dispatch('core.garbage_collection'); + } // Unload cache, must be done before the DB connection if closed if (!empty($cache)) From 98921e0b87b25fcd5985edb747d5768cd8ccf18e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:17:45 +0100 Subject: [PATCH 104/244] [ticket/11213] Add missing global in install_update.php PHPBB3-11213 --- phpBB/install/install_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 8c044550f3..7f40015002 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -71,7 +71,7 @@ class install_update extends module function main($mode, $sub) { - global $style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; + global $phpbb_style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request; $this->tpl_name = 'install_update'; From b534a7a5790df55ab5f0d8aba8f40080d481bac4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:25:14 +0100 Subject: [PATCH 105/244] [ticket/11212] Rename get_http_version to phpbb_request_http_version() PHPBB3-11212 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4754d5194f..495f83e3a6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2865,7 +2865,7 @@ function send_status_line($code, $message) } else { - $version = get_http_version(); + $version = phpbb_request_http_version(); header("$version $code $message", true, $code); } } @@ -2878,7 +2878,7 @@ function send_status_line($code, $message) * * @return string HTTP version */ -function get_http_version() +function phpbb_request_http_version() { global $request; From 1affc35be9a5ee2cdf2cd2551e708c928fb96d88 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:25:38 +0100 Subject: [PATCH 106/244] [ticket/11212] Cosmetics PHPBB3-11212 --- phpBB/includes/functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 495f83e3a6..dbc040e5fe 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2873,7 +2873,7 @@ function send_status_line($code, $message) /** * Returns the HTTP version used in the current request. * -* Handles the case of being called before `$request` is present, +* Handles the case of being called before $request is present, * In which case it falls back to the $_SERVER superglobal. * * @return string HTTP version @@ -5348,7 +5348,8 @@ function garbage_collection() * @event core.garbage_collection * @since 3.1-A1 */ - if (!empty($phpbb_dispatcher)) { + if (!empty($phpbb_dispatcher)) + { $phpbb_dispatcher->dispatch('core.garbage_collection'); } From b8cf74217aacb90ac066eee4e8812a2c32caa58a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:32:40 +0100 Subject: [PATCH 107/244] [ticket/11212] Cosmetic surgery done right PHPBB3-11212 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index dbc040e5fe..ab4c7e1772 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2874,7 +2874,7 @@ function send_status_line($code, $message) * Returns the HTTP version used in the current request. * * Handles the case of being called before $request is present, -* In which case it falls back to the $_SERVER superglobal. +* in which case it falls back to the $_SERVER superglobal. * * @return string HTTP version */ From 8913b2c7c4ffc38d4caf34ca7014b8a07f11d19d Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 17 Nov 2012 17:48:20 -0500 Subject: [PATCH 108/244] [feature/controller] Use query string, not path info, for controller access This is hopefully just temporary until we can fix the relative path issue. PHPBB3-10864 --- phpBB/app.php | 8 ++++++++ phpBB/common.php | 7 ------- phpBB/includes/functions.php | 16 +--------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index f1023ff1b5..13bf3f0be1 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\HttpFoundation\Request; + /** */ @@ -24,6 +26,12 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('app'); +// Until we fix the issue with relative paths, we have to fake path info to +// allow urls like app.php?controller=foo/bar +$controller = $request->variable('controller', '', false, phpbb_request_interface::GET); +$uri = '/' . $controller; +$symfony_request = Request::create($uri); + $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); $response->send(); diff --git a/phpBB/common.php b/phpBB/common.php index a5ffcea8e4..e99b9edee5 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,8 +8,6 @@ * Minimum Requirement: PHP 5.3.3 */ -use Symfony\Component\HttpFoundation\Request; - /** */ if (!defined('IN_PHPBB')) @@ -105,11 +103,6 @@ $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); -// Instantiate the Symfony Request object -// This must be done before phpbb_request -// because otherwise globals are disabled -$symfony_request = Request::createFromGlobals(); - // Instantiate some basic classes $phpbb_dispatcher = $phpbb_container->get('dispatcher'); $request = $phpbb_container->get('request'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 88ce142195..17fc16ef86 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2346,20 +2346,6 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - // Make sure we have a Symfony Request object; tests do not have one - // unless they need it. - if ($symfony_request) - { - // Correct the path when we are accessing it through a controller - // This simply rewrites the value given by $phpbb_root_path to the - // script_path in config. - $path_info = $symfony_request->getPathInfo(); - if (!empty($path_info) && $path_info != '/') - { - $url = $config['script_path'] . '/' . substr($url, strlen($phpbb_root_path)); - } - } - $append_sid_overwrite = false; /** @@ -5056,7 +5042,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // Determine board url - we may need it later $board_url = generate_board_url() . '/'; - $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $config['script_path'] . '/'; + $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; From 4d6f6351dd0563b26105d15b98052d907f9c52ed Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 17 Nov 2012 18:05:32 -0500 Subject: [PATCH 109/244] [feature/controller] Allow injecting Symfony Request into controllers PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 901aa7eaa0..ee469aa9c8 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -109,6 +109,10 @@ class phpbb_controller_resolver implements ControllerResolverInterface { $arguments[] = $attributes[$param->name]; } + else if ($param->getClass() && $param->getClass()->isInstance($request)) + { + $arguments[] = $request; + } else if ($param->isDefaultValueAvailable()) { $arguments[] = $param->getDefaultValue(); From 7a3d9ed85dfd7f32a938070fff854e56bf39738e Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:11:24 -0500 Subject: [PATCH 110/244] [feature/controller] Fix functional tests to use query string for controllers PHPBB3-10864 --- tests/functional/extension_controller_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index ba4a4e8ef0..482fe9dfd3 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -90,7 +90,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/bar'); $this->assert_response_success(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -102,7 +102,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_controller_with_template() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/template'); + $crawler = $this->request('GET', 'app.php?controller=foo/template'); $this->assert_response_success(); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -115,7 +115,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/baz'); + $crawler = $this->request('GET', 'app.php?controller=foo/baz'); $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -132,7 +132,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_ext_disabled_or_404() { - $crawler = $this->request('GET', 'app.php/does/not/exist'); + $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } From 09d7367dfc80f87b2fa36785a1e4285666c2d58a Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:32:54 -0500 Subject: [PATCH 111/244] [feature/controller] Remove url rewriting until we use pathinfo in controllers PHPBB3-10864 --- phpBB/.htaccess | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index d0f65e345c..474f9774c2 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,34 +1,12 @@ - -# -# Uncomment the following line if you will be using any of the URL -# rewriting below. -# -#RewriteEngine on - # # Uncomment the statement below if you want to make use of # HTTP authentication and it does not already work. # This could be required if you are for example using PHP via Apache CGI. # +# +#RewriteEngine on #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] - -# -# Uncomment the following 3 lines if you want to rewrite URLs passed through -# the front controller to not use app.php in the actual URL. In other words, -# a controller is by default accessed at /app.php/my/controller, but will then -# be accessible at either /app.php/my/controller or just /my/controller -# -#RewriteCond %{REQUEST_FILENAME} !-f -#RewriteCond %{REQUEST_FILENAME} !-d -#RewriteRule ^(.*)$ app.php [QSA,L] - -# -# If symbolic links are not already being followed, -# uncomment the line below. -# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/ -# -#Options +FollowSymLinks - +# Order Allow,Deny From 53caf83233c962adbb68dcfb0f8172ebf788b8f7 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:35:04 -0500 Subject: [PATCH 112/244] [feature/controller] Remove now-unused code PHPBB3-10864 --- phpBB/includes/functions.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 17fc16ef86..02a9e33f2a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,9 +7,6 @@ * */ -use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; -use Symfony\Component\Routing\RequestContext; - /** * @ignore */ @@ -2338,7 +2335,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; - global $phpbb_dispatcher, $phpbb_root_path, $config, $symfony_request; + global $phpbb_dispatcher; if ($params === '' || (is_array($params) && empty($params))) { From 50a96a2a2d25734e3df451b0f821817213f085e6 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:40:24 -0500 Subject: [PATCH 113/244] [feature/controller] Update routing documentation for using query string PHPBB3-10864 --- phpBB/config/routing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/config/routing.yml b/phpBB/config/routing.yml index f6f728fa47..d8e890d063 100644 --- a/phpBB/config/routing.yml +++ b/phpBB/config/routing.yml @@ -4,6 +4,6 @@ # pattern: /foo # defaults: { _controller: foo_sevice:method } # -# The above will be accessed via app.php/foo and it will instantiate the -# "foo_service" service and call the "method" method. +# The above will be accessed via app.php?controller=foo and it will +# instantiate the "foo_service" service and call the "method" method. # From 440c66267ef768888617c211c7f05a5fd25e2378 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 18 Nov 2012 14:15:23 -0500 Subject: [PATCH 114/244] [ticket/11202] Add response assertions to file upload functional test. PHPBB3-11202 --- tests/functional/fileupload_form_test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index f7267fa659..3db389b4f9 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -64,6 +64,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); + $this->assert_response_success(); + # error message + $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->client->getResponse()->getContent()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } } From 7ec94208c4096b752e77503ef53382e126b7dab5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 18 Nov 2012 14:32:48 -0500 Subject: [PATCH 115/244] [ticket/11202] Fix comment char, use more descriptive comment. PHPBB3-11202 --- tests/functional/fileupload_form_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 3db389b4f9..99afcfdc3d 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -65,7 +65,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case { $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); - # error message + // ensure there was no error message rendered $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->client->getResponse()->getContent()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } From 60c0a1dd2ac2c733a670093ad440e3ba6be3be4d Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:51:05 -0500 Subject: [PATCH 116/244] [feature/controller] Don't use $user->lang() before container compilation PHPBB3-10864 --- phpBB/includes/di/pass/kernel_pass.php | 7 +++---- phpBB/language/en/app.php | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/di/pass/kernel_pass.php b/phpBB/includes/di/pass/kernel_pass.php index d186ff2767..a701ebcfa6 100644 --- a/phpBB/includes/di/pass/kernel_pass.php +++ b/phpBB/includes/di/pass/kernel_pass.php @@ -29,7 +29,6 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface public function process(ContainerBuilder $container) { $definition = $container->getDefinition('dispatcher'); - $user = $container->get('user'); foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) { @@ -39,12 +38,12 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface if (!isset($event['event'])) { - throw new InvalidArgumentException($user->lang('NO_EVENT_ATTRIBUTE', $id)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); } if (!isset($event['method'])) { - throw new InvalidArgumentException($user->lang('NO_METHOD_ATTRIBUTE', $id)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id)); } $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); @@ -60,7 +59,7 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; if (!$refClass->implementsInterface($interface)) { - throw new InvalidArgumentException($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface)); } $definition->addMethodCall('addSubscriberService', array($id, $class)); diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php index 2cbeaa2cba..2d67246369 100644 --- a/phpBB/language/en/app.php +++ b/phpBB/language/en/app.php @@ -47,11 +47,6 @@ $lang = array_merge($lang, array( 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "%s" is not defined in ./config/services.yml.', 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object %s must return a Symfony\Component\HttpFoundation\Response object.', - // Event Listener/Subscriber error messages - 'NO_EVENT_ATTRIBUTE' => 'Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', - 'NO_METHOD_ATTRIBUTE' => 'Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', - 'SUBSCRIBER_WRONG_TYPE' => 'Service "%1$s" must implement interface "%2$s".', - // Core error controller messages 'PAGE_NOT_FOUND_ERROR' => 'The page you have requested does not exist.', 'NOT_AUTHORISED_ERROR' => 'You do not have permission to access this page.', From 2f50d656481dca3c2aa28cd5035ce0d44e5c4977 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:51:32 -0500 Subject: [PATCH 117/244] [feature/controller] Remove unused language strings PHPBB3-10864 --- phpBB/language/en/app.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php index 2d67246369..cb56015c30 100644 --- a/phpBB/language/en/app.php +++ b/phpBB/language/en/app.php @@ -46,10 +46,4 @@ $lang = array_merge($lang, array( 'CONTROLLER_SERVICE_NOT_GIVEN' => 'The controller "%s" must have a service specified in ./config/routing.yml.', 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "%s" is not defined in ./config/services.yml.', 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object %s must return a Symfony\Component\HttpFoundation\Response object.', - - // Core error controller messages - 'PAGE_NOT_FOUND_ERROR' => 'The page you have requested does not exist.', - 'NOT_AUTHORISED_ERROR' => 'You do not have permission to access this page.', - 'NOT_AUTHENTICATED_ERROR' => 'You must log in to access this page.', - 'INTERNAL_SERVER_ERROR_ERROR' => 'An unknown error occured.', )); From 0f4f81b0966e29b5aaae5bf94e46260474ec0cb2 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:52:35 -0500 Subject: [PATCH 118/244] [feature/controller] Create Symfony Request in new function PHPBB3-10864 --- phpBB/app.php | 6 ++---- phpBB/includes/functions.php | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index 13bf3f0be1..c085f966c8 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\HttpFoundation\Request; - /** */ @@ -28,9 +26,9 @@ $user->setup('app'); // Until we fix the issue with relative paths, we have to fake path info to // allow urls like app.php?controller=foo/bar -$controller = $request->variable('controller', '', false, phpbb_request_interface::GET); +$controller = $request->variable('controller', ''); $uri = '/' . $controller; -$symfony_request = Request::create($uri); +$symfony_request = phpbb_create_symfony_request($uri, $request); $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 02a9e33f2a..820d96c9aa 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\HttpFoundation\Request; + /** * @ignore */ @@ -5430,3 +5432,40 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create a Symfony Request object from a given URI and phpbb_request object +* +* @param string $uri Request URI +* @param phpbb_request $request Request object +* @return Request A Symfony Request object +*/ +function phpbb_create_symfony_request($uri, phpbb_request $request) +{ + $request_method = $request->server('REQUEST_METHOD'); + $parameter_names = array(); + $parameter_names['request'] = array_merge( + $request->variable_names(phpbb_request_interface::GET), + // POST overwrites duplicated GET parameters + $request->variable_names(phpbb_request_interface::POST) + ); + $parameter_names['server'] = $request->variable_names(phpbb_request_interface::SERVER); + $parameter_names['files'] = $request->variable_names(phpbb_request_interface::FILES); + $parameter_names['cookie'] = $request->variable_names(phpbb_request_interface::COOKIE); + + $parameters = array( + 'request' => array(), + 'cookie' => array(), + 'files' => array(), + 'server' => array(), + ); + foreach ($parameter_names as $type => $names) + { + foreach ($names as $name) + { + $parameters[$type][$name] = $request->variable($name, ''); + } + } + + return Request::create($uri, $request_method, $parameters['request'], $parameters['cookie'], $parameters['files'], $parameters['server']); +} From e2bf66d0658ae7d7bb253083b73d5769c117746a Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:58:47 -0500 Subject: [PATCH 119/244] [feature/controller] Add documentation about input being HTML-escaped PHPBB3-10864 --- phpBB/includes/functions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 820d96c9aa..cdc05ca649 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5436,6 +5436,9 @@ function phpbb_to_numeric($input) /** * Create a Symfony Request object from a given URI and phpbb_request object * +* Note that everything passed into the Request object has already been HTML +* escaped by the phpbb_request object. +* * @param string $uri Request URI * @param phpbb_request $request Request object * @return Request A Symfony Request object From 41a95d2c646aba8d6a66ee046c532a51a9022784 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 18 Nov 2012 20:38:58 -0600 Subject: [PATCH 120/244] [ticket/11219] Update sequence values after loading fixtures If a value is provide for an auto_increment type of column, certain DBMSes do not update their internal sequencers. If a row is inserted later, it can be given an ID that is already in use, resulting in an error. The database test cases now resynchronise the sequencers before the tests are run. PHPBB3-11219 --- .../phpbb_database_test_case.php | 10 ++ ...phpbb_database_test_connection_manager.php | 129 ++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..0916679108 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -28,6 +28,16 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test ); } + protected function setUp() + { + parent::setUp(); + + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->post_setup_synchronisation(); + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index a43215bcf2..cae1720587 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -426,4 +426,133 @@ class phpbb_database_test_connection_manager $this->pdo->exec($query); } } + + /** + * Performs synchronisations on the database after a fixture has been loaded + */ + public function post_setup_synchronisation() + { + $this->ensure_connected(__METHOD__); + $queries = array(); + + switch ($this->config['dbms']) + { + case 'oracle': + // Get all of the information about the sequences + $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name + FROM USER_TRIGGERS t + JOIN USER_DEPENDENCIES d on d.name = t.trigger_name + JOIN USER_TRIGGER_COLS tc on (tc.trigger_name = t.trigger_name) + WHERE d.referenced_type = 'SEQUENCE' + AND d.type = 'TRIGGER'"; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the current max value of the table + $sql = "SELECT MAX({$row['COLUMN_NAME']}) + 1 FROM {$row['TABLE_NAME']}"; + + $max_result = $this->pdo->query($sql); + $max_row = $max_result->fetch(PDO::FETCH_NUM); + + if (!$max_row) + { + continue; + } + + $maxval = current($max_row); + if ($maxval == null) + { + $maxval = 1; + } + + // Get the sequence's next value + $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; + try + { + $nextval_result = $this->pdo->query($sql); + } + catch (PDOException $e) + { + // If we catch an exception here it's because the sequencer hasn't been initialized yet. + // If the table hasn't been used, then there's nothing to do. + continue; + } + $nextval_row = $nextval_result->fetch(PDO::FETCH_NUM); + + if ($nextval_row) + { + $nextval = current($nextval_row); + + // Make sure we aren't setting the new increment to zero. + if ($maxval != $nextval) + { + // This is a multi-step process. First we need to get the sequence back into position. + // That means either advancing it or moving it backwards. Sequences have a minimum value + // of 1, so you cannot go past that. Once the offset it determined, you have to request + // the next sequence value to actually move the pointer into position. So if you're at 21 + // and need to be back at 1, set the incrementer to -20. When it's requested, it'll give + // you 1. Then we have to set the increment amount back to 1 to resume normal behavior. + + // Move the sequence to the correct position. + $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY " . ($maxval - $nextval); + $this->pdo->exec($sql); + + // Select the next value to actually update the sequence values + $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; + $this->pdo->query($sql); + + // Reset the sequence's increment amount + $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY 1"; + $this->pdo->exec($sql); + } + } + } + break; + + case 'postgres': + // First get the sequences + $sequences = array(); + $sql = "SELECT relname FROM pg_class WHERE relkind = 'S'"; + $result = $this->pdo->query($sql); + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + $sequences[] = $row['relname']; + } + + // Now get the name of the column using it + foreach ($sequences as $sequence) + { + $table = str_replace('_seq', '', $sequence); + $sql = "SELECT column_name FROM information_schema.columns + WHERE table_name = '$table' + AND column_default = 'nextval(''$sequence''::regclass)'"; + $result = $this->pdo->query($sql); + $row = $result->fetch(PDO::FETCH_ASSOC); + + // Finally, set the new sequence value + if ($row) + { + $column = $row['column_name']; + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$column}) + 1 FROM {$table}), 1) AS val"; + $result = $this->pdo->query($sql); + $row = $result->fetch(PDO::FETCH_ASSOC); + + if ($row) + { + // The last parameter is false so that the system doesn't increment it again + $queries[] = "SELECT SETVAL('{$sequence}', {$row['val']}, false)"; + } + } + } + break; + } + + foreach ($queries as $query) + { + $this->pdo->exec($query); + } + } } From a7404409a8376e7db9f295e5cf598ccee59523b5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Nov 2012 13:49:04 +0100 Subject: [PATCH 121/244] [ticket/11219] Add unit test for inserting into a sequence column PHPBB3-11219 --- tests/dbal/write_sequence_test.php | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/dbal/write_sequence_test.php diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php new file mode 100644 index 0000000000..d2c30b4e89 --- /dev/null +++ b/tests/dbal/write_sequence_test.php @@ -0,0 +1,55 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); + } + + static public function write_sequence_data() + { + return array( + array( + 'ticket/11219', + 4, + ), + ); + } + + /** + * @dataProvider write_sequence_data + */ + public function test_write_sequence($username, $expected) + { + $db = $this->new_dbal(); + + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( + 'username' => $username, + 'username_clean' => $username, + 'user_permissions' => '', + 'user_sig' => '', + 'user_occ' => '', + 'user_interests' => '', + )); + $db->sql_query($sql); + + $this->assertEquals($expected, $db->sql_nextid()); + + $sql = "SELECT user_id + FROM phpbb_users + WHERE username_clean = '" . $db->sql_escape($username) . "'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals($expected, $db->sql_fetchfield('user_id')); + } +} From 30043502814cd42d824dc1d6bcb25bebc60adbed Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 11:47:42 -0500 Subject: [PATCH 122/244] [feature/controller] Correctly create Symfony object from globals PHPBB3-10864 --- phpBB/includes/functions.php | 62 ++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cdc05ca649..ee147969f9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5434,41 +5434,47 @@ function phpbb_to_numeric($input) } /** -* Create a Symfony Request object from a given URI and phpbb_request object +* Create a Symfony Request object from phpbb_request object * -* Note that everything passed into the Request object has already been HTML -* escaped by the phpbb_request object. -* -* @param string $uri Request URI * @param phpbb_request $request Request object * @return Request A Symfony Request object */ -function phpbb_create_symfony_request($uri, phpbb_request $request) +function phpbb_create_symfony_request(phpbb_request $request) { - $request_method = $request->server('REQUEST_METHOD'); - $parameter_names = array(); - $parameter_names['request'] = array_merge( - $request->variable_names(phpbb_request_interface::GET), - // POST overwrites duplicated GET parameters - $request->variable_names(phpbb_request_interface::POST) - ); - $parameter_names['server'] = $request->variable_names(phpbb_request_interface::SERVER); - $parameter_names['files'] = $request->variable_names(phpbb_request_interface::FILES); - $parameter_names['cookie'] = $request->variable_names(phpbb_request_interface::COOKIE); + // This function is meant to sanitize the global input arrays + $sanitizer = function(&$value, $key) { + $type_cast_helper = new phpbb_request_type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + }; - $parameters = array( - 'request' => array(), - 'cookie' => array(), - 'files' => array(), - 'server' => array(), - ); - foreach ($parameter_names as $type => $names) + // We need to re-enable the super globals so we can access them here + $request->enable_super_globals(); + $get_parameters = $_GET; + $post_parameters = $_POST; + $server_parameters = $_SERVER; + $files_parameters = $_FILES; + $cookie_parameters = $_COOKIE; + // And now disable them again for security + $request->disable_super_globals(); + + array_walk_recursive($get_parameters, $sanitizer); + array_walk_recursive($post_parameters, $sanitizer); + + // Until we fix the issue with relative paths, we have to fake path info + // to allow urls like app.php?controller=foo/bar + $controller = $request->variable('controller', ''); + $path_info = '/' . $controller; + $request_uri = $server_parameters['REQUEST_URI']; + + // Remove the query string from REQUEST_URI + if ($pos = strpos($request_uri, '?')) { - foreach ($names as $name) - { - $parameters[$type][$name] = $request->variable($name, ''); - } + $request_uri = substr($request_uri, 0, $pos); } - return Request::create($uri, $request_method, $parameters['request'], $parameters['cookie'], $parameters['files'], $parameters['server']); + // Add the path info (i.e. controller route) to the REQUEST_URI + $server_parameters['REQUEST_URI'] = $request_uri . $path_info; + $server_parameters['SCRIPT_NAME'] = ''; + + return new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); } From f8614bfc84ba9b9cc814b8f78e343005620f18f8 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 12:37:20 -0500 Subject: [PATCH 123/244] [feature/controller] Check for proper status codes from controllers PHPBB3-10864 --- phpBB/app.php | 7 +------ .../includes/event/kernel_exception_subscriber.php | 9 +++++++-- tests/functional/extension_controller_test.php | 13 ++++++++++++- .../fixtures/ext/foo/bar/config/routing.yml | 4 ++++ .../fixtures/ext/foo/bar/controller/controller.php | 5 +++++ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index c085f966c8..d93208d585 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -24,12 +24,7 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('app'); -// Until we fix the issue with relative paths, we have to fake path info to -// allow urls like app.php?controller=foo/bar -$controller = $request->variable('controller', ''); -$uri = '/' . $controller; -$symfony_request = phpbb_create_symfony_request($uri, $request); - +$symfony_request = phpbb_create_symfony_request($request); $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); $response->send(); diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index e2668d4560..e843df2e68 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -18,6 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface @@ -56,9 +57,11 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac { page_header($this->user->lang('INFORMATION')); + $exception = $event->getException(); + $this->template->assign_vars(array( 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $event->getException()->getMessage(), + 'MESSAGE_TEXT' => $exception->getMessage(), )); $this->template->set_filenames(array( @@ -67,7 +70,9 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $response = new Response($this->template->assign_display('body'), 404); + + $status_code = $exception instanceof NotFoundHttpException ? $exception->getStatusCode() : 500; + $response = new Response($this->template->assign_display('body'), $status_code); $event->setResponse($response); } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 482fe9dfd3..c7b585354e 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -116,11 +116,20 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/baz'); - $this->assertEquals(404, $this->client->getResponse()->getStatus()); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } + public function test_exception_thrown_status_code() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/exception'); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + /** * Check the error produced by extension at ./ext/does/not/exist. * @@ -133,6 +142,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); + // This is 500 response because the exception is thrown from within Symfony + // and does not provide a exception code, so we assign it 500 by default $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 123f5f1b73..7eb604f746 100644 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -9,3 +9,7 @@ foo_baz_controller: foo_template_controller: pattern: /foo/template defaults: { _controller: foo_bar.controller:template } + +foo_exception_controller: + pattern: /foo/foo_exception + defaults: { _controller: foo_bar.controller:exception } diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 50ea5d034b..5a91b5f681 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -27,4 +27,9 @@ class phpbb_ext_foo_bar_controller return $this->helper->render('foo_bar_body.html'); } + + public function exception() + { + throw new phpbb_controller_exception('Exception thrown from foo/exception route'); + } } From 01ec6085939d74e6a37c3ef041434db1c4b8f3e4 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 12:55:15 -0500 Subject: [PATCH 124/244] [feature/controller] Fix comments, check against more general HttpException PHPBB3-10864 --- phpBB/includes/event/kernel_exception_subscriber.php | 4 ++-- tests/functional/extension_controller_test.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index e843df2e68..f90989a74c 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpFoundation\Response; class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface @@ -71,7 +71,7 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $status_code = $exception instanceof NotFoundHttpException ? $exception->getStatusCode() : 500; + $status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; $response = new Response($this->template->assign_display('body'), $status_code); $event->setResponse($response); } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index c7b585354e..f28b321942 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -121,7 +121,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->purge('foo/bar'); } - public function test_exception_thrown_status_code() + /** + * Check the status code resulting from an exception thrown by a controller + */ + public function test_exception_should_result_in_500_status_code() { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/exception'); @@ -142,8 +145,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); - // This is 500 response because the exception is thrown from within Symfony - // and does not provide a exception code, so we assign it 500 by default $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } From 305f41cf1a540984fd7a71b61a601b1794e3bd04 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 13:16:55 -0500 Subject: [PATCH 125/244] [feature/controller] Fix misnamed route for functional test PHPBB3-10864 --- tests/functional/fixtures/ext/foo/bar/config/routing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 7eb604f746..09a30a8c67 100644 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -11,5 +11,5 @@ foo_template_controller: defaults: { _controller: foo_bar.controller:template } foo_exception_controller: - pattern: /foo/foo_exception + pattern: /foo/exception defaults: { _controller: foo_bar.controller:exception } From 1dff6d1bf988bb0d11a393fad0c0d0183366a5c9 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 20 Nov 2012 04:40:06 -0600 Subject: [PATCH 126/244] [ticket/11219] Recreate Oracle sequences instead of altering them The previous method would always leave a gap between the last value and the new one due to how you have to update the sequence values. To remove gaps in all situations, the options are to alter the USER_SEQUENCES table or just drop the sequence and recreate it. The prior requires elevated priveleges and the latter can break attached objects. Since we don't attach objects to the sequences, we won't have any problems doing it for the tests. PHPBB3-11219 --- ...phpbb_database_test_connection_manager.php | 69 +++++-------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index cae1720587..e79a764e1d 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -439,10 +439,11 @@ class phpbb_database_test_connection_manager { case 'oracle': // Get all of the information about the sequences - $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name + $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value FROM USER_TRIGGERS t - JOIN USER_DEPENDENCIES d on d.name = t.trigger_name - JOIN USER_TRIGGER_COLS tc on (tc.trigger_name = t.trigger_name) + JOIN USER_DEPENDENCIES d ON (d.name = t.trigger_name) + JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) + JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) WHERE d.referenced_type = 'SEQUENCE' AND d.type = 'TRIGGER'"; $result = $this->pdo->query($sql); @@ -450,63 +451,27 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the current max value of the table - $sql = "SELECT MAX({$row['COLUMN_NAME']}) + 1 FROM {$row['TABLE_NAME']}"; - + $sql = "SELECT MAX({$row['COLUMN_NAME']}) AS max FROM {$row['TABLE_NAME']}"; $max_result = $this->pdo->query($sql); - $max_row = $max_result->fetch(PDO::FETCH_NUM); + $max_row = $max_result->fetch(PDO::FETCH_ASSOC); if (!$max_row) { continue; } - $maxval = current($max_row); - if ($maxval == null) - { - $maxval = 1; - } + $maxval = (int)$max_row['MAX']; + $maxval++; - // Get the sequence's next value - $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; - try - { - $nextval_result = $this->pdo->query($sql); - } - catch (PDOException $e) - { - // If we catch an exception here it's because the sequencer hasn't been initialized yet. - // If the table hasn't been used, then there's nothing to do. - continue; - } - $nextval_row = $nextval_result->fetch(PDO::FETCH_NUM); - - if ($nextval_row) - { - $nextval = current($nextval_row); - - // Make sure we aren't setting the new increment to zero. - if ($maxval != $nextval) - { - // This is a multi-step process. First we need to get the sequence back into position. - // That means either advancing it or moving it backwards. Sequences have a minimum value - // of 1, so you cannot go past that. Once the offset it determined, you have to request - // the next sequence value to actually move the pointer into position. So if you're at 21 - // and need to be back at 1, set the incrementer to -20. When it's requested, it'll give - // you 1. Then we have to set the increment amount back to 1 to resume normal behavior. - - // Move the sequence to the correct position. - $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY " . ($maxval - $nextval); - $this->pdo->exec($sql); - - // Select the next value to actually update the sequence values - $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; - $this->pdo->query($sql); - - // Reset the sequence's increment amount - $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY 1"; - $this->pdo->exec($sql); - } - } + // This is not the "proper" way, but the proper way does not allow you to completely reset + // tables with no rows since you have to select the next value to make the change go into effct. + // You would have to go past the minimum value to set it correctly, but that's illegal. + // Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; + $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} + MINVALUE {$row['MIN_VALUE']} + INCREMENT BY {$row['INCREMENT_BY']} + START WITH $maxval"; } break; From 24939c822529f179a436abfa4e4e2f1b5bcb53ec Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 4 Feb 2012 17:29:10 +0000 Subject: [PATCH 127/244] [ticket/10601]Move Inbox the default in private messages module Did exactly as the answer here asked: http://area51.phpbb.com/phpBB/viewtopic.php?p=234111 PHPBB3-10601 --- phpBB/includes/functions_module.php | 20 +++++++++++++++++++- phpBB/install/install_install.php | 17 +++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ad76be9f2f..6f38dc60ce 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -759,7 +759,25 @@ class p_master } } - $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); + $u_title = $module_url . $delim . 'i='; + // if the item has a name use it, else use its id + if (empty($item_ary['name'])) + { + $u_title .= $item_ary['id']; + } + else + { + $u_title .= $item_ary['name']; + } + // If the item is not a category append the mode + if (!$item_ary['cat']) + { + if ($item_ary['is_duplicate']) + { + $u_title .= '&icat=' . $current_id; + } + $u_title .= '&mode=' . $item_ary['mode']; + } // Was not allowed in categories before - /*!$item_ary['cat'] && */ $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f80b8b5661..d4eba6eefd 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1478,8 +1478,13 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { + $basename = ''; + if (isset($module_categories_basenames[$cat_name])) + { + $basename = $module_categories_basenames[$cat_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, @@ -1507,8 +1512,13 @@ class install_install extends module { foreach ($subs as $level2_name) { + $basename = ''; + if (isset($module_categories_basenames[$level2_name])) + { + $basename = $module_categories_basenames[$level2_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], @@ -2115,6 +2125,9 @@ class install_install extends module 'UCP_ZEBRA' => null, ), ); + var $module_categories_basenames = array( + 'UCP_PM' => 'ucp_pm', + ); var $module_extras = array( 'acp' => array( From 61842c317a0d91278ef5d9bebe0f134be1a6d8f9 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 4 Feb 2012 20:07:21 -0500 Subject: [PATCH 128/244] [ticket/10601] Correctly access class property PHPBB3-10601 --- phpBB/install/install_install.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index d4eba6eefd..4b3d78f656 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1479,9 +1479,9 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $basename = ''; - if (isset($module_categories_basenames[$cat_name])) + if (isset($this->module_categories_basenames[$cat_name])) { - $basename = $module_categories_basenames[$cat_name]; + $basename = $this->module_categories_basenames[$cat_name]; } $module_data = array( 'module_basename' => $basename, @@ -1513,9 +1513,9 @@ class install_install extends module foreach ($subs as $level2_name) { $basename = ''; - if (isset($module_categories_basenames[$level2_name])) + if (isset($this->module_categories_basenames[$level2_name])) { - $basename = $module_categories_basenames[$level2_name]; + $basename = $this->module_categories_basenames[$level2_name]; } $module_data = array( 'module_basename' => $basename, From 81547ba980a09832240ab3523448a159f2d514e1 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 1 Aug 2012 15:54:42 +0100 Subject: [PATCH 129/244] [ticket/10601] Comment explaning the basename applied to categories Explain in the code where if (isset($this->module_categories_basenames[$cat_name])) and if (isset($this->module_categories_basenames[$level2_name])) exists, what does it do. PHPBB3-10601 --- phpBB/install/install_install.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 4b3d78f656..33d6586e48 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1479,6 +1479,7 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $basename = ''; + // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$cat_name])) { $basename = $this->module_categories_basenames[$cat_name]; @@ -1513,6 +1514,7 @@ class install_install extends module foreach ($subs as $level2_name) { $basename = ''; + // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$level2_name])) { $basename = $this->module_categories_basenames[$level2_name]; From 80da19ca7c12feb2996fd9d64dbdc8cb5c3cd2d9 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 7 Nov 2012 09:13:16 +0000 Subject: [PATCH 130/244] [ticket/10601] Database updating code This is what is needed to update the database to comply with these code changes PHPBB3-10601 --- phpBB/install/database_update.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 377e38c423..7b20404cf2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2749,6 +2749,33 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_url', ''); $config->set('site_home_text', ''); } + + + // ticket/10601: Make inbox default. Add basename to ucp's pm category + // Check if this was already applied + $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + FROM ' . MODULES_TABLE . ' + WHERE + module_basename = \'ucp_pm\' + ORDER BY module_id'; + $result = $db->sql_query_limit($sql, 1); + + if ($row = $db->sql_fetchrow($result)) + { + // Checking if this is not a category + if ($row['left_id'] === $row['right_id'] - 1) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_basename = \'ucp_pm\' + WHERE module_id = ' . (int)$row['parent_id']; + + _sql($sql, $errored, $error_ary); + + } + } + $db->sql_freeresult($result); break; } From 85ebbbaec471ea64f22543e006f8c160b02d503f Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 7 Nov 2012 22:26:54 +0000 Subject: [PATCH 131/244] [ticket/10601] Database updating code v2 Added the space after the (int) as requested PHPBB3-10601 --- phpBB/install/database_update.php | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7b20404cf2..620af92173 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2753,29 +2753,29 @@ function change_database_data(&$no_updates, $version) // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied - $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id - FROM ' . MODULES_TABLE . ' - WHERE - module_basename = \'ucp_pm\' - ORDER BY module_id'; - $result = $db->sql_query_limit($sql, 1); + $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + FROM ' . MODULES_TABLE . ' + WHERE + module_basename = \'ucp_pm\' + ORDER BY module_id'; + $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) + if ($row = $db->sql_fetchrow($result)) + { + // Checking if this is not a category + if ($row['left_id'] === $row['right_id'] - 1) { - // Checking if this is not a category - if ($row['left_id'] === $row['right_id'] - 1) - { - // This update is still not applied. Applying it - - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_basename = \'ucp_pm\' - WHERE module_id = ' . (int)$row['parent_id']; - - _sql($sql, $errored, $error_ary); + // This update is still not applied. Applying it - } + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_basename = \'ucp_pm\' + WHERE module_id = ' . (int) $row['parent_id']; + + _sql($sql, $errored, $error_ary); + } - $db->sql_freeresult($result); + } + $db->sql_freeresult($result); break; } From 1f9eaa1c56ec909bde82e1d7ad86079cd23f46bc Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Fri, 9 Nov 2012 08:51:18 +0000 Subject: [PATCH 132/244] [ticket/10601] Cosmetic code changes - Removed the double line before the addition - Moved the condition of the WHERE so that both are in the same line - Removed TABs from the black lines - Used double quotes instead of escaped single quotes. PHPBB3-10601 --- phpBB/install/database_update.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 620af92173..1dae3e566b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2749,14 +2749,12 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_url', ''); $config->set('site_home_text', ''); } - - + // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id FROM ' . MODULES_TABLE . ' - WHERE - module_basename = \'ucp_pm\' + WHERE module_basename = "ucp_pm" ORDER BY module_id'; $result = $db->sql_query_limit($sql, 1); @@ -2766,13 +2764,13 @@ function change_database_data(&$no_updates, $version) if ($row['left_id'] === $row['right_id'] - 1) { // This update is still not applied. Applying it - + $sql = 'UPDATE ' . MODULES_TABLE . ' SET module_basename = \'ucp_pm\' WHERE module_id = ' . (int) $row['parent_id']; - + _sql($sql, $errored, $error_ary); - + } } $db->sql_freeresult($result); From 764da977729aef331241d0cf0df77bd2e29d6256 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:41:58 +0100 Subject: [PATCH 133/244] [ticket/11174] include utf_tools in mysql backend when running tests include utf_tools file in the mysql search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 58a4dd7d6a..cd5f0cef67 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -86,6 +86,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From 6e8f142d3994f4568e40447d7cfd60cb5b082824 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:43:13 +0100 Subject: [PATCH 134/244] [ticket/11174] removes unnecessary space from word PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index cd5f0cef67..ff2e24aa05 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -238,7 +238,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $tmp_split_words[] = $word . ' '; + $tmp_split_words[] = $word; } } if ($phrase) From 6a76b85cbc741ef15c219c2c02c318bc43f29a59 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:46:15 +0100 Subject: [PATCH 135/244] [ticket/11174] add mysql unit tests PHPBB3-11174 --- tests/search/mysql_test.php | 155 ++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/mysql_test.php diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php new file mode 100644 index 0000000000..d9da2dfb2d --- /dev/null +++ b/tests/search/mysql_test.php @@ -0,0 +1,155 @@ +split_words; } +} + "; + eval($code); + } + return $wrapped; +} + +class phpbb_search_mysql_test extends phpbb_database_test_case +{ + protected $db; + protected $search; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_driver_null; + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } + + protected function tearDown() + { + parent::tearDown(); + } + + public function keywords() + { + return array( + // keywords + // terms + // ok + // split words + // common words + array( + 'fooo', + 'all', + true, + array('fooo'), + array(), + ), + array( + 'fooo baar', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // leading, trailing and multiple spaces + array( + ' foo bar ', + 'all', + true, + array('foo', 'bar'), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + null, + // short words count as "common" words + array('f'), + ), + array( + 'f o o', + 'all', + false, + null, + array('f', 'o', 'o'), + ), + array( + 'foo -bar', + 'all', + true, + array('-bar', 'foo'), + array(), + ), + // all negative + array( + '-foo', + 'all', + false, + null, + array(), + ), + array( + '-foo -bar', + 'all', + false, + array('-foo', '-bar'), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } + + public function assert_array_content_equals($one, $two) + { + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } +} From 615582f0dffc8d50604e3cc567e01e807a397bec Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:47:33 +0100 Subject: [PATCH 136/244] [ticket/11174] rename native wrapper class native wrapper class is limited to the native search backend hence renamed. the one used with mysql can be used with pgsql too. PHPBB3-11174 --- tests/search/native_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 66972079cf..722da9eb59 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,7 +7,7 @@ * */ -function phpbb_search_wrapper($class) +function phpbb_native_search_wrapper($class) { $wrapped = $class . '_wrapper'; if (!class_exists($wrapped)) @@ -45,7 +45,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_native'); + $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } From 2d1ac34de60a15e0b9e00a30140a08b4e329099d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 14:19:32 +0100 Subject: [PATCH 137/244] [ticket/11174] add test case for native test PHPBB3-11174 --- tests/search/native_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 722da9eb59..5f6d49c26c 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -106,6 +106,14 @@ class phpbb_search_native_test extends phpbb_database_test_case null, array('f', 'o', 'o'), ), + array( + 'f -o -o', + 'all', + false, + null, + null, + array('f', 'o', 'o'), + ), array( 'foo -bar', 'all', From 9d597dc2ee152f448139dc708663f9a81e5cb209 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:22:10 +0100 Subject: [PATCH 138/244] [ticket/11174] set config values set config values and use min length as 4 for wordss in test cases PHPBB3-11174 --- tests/search/mysql_test.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index d9da2dfb2d..44043da40d 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -42,6 +42,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case // dbal uses cache $cache = new phpbb_cache_driver_null; + // set config values + $config['fulltext_mysql_min_word_len'] = 4; + $config['fulltext_mysql_max_word_len'] = 254; + $this->db = $this->new_dbal(); $error = null; $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); @@ -77,10 +81,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case ), // leading, trailing and multiple spaces array( - ' foo bar ', + ' fooo baar ', 'all', true, - array('foo', 'bar'), + array('fooo', 'baar'), array(), ), // words too short @@ -100,25 +104,32 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array('f', 'o', 'o'), ), array( - 'foo -bar', + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', 'all', true, - array('-bar', 'foo'), + array('-baar', 'fooo'), array(), ), // all negative array( - '-foo', + '-fooo', 'all', false, null, array(), ), array( - '-foo -bar', + '-fooo -baar', 'all', false, - array('-foo', '-bar'), + array('-fooo', '-baar'), array(), ), ); From db2297827d92f09e52cd2dd6f6b4613e0c210fe7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:25:44 +0100 Subject: [PATCH 139/244] [ticket/11174] negation queries do not return false negation queries are split into words too and returns false in mysql search backend PHPBB3-11174 --- tests/search/mysql_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 44043da40d..56cce24c09 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -121,14 +121,14 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array( '-fooo', 'all', - false, - null, + true, + array('-fooo'), array(), ), array( '-fooo -baar', 'all', - false, + true, array('-fooo', '-baar'), array(), ), From c725b02df8a6d8838f6e0b7d82eaa8ec8f1839d1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:05:07 +0100 Subject: [PATCH 140/244] [ticket/11174] include utf_tools in postgres search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_postgres.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 08f64735b6..2880610655 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -121,6 +121,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From d308ee8a25ec6dc7b6e23cb78e14bd1d75f05a91 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:06:05 +0100 Subject: [PATCH 141/244] [ticket/11174] add unit tests for postgres search backend PHPBB3-11174 --- tests/search/postgres_test.php | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/postgres_test.php diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php new file mode 100644 index 0000000000..e20e6789b7 --- /dev/null +++ b/tests/search/postgres_test.php @@ -0,0 +1,155 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_driver_null; + + // set config values + $config['fulltext_postgres_min_word_len'] = 4; + $config['fulltext_postgres_max_word_len'] = 254; + + if(!function_exists('phpbb_search_wrapper')) + { + include('mysql_test.' . $phpEx); + } + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_postgres'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } + + protected function tearDown() + { + parent::tearDown(); + } + + public function keywords() + { + return array( + // keywords + // terms + // ok + // split words + // common words + array( + 'fooo', + 'all', + true, + array('fooo'), + array(), + ), + array( + 'fooo baar', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // leading, trailing and multiple spaces + array( + ' fooo baar ', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + null, + // short words count as "common" words + array('f'), + ), + array( + 'f o o', + 'all', + false, + null, + array('f', 'o', 'o'), + ), + array( + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', + 'all', + true, + array('-baar', 'fooo'), + array(), + ), + // all negative + array( + '-fooo', + 'all', + true, + array('-fooo'), + array(), + ), + array( + '-fooo -baar', + 'all', + true, + array('-fooo', '-baar'), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } + + public function assert_array_content_equals($one, $two) + { + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } +} From 3ed4fc437e2a88638d705b8f4cab23eacf39fe3c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:08:34 -0500 Subject: [PATCH 142/244] [ticket/11174] Move assertion definition to base class. PHPBB3-11174 --- tests/search/native_test.php | 16 ---------------- .../test_framework/phpbb_database_test_case.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 5f6d49c26c..21cbde496a 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -175,20 +175,4 @@ class phpbb_search_native_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important - // but one array_diff is not enough! - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..514619687a 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -141,4 +141,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { return $matches[1] . strtoupper($matches[2]) . $matches[3]; } + + public function assert_array_content_equals($one, $two) + { + // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important + // but one array_diff is not enough! + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } } From 04480ec4ae8435db37072cd976e7591a3abaafb9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:09:35 -0500 Subject: [PATCH 143/244] [ticket/11174] Delete copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 14 -------------- tests/search/postgres_test.php | 14 -------------- 2 files changed, 28 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 56cce24c09..5e5d5c9846 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -149,18 +149,4 @@ class phpbb_search_mysql_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index e20e6789b7..d3172c6457 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -138,18 +138,4 @@ class phpbb_search_postgres_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } From a5900a6b1120a3d062e6d51579872bf940b13dcb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:18:39 -0500 Subject: [PATCH 144/244] [ticket/11174] Extract phpbb_search_test_case. PHPBB3-11174 --- tests/search/native_test.php | 21 ++------------ .../test_framework/phpbb_search_test_case.php | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 tests/test_framework/phpbb_search_test_case.php diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 21cbde496a..544ab7ca17 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,24 +7,9 @@ * */ -function phpbb_native_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_must_contain_ids() { return \$this->must_contain_ids; } - public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_native_test extends phpbb_database_test_case +class phpbb_search_native_test extends phpbb_search_test_case { protected $db; protected $search; @@ -45,7 +30,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); + $class = self::get_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php new file mode 100644 index 0000000000..8b378186df --- /dev/null +++ b/tests/test_framework/phpbb_search_test_case.php @@ -0,0 +1,28 @@ +must_contain_ids; } + public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } +} + "; + eval($code); + } + return $wrapped; + } +} From 4d1486b08cd2f1e75527ed3b54664361934258a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:22:43 -0500 Subject: [PATCH 145/244] [ticket/11174] Eliminate search wrapper copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 20 +++---------------- tests/search/postgres_test.php | 11 ++++------ .../test_framework/phpbb_search_test_case.php | 1 + 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 5e5d5c9846..cf89facc83 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -7,23 +7,9 @@ * */ -function phpbb_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_split_words() { return \$this->split_words; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_mysql_test extends phpbb_database_test_case +class phpbb_search_mysql_test extends phpbb_search_test_case { protected $db; protected $search; @@ -48,7 +34,7 @@ class phpbb_search_mysql_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); + $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index d3172c6457..211755c7db 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_search_postgres_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; + +class phpbb_search_postgres_test extends phpbb_search_test_case { protected $db; protected $search; @@ -30,14 +32,9 @@ class phpbb_search_postgres_test extends phpbb_database_test_case $config['fulltext_postgres_min_word_len'] = 4; $config['fulltext_postgres_max_word_len'] = 254; - if(!function_exists('phpbb_search_wrapper')) - { - include('mysql_test.' . $phpEx); - } - $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_postgres'); + $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php index 8b378186df..418d352c17 100644 --- a/tests/test_framework/phpbb_search_test_case.php +++ b/tests/test_framework/phpbb_search_test_case.php @@ -19,6 +19,7 @@ class $wrapped extends $class { public function get_must_contain_ids() { return \$this->must_contain_ids; } public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } + public function get_split_words() { return \$this->split_words; } } "; eval($code); From 4b5e90a2bd7380d67a0aba053b2788ce7d9abd89 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:45:48 -0500 Subject: [PATCH 146/244] [ticket/11174] Empty fixture for when we don't need any data. PHPBB3-11174 --- tests/fixtures/empty.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/fixtures/empty.xml diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml new file mode 100644 index 0000000000..96eb1ab483 --- /dev/null +++ b/tests/fixtures/empty.xml @@ -0,0 +1,5 @@ + + + +
+
From 0c430a1f9365260502b7b293b32a34f97edeada4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:46:15 -0500 Subject: [PATCH 147/244] [ticket/11174] These tests do not need posts fixtures. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/postgres_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index cf89facc83..097e46d855 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -16,7 +16,7 @@ class phpbb_search_mysql_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 211755c7db..b6dc5ef1a3 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -16,7 +16,7 @@ class phpbb_search_postgres_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() From cb2d029abf2d4857fa462f46af21728afde3cd28 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:56:32 -0500 Subject: [PATCH 148/244] [ticket/11174] Drop needless teardown functions. PHPBB3-11174 --- tests/search/mysql_test.php | 5 ----- tests/search/native_test.php | 5 ----- tests/search/postgres_test.php | 5 ----- 3 files changed, 15 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 097e46d855..9f38ef2ef6 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -38,11 +38,6 @@ class phpbb_search_mysql_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 544ab7ca17..53d7a1fe78 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -34,11 +34,6 @@ class phpbb_search_native_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b6dc5ef1a3..b8c9bcfbe9 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -38,11 +38,6 @@ class phpbb_search_postgres_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( From 7dcb03faf1e9c2374f5d5fd36e3b01e8f0315d73 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 09:06:56 -0500 Subject: [PATCH 149/244] [ticket/11174] Delete more copy pasting. PHPBB3-11174 --- tests/search/common_test_case.php | 106 ++++++++++++++++++++++++++++++ tests/search/mysql_test.php | 97 +-------------------------- tests/search/postgres_test.php | 97 +-------------------------- 3 files changed, 110 insertions(+), 190 deletions(-) create mode 100644 tests/search/common_test_case.php diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php new file mode 100644 index 0000000000..dd04f7048c --- /dev/null +++ b/tests/search/common_test_case.php @@ -0,0 +1,106 @@ +search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } +} diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 9f38ef2ef6..e1538bc81c 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; +require_once dirname(__FILE__) . '/common_test_case.php'; -class phpbb_search_mysql_test extends phpbb_search_test_case +class phpbb_search_mysql_test extends phpbb_search_common_test_case { protected $db; protected $search; @@ -37,97 +37,4 @@ class phpbb_search_mysql_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - - public function keywords() - { - return array( - // keywords - // terms - // ok - // split words - // common words - array( - 'fooo', - 'all', - true, - array('fooo'), - array(), - ), - array( - 'fooo baar', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // leading, trailing and multiple spaces - array( - ' fooo baar ', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // words too short - array( - 'f', - 'all', - false, - null, - // short words count as "common" words - array('f'), - ), - array( - 'f o o', - 'all', - false, - null, - array('f', 'o', 'o'), - ), - array( - 'f -o -o', - 'all', - false, - null, - array('f', '-o', '-o'), - ), - array( - 'fooo -baar', - 'all', - true, - array('-baar', 'fooo'), - array(), - ), - // all negative - array( - '-fooo', - 'all', - true, - array('-fooo'), - array(), - ), - array( - '-fooo -baar', - 'all', - true, - array('-fooo', '-baar'), - array(), - ), - ); - } - - /** - * @dataProvider keywords - */ - public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) - { - $rv = $this->search->split_keywords($keywords, $terms); - $this->assertEquals($ok, $rv); - if ($ok) - { - // only check criteria if the search is going to be performed - $this->assert_array_content_equals($split_words, $this->search->get_split_words()); - } - $this->assert_array_content_equals($common, $this->search->get_common_words()); - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b8c9bcfbe9..6a65e6bf8f 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; +require_once dirname(__FILE__) . '/common_test_case.php'; -class phpbb_search_postgres_test extends phpbb_search_test_case +class phpbb_search_postgres_test extends phpbb_search_common_test_case { protected $db; protected $search; @@ -37,97 +37,4 @@ class phpbb_search_postgres_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - - public function keywords() - { - return array( - // keywords - // terms - // ok - // split words - // common words - array( - 'fooo', - 'all', - true, - array('fooo'), - array(), - ), - array( - 'fooo baar', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // leading, trailing and multiple spaces - array( - ' fooo baar ', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // words too short - array( - 'f', - 'all', - false, - null, - // short words count as "common" words - array('f'), - ), - array( - 'f o o', - 'all', - false, - null, - array('f', 'o', 'o'), - ), - array( - 'f -o -o', - 'all', - false, - null, - array('f', '-o', '-o'), - ), - array( - 'fooo -baar', - 'all', - true, - array('-baar', 'fooo'), - array(), - ), - // all negative - array( - '-fooo', - 'all', - true, - array('-fooo'), - array(), - ), - array( - '-fooo -baar', - 'all', - true, - array('-fooo', '-baar'), - array(), - ), - ); - } - - /** - * @dataProvider keywords - */ - public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) - { - $rv = $this->search->split_keywords($keywords, $terms); - $this->assertEquals($ok, $rv); - if ($ok) - { - // only check criteria if the search is going to be performed - $this->assert_array_content_equals($split_words, $this->search->get_split_words()); - } - $this->assert_array_content_equals($common, $this->search->get_common_words()); - } } From 79237b60b6b234e10f14cbcb00691b5e4374fd04 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 10:24:31 -0500 Subject: [PATCH 150/244] [ticket/11174] Global $cache is a cache service instance. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/native_test.php | 2 +- tests/search/postgres_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index e1538bc81c..3ba3915714 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_mysql_min_word_len'] = 4; diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 53d7a1fe78..eeee3a44f3 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); $this->db = $this->new_dbal(); $error = null; diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 6a65e6bf8f..9c77e0c09e 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_postgres_min_word_len'] = 4; From a4cc07617726bffd4c64cdebaa2e20a463990c5d Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 28 Nov 2012 19:36:13 +0000 Subject: [PATCH 151/244] [ticket/10601] Requested code changes - Renamed the comment to PHPBB3-10601 - Removed backslashes - Traded double quotes into single quotes inside. PHPBB3-10601 --- phpBB/install/database_update.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 1dae3e566b..eed484dfae 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2753,9 +2753,9 @@ function change_database_data(&$no_updates, $version) // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id - FROM ' . MODULES_TABLE . ' - WHERE module_basename = "ucp_pm" - ORDER BY module_id'; + FROM ' . MODULES_TABLE . " + WHERE module_basename = 'ucp_pm' + ORDER BY module_id"; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) @@ -2765,9 +2765,9 @@ function change_database_data(&$no_updates, $version) { // This update is still not applied. Applying it - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_basename = \'ucp_pm\' - WHERE module_id = ' . (int) $row['parent_id']; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['parent_id']; _sql($sql, $errored, $error_ary); From 1d9891588182c831aeb1ce20065f6ceaa3f892b4 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 28 Nov 2012 19:37:16 +0000 Subject: [PATCH 152/244] [ticket/10601] Comment to help understanding the code PHPBB3-10601 --- phpBB/includes/functions_module.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 6f38dc60ce..0d387ace6d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -767,6 +767,7 @@ class p_master } else { + // if the category has a name, then use it. $u_title .= $item_ary['name']; } // If the item is not a category append the mode From 83e85810aa7b04b992c8c24ec8b2eac700c4594e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 6 Nov 2012 14:28:46 -0500 Subject: [PATCH 153/244] [ticket/11095] Use get method in jumpboxes. PHPBB3-11095 --- phpBB/styles/prosilver/template/jumpbox.html | 2 +- phpBB/styles/subsilver2/template/jumpbox.html | 2 +- phpBB/styles/subsilver2/template/mcp_jumpbox.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/jumpbox.html b/phpBB/styles/prosilver/template/jumpbox.html index ff234464dc..562c115495 100644 --- a/phpBB/styles/prosilver/template/jumpbox.html +++ b/phpBB/styles/prosilver/template/jumpbox.html @@ -10,7 +10,7 @@ - +
diff --git a/phpBB/styles/subsilver2/template/jumpbox.html b/phpBB/styles/subsilver2/template/jumpbox.html index f4153d7692..0a11524813 100644 --- a/phpBB/styles/subsilver2/template/jumpbox.html +++ b/phpBB/styles/subsilver2/template/jumpbox.html @@ -1,6 +1,6 @@ - + diff --git a/phpBB/styles/subsilver2/template/mcp_jumpbox.html b/phpBB/styles/subsilver2/template/mcp_jumpbox.html index 734222bc77..0e3433e3d6 100644 --- a/phpBB/styles/subsilver2/template/mcp_jumpbox.html +++ b/phpBB/styles/subsilver2/template/mcp_jumpbox.html @@ -1,6 +1,6 @@ - +{L_JUMP_TO}{L_COLON} "; + } + } + return $hidden; +} + /** * Generate page header */ function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $request; if (defined('HEADER_INC')) { @@ -5135,6 +5169,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $timezone_name = $user->lang['timezones'][$timezone_name]; } + $hidden_fields_for_jumpbox = phpbb_build_hidden_fields_for_query_params($request, array('f')); + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -5149,6 +5185,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'HIDDEN_FIELDS_FOR_JUMPBOX' => $hidden_fields_for_jumpbox, 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], @@ -5507,7 +5544,8 @@ function phpbb_to_numeric($input) function phpbb_create_symfony_request(phpbb_request $request) { // This function is meant to sanitize the global input arrays - $sanitizer = function(&$value, $key) { + $sanitizer = function(&$value, $key) + { $type_cast_helper = new phpbb_request_type_cast_helper(); $type_cast_helper->set_var($value, $value, gettype($value), true); }; diff --git a/phpBB/styles/prosilver/template/jumpbox.html b/phpBB/styles/prosilver/template/jumpbox.html index 562c115495..dd793fbadc 100644 --- a/phpBB/styles/prosilver/template/jumpbox.html +++ b/phpBB/styles/prosilver/template/jumpbox.html @@ -17,6 +17,7 @@
+ {HIDDEN_FIELDS_FOR_JUMPBOX}
- - + - + - + - + - + - + - + + - + + From dd6983b14bba4326d824b3abb130eafc5e8f666c Mon Sep 17 00:00:00 2001 From: Senky Date: Thu, 17 May 2012 20:01:44 +0200 Subject: [PATCH 230/244] [ticket/10841] changing affectedrows check to COUNT in sql this sould reduce load and be faster. Also freeresult functions added PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 19e1b45787..b95d2d4ee8 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -134,11 +134,11 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; - // check for count of installed languages - $sql = 'SELECT lang_id + // check if there are any user-selectable languages + $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if( $db->sql_affectedrows() > 1 ) + if( $db->sql_fetchfield('languages_count') > 1 ) { $s_more_languages = true; } @@ -146,13 +146,14 @@ class ucp_prefs { $s_more_languages = false; } + $db->sql_freeresult($result); - // check for count of installed and active styles - $sql = 'SELECT style_id + // check if there are any user-selectable styles + $sql = 'SELECT COUNT(style_id) as styles_count FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if( $db->sql_affectedrows() > 1 ) + if( $db->sql_fetchfield('styles_count') > 1 ) { $s_more_styles = true; } @@ -160,6 +161,7 @@ class ucp_prefs { $s_more_styles = false; } + $db->sql_freeresult($result); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', From f7508c3f042091f163a87829a051312fa58630f1 Mon Sep 17 00:00:00 2001 From: Senky Date: Wed, 7 Nov 2012 10:28:25 +0100 Subject: [PATCH 231/244] [ticket/10841] removing unnecessary spacing PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index b95d2d4ee8..e84c7e662a 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -138,7 +138,7 @@ class ucp_prefs $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if( $db->sql_fetchfield('languages_count') > 1 ) + if($db->sql_fetchfield('languages_count') > 1) { $s_more_languages = true; } @@ -153,7 +153,7 @@ class ucp_prefs FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if( $db->sql_fetchfield('styles_count') > 1 ) + if($db->sql_fetchfield('styles_count') > 1) { $s_more_styles = true; } From 120accb9d4b2a89ca05f712a54427e072584c2f9 Mon Sep 17 00:00:00 2001 From: Senky Date: Thu, 8 Nov 2012 17:30:58 +0100 Subject: [PATCH 232/244] [ticket/10841] adding space after if PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index e84c7e662a..c6e43b831c 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -138,7 +138,7 @@ class ucp_prefs $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if($db->sql_fetchfield('languages_count') > 1) + if ($db->sql_fetchfield('languages_count') > 1) { $s_more_languages = true; } @@ -153,7 +153,7 @@ class ucp_prefs FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if($db->sql_fetchfield('styles_count') > 1) + if ($db->sql_fetchfield('styles_count') > 1) { $s_more_styles = true; } From 0793f8e2e60453db8de1ff8e231a36b2c9024f3d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 11:54:49 -0500 Subject: [PATCH 233/244] [ticket/10841] Revert whitespace changes. PHPBB3-10841 --- .../template/ucp_prefs_personal.html | 26 +++++++++---------- .../template/ucp_prefs_personal.html | 14 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 416343e57d..01e0c9ba28 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -12,21 +12,21 @@
- +
- +

{L_ALLOW_PM_EXPLAIN}
- +
@@ -34,17 +34,17 @@

{L_HIDE_ONLINE_EXPLAIN}
- +
- +
- - + +
@@ -82,7 +82,7 @@
- +
@@ -99,9 +99,9 @@ - +
- {S_HIDDEN_FIELDS}  + {S_HIDDEN_FIELDS}  {S_FORM_TOKEN}
@@ -115,9 +115,9 @@ function customDates() { var e = document.getElementById('dateoptions'); - + e.selectedIndex = e.length - 1; - + // Loop and match date_format in menu for (var i = 0; i < e.length; i++) { @@ -127,7 +127,7 @@ break; } } - + // Show/hide custom field if (e.selectedIndex == e.length - 1) { diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index c604671c5c..4cd0f37a80 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -29,35 +29,35 @@
- + - + - + - + - + - + - + From a8e74f5292aaa74e2035dd5f3ab972f0201a1fe7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 12:02:30 -0500 Subject: [PATCH 234/244] [ticket/10841] Revert more whitespace changes. PHPBB3-10841 --- phpBB/styles/prosilver/template/ucp_prefs_personal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 01e0c9ba28..600319fc72 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -52,14 +52,14 @@
- +
- +
From dc649ad3cd8ea4520ad3694027679d6312c9495f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 11:34:16 -0500 Subject: [PATCH 235/244] [ticket/11248] Line endings to LF. PHPBB3-11248 --- tests/session/append_sid_test.php | 101 +++++++++++++++--------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 88f6f0718e..ce7bf71215 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -1,51 +1,50 @@ - 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), - - // Custom sid parameter - array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), - - // Testing anchors - array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), - array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), - - // Anchors and custom sid - array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), - array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - - // Empty parameters should not append the ? - array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), - array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), - array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), - ); - } - - /** - * @dataProvider append_sid_data - */ - public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) - { - $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); - } -} - + 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), + array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), + array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) + { + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} From dbb54b217b4d0c0669a566f9c950e8331887d276 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Wed, 5 Dec 2012 22:57:06 -0600 Subject: [PATCH 236/244] [ticket/11219] Coding guidelines and naming consistency changes PHPBB3-11219 --- tests/dbal/write_sequence_test.php | 2 +- ...phpbb_database_test_connection_manager.php | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index d2c30b4e89..8975cfbfb1 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -13,7 +13,7 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/three_users.xml'); } static public function write_sequence_data() diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 97281a0812..d7c2804aa7 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -430,17 +430,17 @@ class phpbb_database_test_connection_manager /** * Performs synchronisations on the database after a fixture has been loaded * - * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $tables Tables contained within the loaded fixture + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $xml_data_set Information about the tables contained within the loaded fixture * * @return null */ - public function post_setup_synchronisation($xmlDataSet) + public function post_setup_synchronisation($xml_data_set) { $this->ensure_connected(__METHOD__); $queries = array(); // Get escaped versions of the table names used in the fixture - $table_names = array_map(array($this->pdo, 'PDO::quote'), $xmlDataSet->getTableNames()); + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); switch ($this->config['dbms']) { @@ -469,18 +469,20 @@ class phpbb_database_test_connection_manager continue; } - $maxval = (int)$max_row['MAX']; - $maxval++; + $max_val = (int) $max_row['MAX']; + $max_val++; - // This is not the "proper" way, but the proper way does not allow you to completely reset - // tables with no rows since you have to select the next value to make the change go into effct. - // You would have to go past the minimum value to set it correctly, but that's illegal. - // Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + /** + * This is not the "proper" way, but the proper way does not allow you to completely reset + * tables with no rows since you have to select the next value to make the change go into effect. + * You would have to go past the minimum value to set it correctly, but that's illegal. + * Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + */ $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} MINVALUE {$row['MIN_VALUE']} INCREMENT BY {$row['INCREMENT_BY']} - START WITH $maxval"; + START WITH $max_val"; } break; @@ -495,7 +497,7 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the columns used in the fixture for this table - $column_names = $xmlDataSet->getTableMetaData($row['table_name'])->getColumns(); + $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); // Skip sequences that weren't specified in the fixture if (!in_array($row['column_name'], $column_names)) From 4103c99a8676653a868014a6f58a76e8986bd5ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Mar 2012 16:15:11 +0100 Subject: [PATCH 237/244] [ticket/10679] Add new permission for changing profile field information The setting is copied from "Can use signature" PHPBB3-10679 --- phpBB/includes/ucp/ucp_profile.php | 5 +++ phpBB/install/database_update.php | 48 +++++++++++++++++++-- phpBB/install/schemas/schema_data.sql | 3 +- phpBB/language/en/acp/permissions_phpbb.php | 1 + phpBB/language/en/ucp.php | 1 + phpBB/ucp.php | 6 +++ 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 89bf20a30f..e7cea06a45 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -251,6 +251,11 @@ class ucp_profile break; case 'profile_info': + // Do not display profile information panel if not authed to do so + if (!$auth->acl_get('u_chgprofileinfo')) + { + trigger_error('NO_AUTH_PROFILEINFO'); + } include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e966756337..f0a16844e9 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2731,8 +2731,6 @@ function change_database_data(&$no_updates, $version) $config->set('display_last_subject', '1'); } - $no_updates = false; - if (!isset($config['assets_version'])) { $config->set('assets_version', '1'); @@ -2771,7 +2769,7 @@ function change_database_data(&$no_updates, $version) } // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category - + // Get the category wanted while checking, at the same time, if this has already been applied $sql = 'SELECT module_id, module_basename FROM ' . MODULES_TABLE . " @@ -2788,10 +2786,52 @@ function change_database_data(&$no_updates, $version) SET module_basename = 'ucp_pm' WHERE module_id = " . (int) $row['module_id']; - _sql($sql, $errored, $error_ary); + _sql($sql, $errored, $error_ary); } $db->sql_freeresult($result); + // Add new permission u_chgprofileinfo and duplicate settings from u_sig + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + + // Only add the new permission if it does not already exist + if (empty($auth_admin->acl_options['id']['u_chgprofileinfo'])) + { + $auth_admin->acl_add_option(array('global' => array('u_chgprofileinfo'))); + + // Now the tricky part, filling the permission + $old_id = $auth_admin->acl_options['id']['u_sig']; + $new_id = $auth_admin->acl_options['id']['u_chgprofileinfo']; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = _sql($sql, $errored, $error_ary); + + $sql_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert($table, $sql_ary); + } + } + + // Remove any old permission entries + $auth_admin->acl_clear_prefetch(); + } + + $no_updates = false; + break; } } diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index dbb5fd7481..7c1a7d40f5 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -387,6 +387,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgemail', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chggrp', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgname', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgpasswd', 1); +INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgprofileinfo', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_download', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_hideonline', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_ignoreflood', 1); @@ -548,7 +549,7 @@ INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 22, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'f_%' AND auth_option NOT IN ('f_announce', 'f_attach', 'f_bump', 'f_delete', 'f_flash', 'f_icons', 'f_ignoreflood', 'f_sticky', 'f_user_lock', 'f_votechg'); # New Member (u_) -INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 23, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group'); +INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 23, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group', 'u_chgprofileinfo'); # New Member (f_) INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 24, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove'); diff --git a/phpBB/language/en/acp/permissions_phpbb.php b/phpBB/language/en/acp/permissions_phpbb.php index b142cfd9aa..27ef714f8b 100644 --- a/phpBB/language/en/acp/permissions_phpbb.php +++ b/phpBB/language/en/acp/permissions_phpbb.php @@ -102,6 +102,7 @@ $lang = array_merge($lang, array( 'acl_u_chgemail' => array('lang' => 'Can change email address', 'cat' => 'profile'), 'acl_u_chgavatar' => array('lang' => 'Can change avatar', 'cat' => 'profile'), 'acl_u_chggrp' => array('lang' => 'Can change default usergroup', 'cat' => 'profile'), + 'acl_u_chgprofileinfo' => array('lang' => 'Can change profile field information', 'cat' => 'profile'), 'acl_u_attach' => array('lang' => 'Can attach files', 'cat' => 'post'), 'acl_u_download' => array('lang' => 'Can download files', 'cat' => 'post'), diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index b919699ea0..267ae00710 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -318,6 +318,7 @@ $lang = array_merge($lang, array( 'NO_AUTH_FORWARD_MESSAGE' => 'You are not authorised to forward private messages.', 'NO_AUTH_GROUP_MESSAGE' => 'You are not authorised to send private messages to groups.', 'NO_AUTH_PASSWORD_REMINDER' => 'You are not authorised to request a new password.', + 'NO_AUTH_PROFILEINFO' => 'You are not authorised to change your profile information.', 'NO_AUTH_READ_HOLD_MESSAGE' => 'You are not authorised to read private messages that are on hold.', 'NO_AUTH_READ_MESSAGE' => 'You are not authorised to read private messages.', 'NO_AUTH_READ_REMOVED_MESSAGE' => 'You are not able to read this message because it was removed by the author.', diff --git a/phpBB/ucp.php b/phpBB/ucp.php index a7e75f76c4..7f4cd94f6f 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -334,6 +334,12 @@ if (!$config['allow_topic_notify'] && !$config['allow_forum_notify']) $vars = array('module', 'id', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); +// Do not display profile information panel if not authed to do so +if (!$auth->acl_get('u_chgprofileinfo')) +{ + $module->set_display('profile', 'profile_info', false); +} + // Select the active module $module->set_active($id, $mode); From 2f490293e4b8d08d6c1008ef5ea324ae259d9993 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Dec 2012 16:33:12 +0100 Subject: [PATCH 238/244] [ticket/10679] Use module_auth to limit access to the module PHPBB3-10679 --- phpBB/includes/ucp/info/ucp_profile.php | 2 +- phpBB/install/database_update.php | 8 ++++++++ phpBB/ucp.php | 6 ------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/ucp/info/ucp_profile.php b/phpBB/includes/ucp/info/ucp_profile.php index 201216e9fd..3581a7f533 100644 --- a/phpBB/includes/ucp/info/ucp_profile.php +++ b/phpBB/includes/ucp/info/ucp_profile.php @@ -19,7 +19,7 @@ class ucp_profile_info 'title' => 'UCP_PROFILE', 'version' => '1.0.0', 'modes' => array( - 'profile_info' => array('title' => 'UCP_PROFILE_PROFILE_INFO', 'auth' => '', 'cat' => array('UCP_PROFILE')), + 'profile_info' => array('title' => 'UCP_PROFILE_PROFILE_INFO', 'auth' => 'acl_u_chgprofileinfo', 'cat' => array('UCP_PROFILE')), 'signature' => array('title' => 'UCP_PROFILE_SIGNATURE', 'auth' => 'acl_u_sig', 'cat' => array('UCP_PROFILE')), 'avatar' => array('title' => 'UCP_PROFILE_AVATAR', 'auth' => 'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)', 'cat' => array('UCP_PROFILE')), 'reg_details' => array('title' => 'UCP_PROFILE_REG_DETAILS', 'auth' => '', 'cat' => array('UCP_PROFILE')), diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index f0a16844e9..95fd1ca2c2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2830,6 +2830,14 @@ function change_database_data(&$no_updates, $version) $auth_admin->acl_clear_prefetch(); } + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'profile' + AND module_mode = 'profile_info'"; + _sql($sql, $errored, $error_ary); + $no_updates = false; break; diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 7f4cd94f6f..a7e75f76c4 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -334,12 +334,6 @@ if (!$config['allow_topic_notify'] && !$config['allow_forum_notify']) $vars = array('module', 'id', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); -// Do not display profile information panel if not authed to do so -if (!$auth->acl_get('u_chgprofileinfo')) -{ - $module->set_display('profile', 'profile_info', false); -} - // Select the active module $module->set_active($id, $mode); From c23d2457e9be616bfa83aebc5e743130b6c69624 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 12:50:21 +0100 Subject: [PATCH 239/244] [ticket/10679] Update module basename, we added the xcp_ prefix in 3.1 PHPBB3-10679 --- phpBB/install/database_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 95fd1ca2c2..30592b995d 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2834,7 +2834,7 @@ function change_database_data(&$no_updates, $version) $sql = 'UPDATE ' . MODULES_TABLE . " SET module_auth = 'acl_u_chgprofileinfo' WHERE module_class = 'ucp' - AND module_basename = 'profile' + AND module_basename = 'ucp_profile' AND module_mode = 'profile_info'"; _sql($sql, $errored, $error_ary); From 5b368dd53a2da6ab481bc608176f442dc067c4a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 7 Dec 2012 15:32:06 -0500 Subject: [PATCH 240/244] [ticket/11255] Fix dbal write sequence test to run standalone. PHPBB3-11255 --- tests/dbal/write_sequence_test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index 8975cfbfb1..f382a971a5 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -33,6 +33,10 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case { $db = $this->new_dbal(); + // dbal uses cache + global $cache; + $cache = new phpbb_mock_cache(); + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( 'username' => $username, 'username_clean' => $username, From 5af3d14af3c35e99c0eba75c43a411ead6191c79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 7 Dec 2012 15:32:26 -0500 Subject: [PATCH 241/244] [ticket/11255] Change search tests to use mock cache. PHPBB3-11255 --- tests/search/mysql_test.php | 2 +- tests/search/native_test.php | 2 +- tests/search/postgres_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 3ba3915714..3ad15bd806 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); // set config values $config['fulltext_mysql_min_word_len'] = 4; diff --git a/tests/search/native_test.php b/tests/search/native_test.php index eeee3a44f3..4a2c210013 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); $this->db = $this->new_dbal(); $error = null; diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 9c77e0c09e..923af6f854 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); // set config values $config['fulltext_postgres_min_word_len'] = 4; From cf956e8f53cadbbe647651b9fd87f9feba23f7e2 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 7 Dec 2012 23:14:07 +0100 Subject: [PATCH 242/244] [ticket/11256] Remove unused service with non-existent class PHPBB3-11256 --- phpBB/config/services.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 37e6c0b5df..fb1df6f508 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -59,12 +59,6 @@ services: - @service_container - @ext.finder - controller.route_collection: - class: phpbb_controller_route_collection - arguments: - - @ext.finder - - @controller.provider - controller.provider: class: phpbb_controller_provider From 2973539760beebc1bb60dc91382c2b628d4276c6 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 7 Dec 2012 23:18:38 +0100 Subject: [PATCH 243/244] [ticket/11256] Remove unused controller.provider service PHPBB3-11256 --- phpBB/config/services.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index fb1df6f508..242fe7f1d2 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -59,9 +59,6 @@ services: - @service_container - @ext.finder - controller.provider: - class: phpbb_controller_provider - cron.task_collection: class: phpbb_di_service_collection arguments: From 8a28271dd500b3623e1402339252504468e567f6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 7 Dec 2012 21:23:20 -0600 Subject: [PATCH 244/244] [ticket/11257] Do not require set_name() method to exist To use Service Collection PHPBB3-11257 --- phpBB/config/cron_tasks.yml | 16 ++++++++++++++++ phpBB/includes/di/service_collection.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml index 74f57e449d..d1954b1877 100644 --- a/phpBB/config/cron_tasks.yml +++ b/phpBB/config/cron_tasks.yml @@ -6,6 +6,8 @@ services: - %core.php_ext% - @config - @dbal.conn + calls: + - [set_name, [cron.task.core.prune_all_forums]] tags: - { name: cron.task } @@ -16,6 +18,8 @@ services: - %core.php_ext% - @config - @dbal.conn + calls: + - [set_name, [cron.task.core.prune_forum]] tags: - { name: cron.task } @@ -25,6 +29,8 @@ services: - %core.root_path% - %core.php_ext% - @config + calls: + - [set_name, [cron.task.core.queue]] tags: - { name: cron.task } @@ -33,6 +39,8 @@ services: arguments: - @config - @cache.driver + calls: + - [set_name, [cron.task.core.tidy_cache]] tags: - { name: cron.task } @@ -42,6 +50,8 @@ services: - %core.root_path% - %core.php_ext% - @config + calls: + - [set_name, [cron.task.core.tidy_database]] tags: - { name: cron.task } @@ -54,6 +64,8 @@ services: - @config - @dbal.conn - @user + calls: + - [set_name, [cron.task.core.tidy_search]] tags: - { name: cron.task } @@ -62,6 +74,8 @@ services: arguments: - @config - @user + calls: + - [set_name, [cron.task.core.tidy_sessions]] tags: - { name: cron.task } @@ -71,5 +85,7 @@ services: - %core.root_path% - %core.php_ext% - @config + calls: + - [set_name, [cron.task.core.tidy_warnings]] tags: - { name: cron.task } diff --git a/phpBB/includes/di/service_collection.php b/phpBB/includes/di/service_collection.php index 60323c8dba..880cb46d4d 100644 --- a/phpBB/includes/di/service_collection.php +++ b/phpBB/includes/di/service_collection.php @@ -43,7 +43,7 @@ class phpbb_di_service_collection extends ArrayObject public function add($name) { $task = $this->container->get($name); - $task->set_name($name); + $this->offsetSet($name, $task); } }
{L_SELECT_TOPICS_FROM}{L_MODERATE_FORUM}{L_JUMP_TO}{L_COLON} {HIDDEN_FIELDS_FOR_JUMPBOX}{L_SELECT_TOPICS_FROM}{L_MODERATE_FORUM}{L_JUMP_TO}{L_COLON}  From 3e907265d5782c535d43e503c32390cfde8dc4a8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 29 Nov 2012 14:41:48 -0500 Subject: [PATCH 156/244] [ticket/11095] Docs and tests for phpbb_build_hidden_fields_for_query_params. PHPBB3-11095 --- phpBB/includes/functions.php | 14 ++++ ...ld_hidden_fields_for_query_params_test.php | 71 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/functions/build_hidden_fields_for_query_params_test.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ee5a1afd30..9c92adb0ec 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4940,6 +4940,20 @@ function phpbb_quoteattr($data, $entities = null) return $data; } +/** +* Converts query string (GET) parameters in request into hidden fields. +* +* Useful for forwarding GET parameters when submitting forms with GET method. +* +* It is possible to omit some of the GET parameters, which is useful if +* they are specified in the form being submitted. +* +* sid is always omitted. +* +* @param phpbb_request $request Request object +* @param array $exclude A list of variable names that should not be forwarded +* @return string HTML with hidden fields +*/ function phpbb_build_hidden_fields_for_query_params($request, $exclude = null) { $names = $request->variable_names(phpbb_request_interface::GET); diff --git a/tests/functions/build_hidden_fields_for_query_params_test.php b/tests/functions/build_hidden_fields_for_query_params_test.php new file mode 100644 index 0000000000..ef2f5744d3 --- /dev/null +++ b/tests/functions/build_hidden_fields_for_query_params_test.php @@ -0,0 +1,71 @@ + 'bar'), + array(), + array(), + "", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array(), + array(), + "", + ), + array( + array('a' => 'quote"', 'b' => ''), + array(), + array(), + "", + ), + array( + array('a' => "quotes'\""), + array(), + array(), + "", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array('a' => 'c'), + array(), + "", + ), + // strict equality check + array( + array('foo' => 'bar', 'a' => '0'), + array('a' => ''), + array(), + "", + ), + ); + } + + /** + * @dataProvider build_hidden_fields_for_query_params_test_data + */ + public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected) + { + $request = new phpbb_mock_request($get, $post); + $result = phpbb_build_hidden_fields_for_query_params($request, $exclude); + + $this->assertEquals($expected, $result); + } +} From 11ca272692ed1b46d4ff208705cb30636c98704f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 29 Nov 2012 14:42:56 -0500 Subject: [PATCH 157/244] [ticket/11095] Restore brace on previous line. PHPBB3-11095 --- phpBB/includes/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9c92adb0ec..8df40b26f6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5558,8 +5558,7 @@ function phpbb_to_numeric($input) function phpbb_create_symfony_request(phpbb_request $request) { // This function is meant to sanitize the global input arrays - $sanitizer = function(&$value, $key) - { + $sanitizer = function(&$value, $key) { $type_cast_helper = new phpbb_request_type_cast_helper(); $type_cast_helper->set_var($value, $value, gettype($value), true); }; From 65253a3023a78b1068be63b91b77618e3fb2d5fd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 29 Nov 2012 15:35:21 -0500 Subject: [PATCH 158/244] [ticket/11227] @return void -> @return null in develop-olympus. PHPBB3-11227 --- phpBB/develop/generate_utf_casefold.php | 2 +- phpBB/develop/generate_utf_confusables.php | 2 +- phpBB/develop/generate_utf_tables.php | 2 +- phpBB/develop/utf_normalizer_test.php | 2 +- phpBB/docs/auth_api.html | 2 +- phpBB/includes/acm/acm_apc.php | 2 +- phpBB/includes/acm/acm_eaccelerator.php | 4 ++-- phpBB/includes/acm/acm_memcache.php | 4 ++-- phpBB/includes/acm/acm_redis.php | 4 ++-- phpBB/includes/acm/acm_wincache.php | 2 +- phpBB/includes/acm/acm_xcache.php | 2 +- phpBB/includes/functions.php | 4 ++-- phpBB/includes/functions_admin.php | 2 +- phpBB/includes/questionnaire/questionnaire.php | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phpBB/develop/generate_utf_casefold.php b/phpBB/develop/generate_utf_casefold.php index 73951cb4dc..08f67c3eb6 100644 --- a/phpBB/develop/generate_utf_casefold.php +++ b/phpBB/develop/generate_utf_casefold.php @@ -111,7 +111,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_confusables.php b/phpBB/develop/generate_utf_confusables.php index d2ffbcfc65..fd0439a4bb 100644 --- a/phpBB/develop/generate_utf_confusables.php +++ b/phpBB/develop/generate_utf_confusables.php @@ -199,7 +199,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_tables.php b/phpBB/develop/generate_utf_tables.php index 6fe5d68ffd..6372270b78 100644 --- a/phpBB/develop/generate_utf_tables.php +++ b/phpBB/develop/generate_utf_tables.php @@ -481,7 +481,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 71f24a716b..b8709888fe 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -222,7 +222,7 @@ die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/docs/auth_api.html b/phpBB/docs/auth_api.html index 29469c21ac..a319460360 100644 --- a/phpBB/docs/auth_api.html +++ b/phpBB/docs/auth_api.html @@ -200,7 +200,7 @@ $user_id = 2; $auth->acl_clear_prefetch($user_id); -

This method returns void.

+

This method returns null.

2.viii. acl_get_list

diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/acm/acm_apc.php index 1a487f94ad..205353d3a5 100644 --- a/phpBB/includes/acm/acm_apc.php +++ b/phpBB/includes/acm/acm_apc.php @@ -33,7 +33,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_eaccelerator.php b/phpBB/includes/acm/acm_eaccelerator.php index 645067c199..ecec3ac9a5 100644 --- a/phpBB/includes/acm/acm_eaccelerator.php +++ b/phpBB/includes/acm/acm_eaccelerator.php @@ -37,7 +37,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { @@ -54,7 +54,7 @@ class acm extends acm_memory /** * Perform cache garbage collection * - * @return void + * @return null */ function tidy() { diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index e54fa36c38..70bc219952 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -71,7 +71,7 @@ class acm extends acm_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -83,7 +83,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index 41533eaacb..dc11ca7768 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -80,7 +80,7 @@ class acm extends acm_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -92,7 +92,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_wincache.php b/phpBB/includes/acm/acm_wincache.php index 0501ab74c5..7faba4f5b6 100644 --- a/phpBB/includes/acm/acm_wincache.php +++ b/phpBB/includes/acm/acm_wincache.php @@ -32,7 +32,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index d0a614660c..e3d83f8bfa 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -48,7 +48,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6e661228b7..571c863839 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2745,7 +2745,7 @@ function meta_refresh($time, $url, $disable_cd_check = false) * * @param int $code HTTP status code * @param string $message Message for the status code -* @return void +* @return null */ function send_status_line($code, $message) { @@ -4332,7 +4332,7 @@ function phpbb_optionset($bit, $set, $data) * * @param array $param Parameter array, see $param_defaults array. * -* @return void +* @return null */ function phpbb_http_login($param) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 7352b3d1f3..190185cfcf 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3343,7 +3343,7 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $ * @param int $flag The binary flag which is OR-ed with the current column value * @param string $sql_more This string is attached to the sql query generated to update the table. * - * @return void + * @return null */ function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '') { diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index cbd7638809..3268775cb6 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -71,7 +71,7 @@ class phpbb_questionnaire_data_collector /** * Collect info into the data property. * - * @return void + * @return null */ function collect() { From ee16ed7b76315f629adc1f234d6cf3ddd9552a97 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 11:53:19 -0500 Subject: [PATCH 159/244] [ticket/10875] Spelling fix. PHPBB3-10875 --- phpBB/includes/cache/driver/interface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 6adc95a86a..26dfd497aa 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -63,7 +63,7 @@ interface phpbb_cache_driver_interface public function destroy($var_name, $table = ''); /** - * Check if a given cache entry exist + * Check if a given cache entry exists */ public function _exists($var_name); @@ -94,7 +94,7 @@ interface phpbb_cache_driver_interface public function sql_save($query, $query_result, $ttl); /** - * Ceck if a given sql query exist in cache + * Check if a given sql query exists in cache * * @param int $query_id * @return bool From 3eb15ab59e202f6d995f40da7cbee0056e73f5d1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:04:05 -0500 Subject: [PATCH 160/244] [ticket/10875] More documentation. PHPBB3-10875 --- phpBB/includes/cache/driver/interface.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 26dfd497aa..d403bbcd71 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -68,7 +68,7 @@ interface phpbb_cache_driver_interface public function _exists($var_name); /** - * Load cached sql query + * Load result of an SQL query from cache. * * @param string $query SQL query * @@ -79,7 +79,11 @@ interface phpbb_cache_driver_interface public function sql_load($query); /** - * Save sql query + * Save result of an SQL query in cache. + * + * In persistent cache stores, this function stores the query + * result to persistent storage. In other words, there is no need + * to call save() afterwards. * * @param string $query SQL query, should be used for generating storage key * @param mixed $query_result The result from dbal::sql_query, to be passed to @@ -94,7 +98,7 @@ interface phpbb_cache_driver_interface public function sql_save($query, $query_result, $ttl); /** - * Check if a given sql query exists in cache + * Check if result for a given SQL query exists in cache. * * @param int $query_id * @return bool From 1ebc6eb68bedc4d6708cb6f23959d129030cf31e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:11:52 -0500 Subject: [PATCH 161/244] [ticket/10875] Must return query result on failure. PHPBB3-10875 --- phpBB/includes/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index bc08494c0c..e4da5767cf 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -294,7 +294,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) { // Bail out if the match fails. - return; + return $query_result; } $tables = array_map('trim', explode(',', $regs[1])); From 7bba09811c65acfd98ebf1e6626f59de7a16cbb3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:18:33 -0500 Subject: [PATCH 162/244] [ticket/10875] Revise sql cache test. Delete data from database before retrieving it from cache, ensuring results come from cache. PHPBB3-10875 --- tests/cache/cache_test.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c5f5fac88c..40eef91d53 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -89,20 +89,26 @@ class phpbb_cache_test extends phpbb_database_test_case WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); + $sql = "DELETE FROM phpbb_config"; + $result = $db->sql_query($sql); + $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); - $this->assertEquals($first_result, $db->sql_fetchrow($result)); + $this->assertEquals($expected, $db->sql_fetchrow($result)); $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'bar'"; - $result = $db->sql_query($sql, 300); + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); - $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); $db->sql_close(); } From 0c06ac466f61cdab1c647cec23ea66ef70b2ad7e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:28:13 -0500 Subject: [PATCH 163/244] [ticket/10875] Test for null cache driver and sql cache. PHPBB3-10875 --- tests/cache/cache_test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 40eef91d53..c904aa6c41 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -112,4 +112,33 @@ class phpbb_cache_test extends phpbb_database_test_case $db->sql_close(); } + + public function test_null_cache_sql() + { + $driver = new phpbb_cache_driver_null($this->cache_dir); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = "DELETE FROM phpbb_config"; + $result = $db->sql_query($sql); + + // As null cache driver does not actually cache, + // this should return no results + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertSame(false, $db->sql_fetchrow($result)); + + $db->sql_close(); + } } From e4d2ad6b2788d9c3c030382f5ad2f02b6b7f75db Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 1 Dec 2012 00:36:34 +0100 Subject: [PATCH 164/244] [ticket/10875] tests/cache/cache_test.php: Use single quotes where possible. PHPBB3-10875 --- tests/cache/cache_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c904aa6c41..285af5cd0c 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -94,7 +94,7 @@ class phpbb_cache_test extends phpbb_database_test_case $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); - $sql = "DELETE FROM phpbb_config"; + $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); $sql = "SELECT * FROM phpbb_config @@ -128,7 +128,7 @@ class phpbb_cache_test extends phpbb_database_test_case $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); $this->assertEquals($expected, $first_result); - $sql = "DELETE FROM phpbb_config"; + $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); // As null cache driver does not actually cache, From ec4343c7447911c7e822a03c0f57fc2bb1c4ab3d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 23:03:06 -0500 Subject: [PATCH 165/244] [ticket/11227] @return void -> @return null, per coding guidelines. PHPBB3-11227 --- phpBB/includes/config/config.php | 2 +- phpBB/includes/config/db.php | 2 +- phpBB/includes/cron/manager.php | 2 +- phpBB/includes/cron/task/core/prune_all_forums.php | 2 +- phpBB/includes/cron/task/core/prune_forum.php | 4 ++-- phpBB/includes/cron/task/core/queue.php | 2 +- phpBB/includes/cron/task/core/tidy_cache.php | 2 +- phpBB/includes/cron/task/core/tidy_database.php | 2 +- phpBB/includes/cron/task/core/tidy_search.php | 2 +- phpBB/includes/cron/task/core/tidy_sessions.php | 2 +- phpBB/includes/cron/task/core/tidy_warnings.php | 2 +- phpBB/includes/cron/task/parametrized.php | 2 +- phpBB/includes/cron/task/task.php | 2 +- phpBB/includes/functions_download.php | 2 +- phpBB/includes/group_positions.php | 10 +++++----- phpBB/includes/lock/db.php | 2 +- phpBB/includes/style/resource_locator.php | 4 ++-- phpBB/includes/template/compile.php | 2 +- 18 files changed, 24 insertions(+), 24 deletions(-) diff --git a/phpBB/includes/config/config.php b/phpBB/includes/config/config.php index 12a4a418b2..4b533dd55c 100644 --- a/phpBB/includes/config/config.php +++ b/phpBB/includes/config/config.php @@ -109,7 +109,7 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/config/db.php b/phpBB/includes/config/db.php index 993a764a7f..45f9f1cb21 100644 --- a/phpBB/includes/config/db.php +++ b/phpBB/includes/config/db.php @@ -96,7 +96,7 @@ class phpbb_config_db extends phpbb_config * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index ccaa4f3764..84c9650830 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -54,7 +54,7 @@ class phpbb_cron_manager * * @param array|Traversable $tasks Array of instances of phpbb_cron_task * - * @return void + * @return null */ public function load_tasks($tasks) { diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 252e16e57d..ee0b5f7626 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -50,7 +50,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 41d60af921..fa7a761d88 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -70,7 +70,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p /** * Runs this cron task. * - * @return void + * @return null */ public function run() { @@ -138,7 +138,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index c765660906..732f9c6bea 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 6017eea561..16a45dae7c 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 1d256f964f..b882e7b500 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 2e5f3d79d5..fdbe31346e 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -54,7 +54,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index 13531aa30b..95f55235c9 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index 8dd0674fe5..2a7798e56e 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -45,7 +45,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/parametrized.php b/phpBB/includes/cron/task/parametrized.php index 0714b2e701..5f0e46eafc 100644 --- a/phpBB/includes/cron/task/parametrized.php +++ b/phpBB/includes/cron/task/parametrized.php @@ -46,7 +46,7 @@ interface phpbb_cron_task_parametrized extends phpbb_cron_task * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request); } diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 7b08fed413..2d585df96d 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -31,7 +31,7 @@ interface phpbb_cron_task /** * Runs this cron task. * - * @return void + * @return null */ public function run(); diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index b6371dbecc..fc6f1cc762 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -433,7 +433,7 @@ function set_modified_headers($stamp, $browser) * * @param bool $exit Whether to die or not. * -* @return void +* @return null */ function file_gc($exit = true) { diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index 74de3516cb..60352ed97d 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -104,7 +104,7 @@ class phpbb_group_positions * Addes a group by group_id * * @param int $group_id group_id of the group to be added - * @return void + * @return null */ public function add_group($group_id) { @@ -128,7 +128,7 @@ class phpbb_group_positions * * @param int $group_id group_id of the group to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return void + * @return null */ public function delete_group($group_id, $skip_group = false) { @@ -159,7 +159,7 @@ class phpbb_group_positions * Moves a group up by group_id * * @param int $group_id group_id of the group to be moved - * @return void + * @return null */ public function move_up($group_id) { @@ -170,7 +170,7 @@ class phpbb_group_positions * Moves a group down by group_id * * @param int $group_id group_id of the group to be moved - * @return void + * @return null */ public function move_down($group_id) { @@ -184,7 +184,7 @@ class phpbb_group_positions * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return void + * @return null */ public function move($group_id, $delta) { diff --git a/phpBB/includes/lock/db.php b/phpBB/includes/lock/db.php index fa559d6887..6e94dd5a85 100644 --- a/phpBB/includes/lock/db.php +++ b/phpBB/includes/lock/db.php @@ -125,7 +125,7 @@ class phpbb_lock_db * Note: Attempting to release a lock that is already released, * that is, calling release() multiple times, is harmless. * - * @return void + * @return null */ public function release() { diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 04beddb434..4cf767c062 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -110,7 +110,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * Typically it is one directory level deep, e.g. "template/". * * @param string $template_path Relative path to templates directory within style directories - * @return void + * @return null */ public function set_template_path($template_path) { @@ -121,7 +121,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * Sets the location of templates directory within style directories * to the default, which is "template/". * - * @return void + * @return null */ public function set_default_template_path() { diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 82b301c1a2..d0b3d0f115 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -118,7 +118,7 @@ class phpbb_template_compile * * @param resource $source_stream Source stream * @param resource $dest_stream Destination stream - * @return void + * @return null */ private function compile_stream_to_stream($source_stream, $dest_stream) { From e5e8087bebdae8c4da2e59e9afd984d6a2008caf Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 23:03:48 -0500 Subject: [PATCH 166/244] [ticket/11227] @return void -> @return null in code sniffer. PHPBB3-11227 --- .../phpbb/Sniffs/Commenting/FileCommentSniff.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index ba2b40ecba..68e9e6bb86 100644 --- a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -35,7 +35,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * - * @return void + * @return null */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { @@ -120,7 +120,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -143,7 +143,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -166,7 +166,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -189,7 +189,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { From c852044d6eecc0a652800b1661491c0f9c545054 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 00:48:21 -0500 Subject: [PATCH 167/244] [ticket/9983] Add redis cache driver tests. In order to not overwrite data in default redis store, at least one of redis host or post must be explicitly specified. Redis cache driver constructor has been modified to accept host and port as parameters. This was not added to public API as there are more parameters being passed via global constants. PHPBB3-9983 --- phpBB/includes/cache/driver/redis.php | 27 +++++++- tests/RUNNING_TESTS.txt | 15 ++++ tests/cache/cache_test.php | 68 ++++++++++++++++++- .../phpbb_test_case_helpers.php | 19 ++++++ 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index d256b5600e..ae6f9e04f2 100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php @@ -39,13 +39,38 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory var $redis; + /** + * Creates a redis cache driver. + * + * The following global constants affect operation: + * + * PHPBB_ACM_REDIS_HOST + * PHPBB_ACM_REDIS_PORT + * PHPBB_ACM_REDIS_PASSWORD + * PHPBB_ACM_REDIS_DB + * + * There are no publicly documented constructor parameters. + */ function __construct() { // Call the parent constructor parent::__construct(); $this->redis = new Redis(); - $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + + $args = func_get_args(); + if (!empty($args)) + { + $ok = call_user_func_array(array($this->redis, 'connect'), $args); + } + else + { + $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + } + if (!$ok) + { + trigger_error('Could not connect to redis server'); + } if (defined('PHPBB_ACM_REDIS_PASSWORD')) { diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 7c2a7c3fce..11617964cb 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -72,6 +72,21 @@ to connect to that database in phpBB. Additionally, you will need to be running the DbUnit fork from https://github.com/phpbb/dbunit/tree/phpbb. +Redis +----- + +In order to run tests for the Redis cache driver, at least one of Redis host +or port must be specified in test configuration. This can be done via +test_config.php as follows: + + cache_dir); @@ -87,12 +87,76 @@ class phpbb_cache_test extends phpbb_database_test_case $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; + + $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; + $this->assertFileNotExists($cache_path); + $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); $this->assertEquals($expected, $first_result); - $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); + $this->assertFileExists($cache_path); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } + + public function test_cache_sql_redis() + { + if (!extension_loaded('redis')) + { + $this->markTestSkipped('redis extension is not loaded'); + } + + $config = phpbb_test_case_helpers::get_test_config(); + if (isset($config['redis_host']) || isset($config['redis_port'])) + { + $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; + $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; + } + else + { + $this->markTestSkipped('Test redis host/port is not specified'); + } + $driver = new phpbb_cache_driver_redis($host, $port); + $driver->purge(); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $redis = new Redis(); + $ok = $redis->connect($host, $port); + $this->assertTrue($ok); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse($redis->exists($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue($redis->exists($key)); $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index d10645a732..b56a699d1c 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -91,6 +91,15 @@ class phpbb_test_case_helpers { $config['phpbb_functional_url'] = $phpbb_functional_url; } + + if (isset($redis_host)) + { + $config['redis_host'] = $redis_host; + } + if (isset($redis_port)) + { + $config['redis_port'] = $redis_port; + } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) @@ -113,6 +122,16 @@ class phpbb_test_case_helpers )); } + if (isset($_SERVER['PHPBB_TEST_REDIS_HOST'])) + { + $config['redis_host'] = $_SERVER['PHPBB_TEST_REDIS_HOST']; + } + + if (isset($_SERVER['PHPBB_TEST_REDIS_PORT'])) + { + $config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT']; + } + return $config; } From a0d5c52eb6e8ef3a6bb44cff60b364d3a3a5bf3e Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 1 Dec 2012 09:44:51 +0000 Subject: [PATCH 168/244] [ticket/10601] New approach in the update algorithm - New approach in the database update algorithm PHPBB3-10601 --- phpBB/install/database_update.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index eed484dfae..f3136690a2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2750,28 +2750,25 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_text', ''); } - // ticket/10601: Make inbox default. Add basename to ucp's pm category - // Check if this was already applied - $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category + + // Get the category wanted while checking, at the same time, if this has already been applied + $sql = 'SELECT module_id, module_basename FROM ' . MODULES_TABLE . " - WHERE module_basename = 'ucp_pm' + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM' ORDER BY module_id"; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) { - // Checking if this is not a category - if ($row['left_id'] === $row['right_id'] - 1) - { - // This update is still not applied. Applying it + // This update is still not applied. Applying it - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_basename = 'ucp_pm' - WHERE module_id = " . (int) $row['parent_id']; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; - _sql($sql, $errored, $error_ary); - - } + _sql($sql, $errored, $error_ary); } $db->sql_freeresult($result); From 314462d8352a6b5ea1fd27ce1bb21cb0a8fb1310 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 22:36:01 +0100 Subject: [PATCH 169/244] [ticket/10184] Disable receiving pms for bots by default PHPBB3-10184 --- phpBB/install/database_update.php | 6 ++++++ phpBB/install/install_install.php | 1 + 2 files changed, 7 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 399ad3429a..8e23434b5b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2171,6 +2171,12 @@ function change_database_data(&$no_updates, $version) } } + // Disable receiving pms for bots + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE user_type = ' . USER_IGNORE; + $db->sql_query($sql); + $no_updates = false; break; } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 67ebb8b1c5..0575b58d92 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1859,6 +1859,7 @@ class install_install extends module 'user_timezone' => 0, 'user_dateformat' => $lang['default_dateformat'], 'user_allow_massemail' => 0, + 'user_allow_pm' => 0, ); $user_id = user_add($user_row); From ad2d560f3f6ab0232728392b2c1c946f2b07902d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Nov 2012 14:32:31 +0100 Subject: [PATCH 170/244] [ticket/10184] Query bots table to get the user_ids of the bots PHPBB3-10184 --- phpBB/install/database_update.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8e23434b5b..983b1b46c4 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2172,10 +2172,24 @@ function change_database_data(&$no_updates, $version) } // Disable receiving pms for bots - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_allow_pm = 0 - WHERE user_type = ' . USER_IGNORE; - $db->sql_query($sql); + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $db->sql_in_set('user_id', $bot_user_ids); + _sql($sql, $errored, $error_ary); + } $no_updates = false; break; From 1ce06711811561d2e3fa3c6ba2aeac4ebffa6581 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 1 Dec 2012 10:05:20 +0000 Subject: [PATCH 171/244] [ticket/10601] The ORDER BY is only taking space there PHPBB3-10601 --- phpBB/install/database_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index f3136690a2..ae6e3bd9cf 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2757,7 +2757,7 @@ function change_database_data(&$no_updates, $version) FROM ' . MODULES_TABLE . " WHERE module_basename <> 'ucp_pm' AND module_langname='UCP_PM' - ORDER BY module_id"; + "; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) From 1e3dff83b3e56353fd97a6581989c478e52ed892 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 15:03:44 -0500 Subject: [PATCH 172/244] [ticket/9983] Split cache test into per-driver files. PHPBB3-9983 --- tests/cache/cache_test.php | 208 ------------------------------ tests/cache/file_driver_test.php | 117 +++++++++++++++++ tests/cache/null_driver_test.php | 45 +++++++ tests/cache/redis_driver_test.php | 89 +++++++++++++ 4 files changed, 251 insertions(+), 208 deletions(-) delete mode 100644 tests/cache/cache_test.php create mode 100644 tests/cache/file_driver_test.php create mode 100644 tests/cache/null_driver_test.php create mode 100644 tests/cache/redis_driver_test.php diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php deleted file mode 100644 index ad60a9077e..0000000000 --- a/tests/cache/cache_test.php +++ /dev/null @@ -1,208 +0,0 @@ -cache_dir = dirname(__FILE__) . '/../tmp/cache/'; - } - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); - } - - protected function setUp() - { - parent::setUp(); - - if (file_exists($this->cache_dir)) - { - // cache directory possibly left after aborted - // or failed run earlier - $this->remove_cache_dir(); - } - $this->create_cache_dir(); - } - - protected function tearDown() - { - if (file_exists($this->cache_dir)) - { - $this->remove_cache_dir(); - } - - parent::tearDown(); - } - - private function create_cache_dir() - { - $this->get_test_case_helpers()->makedirs($this->cache_dir); - } - - private function remove_cache_dir() - { - $iterator = new DirectoryIterator($this->cache_dir); - foreach ($iterator as $file) - { - if ($file != '.' && $file != '..') - { - unlink($this->cache_dir . '/' . $file); - } - } - rmdir($this->cache_dir); - } - - public function test_cache_driver_file() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - $driver->put('test_key', 'test_value'); - $driver->save(); - - $this->assertEquals( - 'test_value', - $driver->get('test_key'), - 'File ACM put and get' - ); - } - - public function test_cache_sql_file() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; - $this->assertFileNotExists($cache_path); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertFileExists($cache_path); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } - - public function test_cache_sql_redis() - { - if (!extension_loaded('redis')) - { - $this->markTestSkipped('redis extension is not loaded'); - } - - $config = phpbb_test_case_helpers::get_test_config(); - if (isset($config['redis_host']) || isset($config['redis_port'])) - { - $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; - $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; - } - else - { - $this->markTestSkipped('Test redis host/port is not specified'); - } - $driver = new phpbb_cache_driver_redis($host, $port); - $driver->purge(); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $redis = new Redis(); - $ok = $redis->connect($host, $port); - $this->assertTrue($ok); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse($redis->exists($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue($redis->exists($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } - - public function test_null_cache_sql() - { - $driver = new phpbb_cache_driver_null($this->cache_dir); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - // As null cache driver does not actually cache, - // this should return no results - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertSame(false, $db->sql_fetchrow($result)); - - $db->sql_close(); - } -} diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php new file mode 100644 index 0000000000..436bd2f6bc --- /dev/null +++ b/tests/cache/file_driver_test.php @@ -0,0 +1,117 @@ +cache_dir = dirname(__FILE__) . '/../tmp/cache/'; + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + + $this->driver = new phpbb_cache_driver_file($this->cache_dir); + } + + protected function tearDown() + { + if (file_exists($this->cache_dir)) + { + $this->remove_cache_dir(); + } + + parent::tearDown(); + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } + + public function test_cache_driver_file() + { + $this->driver->put('test_key', 'test_value'); + $this->driver->save(); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + } + + public function test_cache_sql_file() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; + $this->assertFileNotExists($cache_path); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertFileExists($cache_path); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php new file mode 100644 index 0000000000..7bf72931a0 --- /dev/null +++ b/tests/cache/null_driver_test.php @@ -0,0 +1,45 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function test_null_cache_sql() + { + $driver = new phpbb_cache_driver_null; + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + // As null cache driver does not actually cache, + // this should return no results + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertSame(false, $db->sql_fetchrow($result)); + + $db->sql_close(); + } +} diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php new file mode 100644 index 0000000000..be8b518dca --- /dev/null +++ b/tests/cache/redis_driver_test.php @@ -0,0 +1,89 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('redis')) + { + self::markTestSkipped('redis extension is not loaded'); + } + + $config = phpbb_test_case_helpers::get_test_config(); + if (isset($config['redis_host']) || isset($config['redis_port'])) + { + $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; + $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; + self::$config = array('host' => $host, 'port' => $port); + } + else + { + $this->markTestSkipped('Test redis host/port is not specified'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); + $this->driver->purge(); + } + + public function test_cache_sql_redis() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $redis = new Redis(); + $ok = $redis->connect(self::$config['host'], self::$config['port']); + $this->assertTrue($ok); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse($redis->exists($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue($redis->exists($key)); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} From 829b75e5c8d7b053f3988db89f6f9505102c92b3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 15:06:32 -0500 Subject: [PATCH 173/244] [ticket/9983] Create driver in setup in null driver test. PHPBB3-9983 --- tests/cache/null_driver_test.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 7bf72931a0..45e53edaa1 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -9,18 +9,25 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case { + protected $driver; + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_null; + } + public function test_null_cache_sql() { - $driver = new phpbb_cache_driver_null; - global $db, $cache; $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); + $cache = new phpbb_cache_service($this->driver); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; From c3d1408c52dabcafa314fcc13d19f0c537d3a5df Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:49:27 -0500 Subject: [PATCH 174/244] [ticket/9983] get/put cache test moved to a base class. PHPBB3-9983 --- tests/cache/common_test_case.php | 24 ++++++++++++++++++++++++ tests/cache/file_driver_test.php | 16 +++------------- tests/cache/null_driver_test.php | 10 ++++++++++ tests/cache/redis_driver_test.php | 4 +++- 4 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 tests/cache/common_test_case.php diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php new file mode 100644 index 0000000000..059ce25133 --- /dev/null +++ b/tests/cache/common_test_case.php @@ -0,0 +1,24 @@ +assertSame(false, $this->driver->get('test_key')); + + $this->driver->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + } +} diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 436bd2f6bc..67408cc6d9 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_cache_file_driver_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case { private $cache_dir; protected $driver; @@ -65,18 +67,6 @@ class phpbb_cache_file_driver_test extends phpbb_database_test_case rmdir($this->cache_dir); } - public function test_cache_driver_file() - { - $this->driver->put('test_key', 'test_value'); - $this->driver->save(); - - $this->assertEquals( - 'test_value', - $this->driver->get('test_key'), - 'File ACM put and get' - ); - } - public function test_cache_sql_file() { global $db, $cache; diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 45e53edaa1..efa56762bf 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -23,6 +23,16 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->driver = new phpbb_cache_driver_null; } + public function test_get_put() + { + $this->assertSame(false, $this->driver->get('key')); + + $this->driver->put('key', 'value'); + + // null driver does not cache + $this->assertSame(false, $this->driver->get('key')); + } + public function test_null_cache_sql() { global $db, $cache; diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index be8b518dca..bf8e49eb65 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_cache_redis_driver_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case { protected static $config; protected $driver; From 90bd7858fdf418c45bac1b30a4dc634cd23f5247 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:52:04 -0500 Subject: [PATCH 175/244] [ticket/9983] Rename test methods. PHPBB3-9983 --- tests/cache/file_driver_test.php | 2 +- tests/cache/null_driver_test.php | 2 +- tests/cache/redis_driver_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 67408cc6d9..2353940277 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -67,7 +67,7 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case rmdir($this->cache_dir); } - public function test_cache_sql_file() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index efa56762bf..a9b40c5f40 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -33,7 +33,7 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('key')); } - public function test_null_cache_sql() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index bf8e49eb65..cd24e33baf 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -47,7 +47,7 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case $this->driver->purge(); } - public function test_cache_sql_redis() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); From d9e636fab0b1c2de36e38e7bdd3498711108a0e6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:53:13 -0500 Subject: [PATCH 176/244] [ticket/9983] Add a purge test. PHPBB3-9983 --- tests/cache/common_test_case.php | 15 +++++++++++++++ tests/cache/null_driver_test.php | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 059ce25133..c44dbf5250 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -21,4 +21,19 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case 'File ACM put and get' ); } + + public function test_purge() + { + $this->driver->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + + $this->driver->purge(); + + $this->assertSame(false, $this->driver->get('test_key')); + } } diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index a9b40c5f40..1e8b254294 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -33,6 +33,12 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('key')); } + public function test_purge() + { + // does nothing + $this->driver->purge(); + } + public function test_cache_sql() { global $db, $cache; From 8595b1f56018d0bfac0b83ac1511175c88a8b9cb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:57:09 -0500 Subject: [PATCH 177/244] [ticket/9983] Exercise exists also. PHPBB3-9983 --- tests/cache/common_test_case.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index c44dbf5250..5c387d98a1 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -9,12 +9,14 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case { - public function test_get_put() + public function test_get_put_exists() { + $this->assertFalse($this->driver->_exists('test_key')); $this->assertSame(false, $this->driver->get('test_key')); $this->driver->put('test_key', 'test_value'); + $this->assertTrue($this->driver->_exists('test_key')); $this->assertEquals( 'test_value', $this->driver->get('test_key'), From dd36b128e80112ba47ae51dca47702209e8aac18 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:59:28 -0500 Subject: [PATCH 178/244] [ticket/9983] Add a test for destroy. PHPBB3-9983 --- tests/cache/common_test_case.php | 23 +++++++++++++++++++++++ tests/cache/null_driver_test.php | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 5c387d98a1..45cf80e424 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -38,4 +38,27 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('test_key')); } + + public function test_destroy() + { + $this->driver->put('first_key', 'first_value'); + $this->driver->put('second_key', 'second_value'); + + $this->assertEquals( + 'first_value', + $this->driver->get('first_key') + ); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + + $this->driver->destroy('first_key'); + + $this->assertFalse($this->driver->_exists('first_key')); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + } } diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 1e8b254294..86553d4dc5 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -39,6 +39,12 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->driver->purge(); } + public function test_destroy() + { + // does nothing + $this->driver->destroy('foo'); + } + public function test_cache_sql() { global $db, $cache; From 720ef233b122d00ef9d2128c9a0a518ff017b0d7 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sat, 1 Dec 2012 22:34:03 -0600 Subject: [PATCH 179/244] [ticket/11219] Only update sequences that are affected by a fixture PHPBB3-11219 --- .../phpbb_database_test_case.php | 18 +++-- ...phpbb_database_test_connection_manager.php | 73 +++++++++++-------- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 0916679108..429bb92bf1 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -13,6 +13,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test protected $test_case_helpers; + protected $fixture_xml_data; + public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); @@ -32,10 +34,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { parent::setUp(); - $config = $this->get_database_config(); - $manager = $this->create_connection_manager($config); - $manager->connect(); - $manager->post_setup_synchronisation(); + // Resynchronise tables if a fixture was loaded + if (isset($this->fixture_xml_data)) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->post_setup_synchronisation($this->fixture_xml_data); + } } public function createXMLDataSet($path) @@ -57,7 +63,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $path = $meta_data['uri']; } - return parent::createXMLDataSet($path); + $this->fixture_xml_data = parent::createXMLDataSet($path); + + return $this->fixture_xml_data; } public function get_test_case_helpers() diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index e79a764e1d..97281a0812 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -429,12 +429,19 @@ class phpbb_database_test_connection_manager /** * Performs synchronisations on the database after a fixture has been loaded + * + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $tables Tables contained within the loaded fixture + * + * @return null */ - public function post_setup_synchronisation() + public function post_setup_synchronisation($xmlDataSet) { $this->ensure_connected(__METHOD__); $queries = array(); + // Get escaped versions of the table names used in the fixture + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xmlDataSet->getTableNames()); + switch ($this->config['dbms']) { case 'oracle': @@ -445,7 +452,9 @@ class phpbb_database_test_connection_manager JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) WHERE d.referenced_type = 'SEQUENCE' - AND d.type = 'TRIGGER'"; + AND d.type = 'TRIGGER' + AND t.table_name IN (" . implode(', ', array_map('strtoupper', $table_names)) . ')'; + $result = $this->pdo->query($sql); while ($row = $result->fetch(PDO::FETCH_ASSOC)) @@ -476,41 +485,43 @@ class phpbb_database_test_connection_manager break; case 'postgres': - // First get the sequences - $sequences = array(); - $sql = "SELECT relname FROM pg_class WHERE relkind = 'S'"; + // Get the sequences attached to the tables + $sql = 'SELECT column_name, table_name FROM information_schema.columns + WHERE table_name IN (' . implode(', ', $table_names) . ") + AND strpos(column_default, '_seq''::regclass') > 0"; $result = $this->pdo->query($sql); + + $setval_queries = array(); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $sequences[] = $row['relname']; + // Get the columns used in the fixture for this table + $column_names = $xmlDataSet->getTableMetaData($row['table_name'])->getColumns(); + + // Skip sequences that weren't specified in the fixture + if (!in_array($row['column_name'], $column_names)) + { + continue; + } + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$row['column_name']}) + 1 FROM {$row['table_name']}), 1) AS val"; + $result_max = $this->pdo->query($sql); + $row_max = $result_max->fetch(PDO::FETCH_ASSOC); + + if ($row_max) + { + $seq_name = $this->pdo->quote($row['table_name'] . '_seq'); + $max_val = (int) $row_max['val']; + + // The last parameter is false so that the system doesn't increment it again + $setval_queries[] = "SETVAL($seq_name, $max_val, false)"; + } } - // Now get the name of the column using it - foreach ($sequences as $sequence) + // Combine all of the SETVALs into one query + if (sizeof($setval_queries)) { - $table = str_replace('_seq', '', $sequence); - $sql = "SELECT column_name FROM information_schema.columns - WHERE table_name = '$table' - AND column_default = 'nextval(''$sequence''::regclass)'"; - $result = $this->pdo->query($sql); - $row = $result->fetch(PDO::FETCH_ASSOC); - - // Finally, set the new sequence value - if ($row) - { - $column = $row['column_name']; - - // Get the old value if it exists, or use 1 if it doesn't - $sql = "SELECT COALESCE((SELECT MAX({$column}) + 1 FROM {$table}), 1) AS val"; - $result = $this->pdo->query($sql); - $row = $result->fetch(PDO::FETCH_ASSOC); - - if ($row) - { - // The last parameter is false so that the system doesn't increment it again - $queries[] = "SELECT SETVAL('{$sequence}', {$row['val']}, false)"; - } - } + $queries[] = 'SELECT ' . implode(', ', $setval_queries); } break; } From dacacbbd52dc22f3344f313301cf6b4fb0f77233 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Sun, 15 Apr 2012 13:08:44 +0530 Subject: [PATCH 180/244] [ticket/10771] Using Remember Me instead of autologin or persistent keys Changed language variable LOG_ME_IN's value to "Remember me" PHPBB3-10771 --- phpBB/language/en/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 4300ef431a..71f1beb66a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -343,7 +343,7 @@ $lang = array_merge($lang, array( 'LOGIN_EXPLAIN_VIEWONLINE' => 'In order to view the online list you have to be registered and logged in.', 'LOGOUT' => 'Logout', 'LOGOUT_USER' => 'Logout [ %s ]', - 'LOG_ME_IN' => 'Log me on automatically each visit', + 'LOG_ME_IN' => 'Remember me', 'MARK' => 'Mark', 'MARK_ALL' => 'Mark all', From a17c1a29f8ce5781082dcf87a8bde261647062f0 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Wed, 18 Apr 2012 12:13:00 +0530 Subject: [PATCH 181/244] [ticket/10771] changed value in help_faq.php PHPBB3-10771 --- phpBB/language/en/help_faq.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index 5c99f81c06..9500943b88 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -43,7 +43,7 @@ $help = array( ), array( 0 => 'Why do I get logged off automatically?', - 1 => 'If you do not check the Log me in automatically box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' + 1 => 'If you do not check the Remember me box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' ), array( 0 => 'How do I prevent my username appearing in the online user listings?', From a97401a180657b8b9526c5a0af055d46cf3e8487 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 00:03:22 +0100 Subject: [PATCH 182/244] [ticket/10771] use remember me in acp PHPBB3-10771 --- phpBB/language/en/acp/board.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index a4380486cc..4adcbd689e 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -449,10 +449,10 @@ $lang = array_merge($lang, array( 'ACP_SECURITY_SETTINGS_EXPLAIN' => 'Here you are able to define session and login related settings.', 'ALL' => 'All', - 'ALLOW_AUTOLOGIN' => 'Allow persistent logins', - 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can autologin when they visit the board.', - 'AUTOLOGIN_LENGTH' => 'Persistent login key expiration length (in days)', - 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which persistent login keys are removed or zero to disable.', + 'ALLOW_AUTOLOGIN' => 'Allow remember me logins', + 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can select remember me option when they visit the board.', + 'AUTOLOGIN_LENGTH' => 'Remember me login key expiration length (in days)', + 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which remember me login keys are removed or zero to disable.', 'BROWSER_VALID' => 'Validate browser', 'BROWSER_VALID_EXPLAIN' => 'Enables browser validation for each session improving security.', 'CHECK_DNSBL' => 'Check IP against DNS Blackhole List', From 619e15378dd6839b26ceb7a698b8d07fa5ebbec9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 00:03:45 +0100 Subject: [PATCH 183/244] [ticket/10771] use remember me in ucp PHPBB3-10771 --- phpBB/language/en/ucp.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 705b07b170..0ae58392d5 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -87,7 +87,7 @@ $lang = array_merge($lang, array( 'ATTACHMENTS_EXPLAIN' => 'This is a list of attachments you have made in posts to this board.', 'ATTACHMENTS_DELETED' => 'Attachments successfully deleted.', 'ATTACHMENT_DELETED' => 'Attachment successfully deleted.', - 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected persistent login keys were successfully deleted.', + 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected remember me login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_EXPLAIN' => 'Maximum dimensions; width: %1$s, height: %2$s, file size: %3$.2f KiB.', 'AVATAR_FEATURES_DISABLED' => 'The avatar functionality is currently disabled.', @@ -380,8 +380,8 @@ $lang = array_merge($lang, array( 'PREFERENCES_UPDATED' => 'Your preferences have been updated.', 'PROFILE_INFO_NOTICE' => 'Please note that this information may be viewable to other members. Be careful when including any personal details. Any fields marked with a * must be completed.', 'PROFILE_UPDATED' => 'Your profile has been updated.', - 'PROFILE_AUTOLOGIN_KEYS' => 'The persistent login keys automatically log you in when you visit the board. If you logout, the persistent login key is deleted only on the computer you are using to logout. Here you can see persistent login keys created on other computers you used to access this site.', - 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved persistent login keys.', + 'PROFILE_AUTOLOGIN_KEYS' => 'The remember me login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', + 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved remember me login keys.', 'RECIPIENT' => 'Recipient', 'RECIPIENTS' => 'Recipients', @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'UCP_PROFILE_PROFILE_INFO' => 'Edit profile', 'UCP_PROFILE_REG_DETAILS' => 'Edit account settings', 'UCP_PROFILE_SIGNATURE' => 'Edit signature', - 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit persistent login keys', + 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit remember me login keys', 'UCP_USERGROUPS' => 'Usergroups', 'UCP_USERGROUPS_MEMBER' => 'Edit memberships', From 37f2841af2d1027b92953ee2c08da44481d0a06e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 15:20:43 +0530 Subject: [PATCH 184/244] [ticket/10771] fix remember me language PHPBB3-10771 --- phpBB/language/en/acp/board.php | 8 ++++---- phpBB/language/en/ucp.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 4adcbd689e..1b99c87938 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -449,10 +449,10 @@ $lang = array_merge($lang, array( 'ACP_SECURITY_SETTINGS_EXPLAIN' => 'Here you are able to define session and login related settings.', 'ALL' => 'All', - 'ALLOW_AUTOLOGIN' => 'Allow remember me logins', - 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can select remember me option when they visit the board.', - 'AUTOLOGIN_LENGTH' => 'Remember me login key expiration length (in days)', - 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which remember me login keys are removed or zero to disable.', + 'ALLOW_AUTOLOGIN' => 'Allow "Remember Me" logins', + 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users are given "Remember Me" option when they visit the board.', + 'AUTOLOGIN_LENGTH' => '"Remember Me" login key expiration length (in days)', + 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which "Remember Me" login keys are removed or zero to disable.', 'BROWSER_VALID' => 'Validate browser', 'BROWSER_VALID_EXPLAIN' => 'Enables browser validation for each session improving security.', 'CHECK_DNSBL' => 'Check IP against DNS Blackhole List', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 0ae58392d5..b919699ea0 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -87,7 +87,7 @@ $lang = array_merge($lang, array( 'ATTACHMENTS_EXPLAIN' => 'This is a list of attachments you have made in posts to this board.', 'ATTACHMENTS_DELETED' => 'Attachments successfully deleted.', 'ATTACHMENT_DELETED' => 'Attachment successfully deleted.', - 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected remember me login keys were successfully deleted.', + 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected "Remember Me" login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_EXPLAIN' => 'Maximum dimensions; width: %1$s, height: %2$s, file size: %3$.2f KiB.', 'AVATAR_FEATURES_DISABLED' => 'The avatar functionality is currently disabled.', @@ -380,8 +380,8 @@ $lang = array_merge($lang, array( 'PREFERENCES_UPDATED' => 'Your preferences have been updated.', 'PROFILE_INFO_NOTICE' => 'Please note that this information may be viewable to other members. Be careful when including any personal details. Any fields marked with a * must be completed.', 'PROFILE_UPDATED' => 'Your profile has been updated.', - 'PROFILE_AUTOLOGIN_KEYS' => 'The remember me login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', - 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved remember me login keys.', + 'PROFILE_AUTOLOGIN_KEYS' => 'The "Remember Me" login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', + 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved "Remember Me" login keys.', 'RECIPIENT' => 'Recipient', 'RECIPIENTS' => 'Recipients', @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'UCP_PROFILE_PROFILE_INFO' => 'Edit profile', 'UCP_PROFILE_REG_DETAILS' => 'Edit account settings', 'UCP_PROFILE_SIGNATURE' => 'Edit signature', - 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit remember me login keys', + 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit "Remember Me" login keys', 'UCP_USERGROUPS' => 'Usergroups', 'UCP_USERGROUPS_MEMBER' => 'Edit memberships', From 9d5fc4ae33ac5a5ea2dc85fd4157ce56653c4a16 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 13:16:11 -0500 Subject: [PATCH 185/244] [ticket/11238] Set goutte to 0.1.0 in develop. PHPBB3-11238 --- phpBB/composer.json | 2 +- phpBB/composer.lock | 170 +++++++++++++++++--------------------------- 2 files changed, 68 insertions(+), 104 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index 5a03e68f73..d2536a73cf 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -9,6 +9,6 @@ "symfony/yaml": "2.1.*" }, "require-dev": { - "fabpot/goutte": "1.0.x-dev" + "fabpot/goutte": "v0.1.0" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 62ece6d505..e96c15fe8b 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,5 +1,5 @@ { - "hash": "efb4768ba71d7cd2c84baa0610d84067", + "hash": "c1a76530df6b9daa16b8033d61b76503", "packages": [ { "name": "symfony/config", @@ -381,29 +381,29 @@ "packages-dev": [ { "name": "fabpot/goutte", - "version": "dev-master", + "version": "v0.1.0", "source": { "type": "git", "url": "https://github.com/fabpot/Goutte", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48" + "reference": "v0.1.0" }, "dist": { "type": "zip", - "url": "https://github.com/fabpot/Goutte/archive/f2940f9c7c1f409159f5e9f512e575946c5cff48.zip", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48", + "url": "https://github.com/fabpot/Goutte/archive/v0.1.0.zip", + "reference": "v0.1.0", "shasum": "" }, "require": { "php": ">=5.3.0", + "ext-curl": "*", "symfony/browser-kit": "2.1.*", "symfony/css-selector": "2.1.*", "symfony/dom-crawler": "2.1.*", "symfony/finder": "2.1.*", "symfony/process": "2.1.*", - "ext-curl": "*", - "guzzle/http": "2.8.*" + "guzzle/guzzle": "3.0.*" }, - "time": "1351086217", + "time": "2012-12-02 13:44:35", "type": "application", "extra": { "branch-alias": { @@ -432,126 +432,90 @@ ] }, { - "name": "guzzle/common", - "version": "v2.8.8", - "target-dir": "Guzzle/Common", + "name": "guzzle/guzzle", + "version": "v3.0.5", "source": { "type": "git", - "url": "git://github.com/guzzle/common.git", - "reference": "v2.8.8" + "url": "https://github.com/guzzle/guzzle", + "reference": "v3.0.5" }, "dist": { "type": "zip", - "url": "https://github.com/guzzle/common/zipball/v2.8.8", - "reference": "v2.8.8", + "url": "https://github.com/guzzle/guzzle/archive/v3.0.5.zip", + "reference": "v3.0.5", "shasum": "" }, "require": { "php": ">=5.3.2", + "ext-curl": "*", "symfony/event-dispatcher": "2.1.*" }, - "time": "2012-10-15 17:42:47", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Common": "" - } - }, - "license": [ - "MIT" - ], - "description": "Common libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "log", - "event", - "cache", - "validation", - "Socket", - "common", - "batch", - "inflection" - ] - }, - { - "name": "guzzle/http", - "version": "v2.8.8", - "target-dir": "Guzzle/Http", - "source": { - "type": "git", - "url": "git://github.com/guzzle/http.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/http/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2", + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", "guzzle/common": "self.version", - "guzzle/parser": "self.version" + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" }, - "time": "2012-10-15 17:42:47", + "require-dev": { + "doctrine/common": "*", + "symfony/class-loader": "*", + "monolog/monolog": "1.*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*", + "zend/zend-log1": "1.12", + "zend/zend-cache1": "1.12", + "phpunit/phpunit": "3.7.*" + }, + "time": "2012-11-19 00:15:33", "type": "library", "installation-source": "dist", "autoload": { "psr-0": { - "Guzzle\\Http": "" + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" } }, "license": [ "MIT" ], - "description": "HTTP libraries used by Guzzle", + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", "homepage": "http://guzzlephp.org/", "keywords": [ + "framework", "curl", "http", + "rest", "http client", "client", - "Guzzle" - ] - }, - { - "name": "guzzle/parser", - "version": "v2.8.8", - "target-dir": "Guzzle/Parser", - "source": { - "type": "git", - "url": "git://github.com/guzzle/parser.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/parser/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "time": "2012-09-20 13:28:06", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Parser": "" - } - }, - "license": [ - "MIT" - ], - "description": "Interchangeable parsers used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "http", - "url", - "message", - "cookie", - "URI Template" + "web service" ] }, { @@ -808,7 +772,7 @@ ], "minimum-stability": "beta", - "stability-flags": { - "fabpot/goutte": 20 - } + "stability-flags": [ + + ] } From 6f7e39996c926b0f0080ccdd594fd465c311cb79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:44:49 -0500 Subject: [PATCH 186/244] [ticket/11238] Set goutte version to 0.1.0. PHPBB3-11238 --- phpBB/composer.json | 2 +- phpBB/composer.lock | 463 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 433 insertions(+), 32 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index c2811ad1d7..8d5dd1d52e 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -1,6 +1,6 @@ { "minimum-stability": "beta", "require-dev": { - "fabpot/goutte": "1.0.x-dev" + "fabpot/goutte": "v0.1.0" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 9f2195e70a..a78fff9a14 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,55 +1,456 @@ { - "hash": "a5d02c59e3a91c84c1a96aca0f1ae81a", + "hash": "23352b29002e6d22658e314a8e737f71", "packages": [ - + { + "name": "symfony/event-dispatcher", + "version": "v2.1.4", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/EventDispatcher/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "2.1.*" + }, + "suggest": { + "symfony/dependency-injection": "2.1.*", + "symfony/http-kernel": "2.1.*" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com" + } ], "packages-dev": [ { - "package": "fabpot/goutte", - "version": "dev-master", - "alias-pretty-version": "1.0.x-dev", - "alias-version": "1.0.9999999.9999999-dev" + "name": "fabpot/goutte", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Goutte", + "reference": "v0.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/fabpot/Goutte/archive/v0.1.0.zip", + "reference": "v0.1.0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "ext-curl": "*", + "symfony/browser-kit": "2.1.*", + "symfony/css-selector": "2.1.*", + "symfony/dom-crawler": "2.1.*", + "symfony/finder": "2.1.*", + "symfony/process": "2.1.*", + "guzzle/guzzle": "3.0.*" + }, + "time": "2012-12-02 13:44:35", + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "source", + "autoload": { + "psr-0": { + "Goutte": "." + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A simple PHP Web Scraper", + "homepage": "https://github.com/fabpot/Goutte", + "keywords": [ + "scraper" + ] }, { - "package": "fabpot/goutte", - "version": "dev-master", - "source-reference": "c2ea8d9a6682d14482e57ede2371001b8a5238d2", - "commit-date": "1340264258" + "name": "guzzle/guzzle", + "version": "v3.0.5", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle", + "reference": "v3.0.5" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/guzzle/archive/v3.0.5.zip", + "reference": "v3.0.5", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "ext-curl": "*", + "symfony/event-dispatcher": "2.1.*" + }, + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", + "guzzle/common": "self.version", + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" + }, + "require-dev": { + "doctrine/common": "*", + "symfony/class-loader": "*", + "monolog/monolog": "1.*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*", + "zend/zend-log1": "1.12", + "zend/zend-cache1": "1.12", + "phpunit/phpunit": "3.7.*" + }, + "time": "2012-11-19 00:15:33", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "framework", + "curl", + "http", + "rest", + "http client", + "client", + "web service" + ] }, { - "package": "guzzle/guzzle", - "version": "v2.6.6" + "name": "symfony/browser-kit", + "version": "v2.1.4", + "target-dir": "Symfony/Component/BrowserKit", + "source": { + "type": "git", + "url": "https://github.com/symfony/BrowserKit", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/BrowserKit/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/dom-crawler": "2.1.*" + }, + "require-dev": { + "symfony/process": "2.1.*", + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/process": "2.1.*" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\BrowserKit": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/browser-kit", - "version": "v2.1.0-BETA3" + "name": "symfony/css-selector", + "version": "v2.1.4", + "target-dir": "Symfony/Component/CssSelector", + "source": { + "type": "git", + "url": "https://github.com/symfony/CssSelector", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/CssSelector/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\CssSelector": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/css-selector", - "version": "v2.1.0-BETA3" + "name": "symfony/dom-crawler", + "version": "v2.1.4", + "target-dir": "Symfony/Component/DomCrawler", + "source": { + "type": "git", + "url": "https://github.com/symfony/DomCrawler", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/DomCrawler/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/css-selector": "2.1.*" + }, + "time": "2012-11-29 10:32:18", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\DomCrawler": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/dom-crawler", - "version": "v2.1.0-BETA3" + "name": "symfony/finder", + "version": "v2.1.4", + "target-dir": "Symfony/Component/Finder", + "source": { + "type": "git", + "url": "https://github.com/symfony/Finder", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Finder/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Finder": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/event-dispatcher", - "version": "v2.1.0-BETA3" - }, - { - "package": "symfony/finder", - "version": "v2.1.0-BETA3" - }, - { - "package": "symfony/process", - "version": "v2.1.0-BETA3" + "name": "symfony/process", + "version": "v2.1.4", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Process/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-19 20:53:52", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Process": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com" } ], "aliases": [ ], "minimum-stability": "beta", - "stability-flags": { - "fabpot/goutte": 20 - } + "stability-flags": [ + + ] } From df78c616aadf57ebb00988b299b34d39b558fda1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:54:59 -0500 Subject: [PATCH 187/244] [ticket/9983] Indeed, it is Date: Sun, 2 Dec 2012 23:55:42 -0500 Subject: [PATCH 188/244] [ticket/9983] Empty line by request. PHPBB3-9983 --- phpBB/includes/cache/driver/redis.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index ae6f9e04f2..960735b673 100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php @@ -67,6 +67,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory { $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); } + if (!$ok) { trigger_error('Could not connect to redis server'); From 7d09b9b4bb58e71f0e7b895ef32059ad08d12416 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:57:37 -0500 Subject: [PATCH 189/244] [ticket/9983] Add phpbb prefix to global variables. PHPBB3-9983 --- tests/RUNNING_TESTS.txt | 4 ++-- tests/test_framework/phpbb_test_case_helpers.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 395cf1240a..75a6fc94f6 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -80,8 +80,8 @@ or port must be specified in test configuration. This can be done via test_config.php as follows: Date: Mon, 3 Dec 2012 00:18:52 -0500 Subject: [PATCH 190/244] [ticket/9983] Test for apc cache driver. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/cache/apc_driver_test.php diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php new file mode 100644 index 0000000000..f6e001f705 --- /dev/null +++ b/tests/cache/apc_driver_test.php @@ -0,0 +1,79 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('apc')) + { + self::markTestSkipped('apc extension is not loaded'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_apc; + $this->driver->purge(); + } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse(apc_fetch($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue((bool) apc_fetch($key)); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} From 0b4b7e68a75438368868ede050bc6dd66fc80767 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:17:34 +0100 Subject: [PATCH 191/244] [ticket/9983] Skip tests if APC is not enabled for CLI. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index f6e001f705..f7cf2119ed 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -29,6 +29,12 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case { self::markTestSkipped('apc extension is not loaded'); } + + $php_ini = new phpbb_php_ini; + if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) + { + self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); + } } protected function setUp() From 2e851baab90b0c9960eb7427acf41bfb8a848195 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:18:05 +0100 Subject: [PATCH 192/244] [ticket/9983] Use APC instead of apc in error messages. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index f7cf2119ed..100ba76686 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -27,7 +27,7 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case { if (!extension_loaded('apc')) { - self::markTestSkipped('apc extension is not loaded'); + self::markTestSkipped('APC extension is not loaded'); } $php_ini = new phpbb_php_ini; From db6b11a3902c27b612d7d6d4696c4cd8cf1f0bdf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:35:59 +0100 Subject: [PATCH 193/244] [ticket/9983] Also check generic APC enable/disable. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index 100ba76686..c8b8f82b67 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -31,6 +31,12 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case } $php_ini = new phpbb_php_ini; + + if (!$php_ini->get_bool('apc.enabled')) + { + self::markTestSkipped('APC is not enabled. Make sure apc.enabled=1 in php.ini'); + } + if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) { self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); From e845e2ed89f75a5c9f14191f833334d84d389faf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 4 Dec 2012 00:40:24 +0100 Subject: [PATCH 194/244] [ticket/11240] Enable PHPUnit's verbose mode so we get a list of skipped tests. PHPBB3-11240 --- travis/phpunit-mysql-travis.xml | 1 + travis/phpunit-postgres-travis.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/travis/phpunit-mysql-travis.xml b/travis/phpunit-mysql-travis.xml index e54b2bb77b..5366494c8b 100644 --- a/travis/phpunit-mysql-travis.xml +++ b/travis/phpunit-mysql-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> diff --git a/travis/phpunit-postgres-travis.xml b/travis/phpunit-postgres-travis.xml index 55ba996548..0383edd9d6 100644 --- a/travis/phpunit-postgres-travis.xml +++ b/travis/phpunit-postgres-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> From d93f582b04d2e6d0738cd6a2ffee739b8c987276 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 3 Dec 2012 21:47:29 -0500 Subject: [PATCH 195/244] [ticket/9983] Make sql cache test into a black box. This makes it non-driver-specific and also makes it possible to make prefix variable private on drivers. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 38 ---------------------------- tests/cache/common_test_case.php | 33 ++++++++++++++++++++++++ tests/cache/file_driver_test.php | 38 ---------------------------- tests/cache/redis_driver_test.php | 42 ------------------------------- 4 files changed, 33 insertions(+), 118 deletions(-) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index c8b8f82b67..3380762878 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -50,42 +50,4 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case $this->driver = new phpbb_cache_driver_apc; $this->driver->purge(); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse(apc_fetch($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue((bool) apc_fetch($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 45cf80e424..fa298ec9ae 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -61,4 +61,37 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case $this->driver->get('second_key') ); } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } } diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 2353940277..745c6bb081 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -66,42 +66,4 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case } rmdir($this->cache_dir); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; - $this->assertFileNotExists($cache_path); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertFileExists($cache_path); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index cd24e33baf..c59d5e1929 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -46,46 +46,4 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); $this->driver->purge(); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $redis = new Redis(); - $ok = $redis->connect(self::$config['host'], self::$config['port']); - $this->assertTrue($ok); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse($redis->exists($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue($redis->exists($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } From f08c28c77a585e35cc17a2248ba61428275ccdd7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 01:59:27 -0500 Subject: [PATCH 196/244] [ticket/10103] Factor out flock lock class. PHPBB3-10103 --- phpBB/includes/functions_messenger.php | 58 ------------ phpBB/includes/lock/flock.php | 124 +++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 58 deletions(-) create mode 100644 phpBB/includes/lock/flock.php diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index cf03de08c4..503f419e5a 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -650,64 +650,6 @@ class queue $this->data[$object]['data'][] = $scope; } - /** - * Obtains exclusive lock on queue cache file. - * Returns resource representing the lock - */ - function lock() - { - // For systems that can't have two processes opening - // one file for writing simultaneously - if (file_exists($this->cache_file . '.lock')) - { - $mode = 'rb'; - } - else - { - $mode = 'wb'; - } - - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - - if ($mode == 'wb') - { - if (!$lock_fp) - { - // Two processes may attempt to create lock file at the same time. - // Have the losing process try opening the lock file again for reading - // on the assumption that the winning process created it - $mode = 'rb'; - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - } - else - { - // Only need to set mode when the lock file is written - @chmod($this->cache_file . '.lock', 0666); - } - } - - if ($lock_fp) - { - @flock($lock_fp, LOCK_EX); - } - - return $lock_fp; - } - - /** - * Releases lock on queue cache file, using resource obtained from lock() - */ - function unlock($lock_fp) - { - // lock() will return null if opening lock file, and thus locking, failed. - // Accept null values here so that client code does not need to check them - if ($lock_fp) - { - @flock($lock_fp, LOCK_UN); - fclose($lock_fp); - } - } - /** * Process queue * Using lock file diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php new file mode 100644 index 0000000000..e24a5f3e1c --- /dev/null +++ b/phpBB/includes/lock/flock.php @@ -0,0 +1,124 @@ +path = $path; + $this->lock_fp = null; + } + + /** + * Tries to acquire the lock. + * + * As a lock may only be held by one process at a time, lock + * acquisition may fail if another process is holding the lock. + * + * @return bool true if lock was acquired + * false otherwise + */ + public function acquire() + { + if ($this->locked) + { + return false; + } + + // For systems that can't have two processes opening + // one file for writing simultaneously + if (file_exists($this->path . '.lock')) + { + $mode = 'rb'; + } + else + { + $mode = 'wb'; + } + + $this->lock_fp = @fopen($this->path . '.lock', $mode); + + if ($mode == 'wb') + { + if (!$this->lock_fp) + { + // Two processes may attempt to create lock file at the same time. + // Have the losing process try opening the lock file again for reading + // on the assumption that the winning process created it + $mode = 'rb'; + $this->lock_fp = @fopen($this->path . '.lock', $mode); + } + else + { + // Only need to set mode when the lock file is written + @chmod($this->path . '.lock', 0666); + } + } + + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_EX); + } + + return (bool) $this->lock_fp; + } + + /** + * Releases the lock. + * + * The lock must have been previously obtained, that is, acquire() call + * was issued and returned true. + * + * Note: Attempting to release a lock that is already released, + * that is, calling release() multiple times, is harmless. + * + * @return null + */ + public function release() + { + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_UN); + fclose($this->lock_fp); + $this->lock_fp = null; + } + } +} From 4010f4085aa56f20fd95274ecfc2fe7404f98269 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:00:27 -0500 Subject: [PATCH 197/244] [ticket/10103] Use flock lock class in messenger. PHPBB3-10103 --- phpBB/includes/functions_messenger.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 503f419e5a..56fc7e628f 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -658,13 +658,14 @@ class queue { global $db, $config, $phpEx, $phpbb_root_path, $user; - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); set_config('last_queue_run', time(), true); if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) { - $this->unlock($lock_fp); + $lock->release(); return; } @@ -731,7 +732,7 @@ class queue break; default: - $this->unlock($lock_fp); + $lock->release(); return; } @@ -807,7 +808,7 @@ class queue } } - $this->unlock($lock_fp); + $lock->release(); } /** @@ -820,7 +821,8 @@ class queue return; } - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); if (file_exists($this->cache_file)) { @@ -847,7 +849,7 @@ class queue phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE); } - $this->unlock($lock_fp); + $lock->release(); } } From f72e435759e8fafe3b06af35072c1907ba016546 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:21:53 -0500 Subject: [PATCH 198/244] [ticket/10103] Test for flock lock class, with concurrency no less. PHPBB3-10103 --- tests/lock/flock_test.php | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/lock/flock_test.php diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php new file mode 100644 index 0000000000..5c645de27c --- /dev/null +++ b/tests/lock/flock_test.php @@ -0,0 +1,108 @@ +acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + public function test_consecutive_locking() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + /* This hangs the process. + public function test_concurrent_locking_fail() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock1 = new phpbb_lock_flock($path); + $ok = $lock1->acquire(); + $this->assertTrue($ok); + + $lock2 = new phpbb_lock_flock($path); + $ok = $lock2->acquire(); + $this->assertFalse($ok); + + $lock->release(); + $ok = $lock2->acquire(); + $this->assertTrue($ok); + } + */ + + public function test_concurrent_locking() + { + if (!function_exists('pcntl_fork')) + { + $this->markTestSkipped('pcntl extension and pcntl_fork are required for this test'); + } + + $path = __DIR__ . '/../tmp/precious'; + + if ($pid = pcntl_fork()) + { + // parent + // wait 0.5 s, acquire the lock, note how long it took + sleep(0.5); + + $lock = new phpbb_lock_flock($path); + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertTrue($delta > 0.5); + + $lock->release(); + + // acquire again, this should be instantaneous + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertTrue($delta < 0.1); + + // reap the child + $status = null; + pcntl_waitpid($pid, $status); + } + else + { + // child + // immediately acquire the lock and sleep for 2 s + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + sleep(2); + $lock->release(); + + // and go away silently + pcntl_exec('/usr/bin/env', array('true')); + } + } +} From 318140b4d6257dd49ae86ed1185568f4d523e53e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:26:55 -0500 Subject: [PATCH 199/244] [ticket/10103] Convert the rest of the tree to flock class. PHPBB3-10103 --- phpBB/includes/cache/driver/file.php | 16 +++++++++++----- phpBB/includes/template/compile.php | 8 +++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index a0f06dde4b..ee1b430451 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -653,10 +653,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base $file = "{$this->cache_dir}$filename.$phpEx"; + $lock = new phpbb_lock_flock($file); + $lock->acquire(); + if ($handle = @fopen($file, 'wb')) { - @flock($handle, LOCK_EX); - // File header fwrite($handle, '<' . '?php exit; ?' . '>'); @@ -697,7 +698,6 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base fwrite($handle, $data); } - @flock($handle, LOCK_UN); fclose($handle); if (!function_exists('phpbb_chmod')) @@ -708,10 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); - return true; + $rv = true; + } + else + { + $rv = false; } - return false; + $lock->release(); + + return $rv; } /** diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index d0b3d0f115..22da21820e 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -58,6 +58,9 @@ class phpbb_template_compile */ public function compile_file_to_file($source_file, $compiled_file) { + $lock = new phpbb_lock_flock($compiled_file); + $lock->acquire(); + $source_handle = @fopen($source_file, 'rb'); $destination_handle = @fopen($compiled_file, 'wb'); @@ -66,16 +69,15 @@ class phpbb_template_compile return false; } - @flock($destination_handle, LOCK_EX); - $this->compile_stream_to_stream($source_handle, $destination_handle); @fclose($source_handle); - @flock($destination_handle, LOCK_UN); @fclose($destination_handle); phpbb_chmod($compiled_file, CHMOD_READ | CHMOD_WRITE); + $lock->release(); + clearstatcache(); return true; From fc410e1cd0071a2de3dc90ce62a5abbef0266f15 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:38:57 -0500 Subject: [PATCH 200/244] [ticket/10103] Try a longer sleep for travis. Apparently travis takes longer than half a second to fork php. PHPBB3-10103 --- tests/lock/flock_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 5c645de27c..bc682f9410 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -69,7 +69,7 @@ class phpbb_lock_flock_test extends phpbb_test_case { // parent // wait 0.5 s, acquire the lock, note how long it took - sleep(0.5); + sleep(1); $lock = new phpbb_lock_flock($path); $start = time(); From cf3080b83ed6f90b24cfd99a9fc7dd71dddde827 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:39:50 -0500 Subject: [PATCH 201/244] [ticket/9983] Correct incorrect markTestSkipped call. PHPBB3-9983 --- tests/cache/redis_driver_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index cd24e33baf..a90a750460 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -35,7 +35,7 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case } else { - $this->markTestSkipped('Test redis host/port is not specified'); + self::markTestSkipped('Test redis host/port is not specified'); } } From b67f112e03cf37436bdd650ea4b9a75b35000fdd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:52:18 -0500 Subject: [PATCH 202/244] [ticket/10091] Bump minimum supported postgresql version to 8.3. PHPBB3-10091 --- phpBB/docs/INSTALL.html | 2 +- phpBB/docs/coding-guidelines.html | 2 +- phpBB/includes/functions_install.php | 2 +- phpBB/language/en/install.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/INSTALL.html b/phpBB/docs/INSTALL.html index 07f0cbc8c2..58aeb904c7 100644 --- a/phpBB/docs/INSTALL.html +++ b/phpBB/docs/INSTALL.html @@ -132,7 +132,7 @@
  • A SQL database system, one of:
    • MySQL 3.23 or above (MySQLi supported)
    • -
    • PostgreSQL 7.3+
    • +
    • PostgreSQL 8.3+
    • SQLite 2.8.2+ (SQLite 3 is not supported)
    • Firebird 2.1+
    • MS SQL Server 2000 or above (directly or via ODBC or the native adapter)
    • diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 0e3a97c004..eb569d12d5 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -740,7 +740,7 @@ static private function f()

      2.iii. SQL/SQL Layout

      Common SQL Guidelines:

      -

      All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).

      +

      All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (8.3+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).

      All SQL commands should utilise the DataBase Abstraction Layer (DBAL)

      SQL code layout:

      diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 7a799993db..ab6b3ea009 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -87,7 +87,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20 '2.0.x' => false, ), 'postgres' => array( - 'LABEL' => 'PostgreSQL 7.x/8.x', + 'LABEL' => 'PostgreSQL 8.3+', 'SCHEMA' => 'postgres', 'MODULE' => 'pgsql', 'DELIM' => ';', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index cb6a17afa2..1c45deae11 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -210,7 +210,7 @@ $lang = array_merge($lang, array(

      phpBB3 supports the following databases:

      • MySQL 3.23 or above (MySQLi supported)
      • -
      • PostgreSQL 7.3+
      • +
      • PostgreSQL 8.3+
      • SQLite 2.8.2+
      • Firebird 2.1+
      • MS SQL Server 2000 or above (directly or via ODBC)
      • From af2887f3a7f27b33c2ecd14d4baab846b71ddb62 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 03:34:51 -0500 Subject: [PATCH 203/244] [ticket/10716] php parse all php files as part of the test suite. PHPBB3-10716 --- tests/lint_test.php | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/lint_test.php diff --git a/tests/lint_test.php b/tests/lint_test.php new file mode 100644 index 0000000000..57c78ae809 --- /dev/null +++ b/tests/lint_test.php @@ -0,0 +1,49 @@ +check($root); + } + + protected function check($root) + { + $dh = opendir($root); + while (($filename = readdir($dh)) !== false) + { + if ($filename == '.' || $filename == '..' || $filename == 'git') + { + continue; + } + $path = $root . '/' . $filename; + // skip symlinks to avoid infinite loops + if (is_link($path)) + { + continue; + } + if (is_dir($path)) + { + $this->check($path); + } + else if (substr($filename, strlen($filename)-4) == '.php') + { + // assume php binary is called php and it is in PATH + $cmd = 'php -l ' . escapeshellarg($path); + $output = array(); + $status = 1; + exec($cmd, $output, $status); + $output = implode("\n", $output); + $this->assertEquals(0, $status, "php -l failed for $path:\n$output"); + } + } + } +} From 025a95ea909d449e14cb22564983fb005e3f8c06 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 9 Mar 2011 21:50:45 -0500 Subject: [PATCH 204/244] [ticket/10205] Account for potentially missing extensions in dbal. PHPBB3-10205 --- phpBB/includes/db/mssql_odbc.php | 20 +++++++++++++++++++- phpBB/includes/db/mysql.php | 20 +++++++++++++++++++- phpBB/includes/db/mysqli.php | 7 +++++++ phpBB/includes/db/oracle.php | 29 ++++++++++++++++++++++++++++- phpBB/includes/db/sqlite.php | 21 ++++++++++++++++++++- 5 files changed, 93 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 2ecc42cadf..dabdbd1a44 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -32,6 +32,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_mssql_odbc extends dbal { var $last_query_text = ''; + var $connect_error = ''; /** * Connect to server @@ -68,7 +69,24 @@ class dbal_mssql_odbc extends dbal @ini_set('odbc.defaultlrl', $max_size); } - $this->db_connect_id = ($this->persistency) ? @odbc_pconnect($this->server, $this->user, $sqlpassword) : @odbc_connect($this->server, $this->user, $sqlpassword); + if ($this->persistency) + { + if (!function_exists('odbc_pconnect')) + { + $this->connect_error = 'odbc_pconnect function does not exist, is odbc extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @odbc_pconnect($this->server, $this->user, $sqlpassword); + } + else + { + if (!function_exists('odbc_connect')) + { + $this->connect_error = 'odbc_connect function does not exist, is odbc extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @odbc_connect($this->server, $this->user, $sqlpassword); + } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 1ccb785150..ae36fe6425 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -30,6 +30,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_mysql extends dbal { var $multi_insert = true; + var $connect_error = ''; /** * Connect to server @@ -44,7 +45,24 @@ class dbal_mysql extends dbal $this->sql_layer = 'mysql4'; - $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); + if ($this->persistency) + { + if (!function_exists('mysql_pconnect')) + { + $this->connect_error = 'mysql_pconnect function does not exist, is mysql extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $sqlpassword); + } + else + { + if (!function_exists('mysql_connect')) + { + $this->connect_error = 'mysql_connect function does not exist, is mysql extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); + } if ($this->db_connect_id && $this->dbname != '') { diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index a311b8cda6..98b659723f 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -27,12 +27,19 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_mysqli extends dbal { var $multi_insert = true; + var $connect_error = ''; /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false) { + if (!function_exists('mysqli_connect')) + { + $this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?'; + return $this->sql_error(''); + } + // Mysqli extension supports persistent connection since PHP 5.3.0 $this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false; $this->user = $sqluser; diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 62b36aa8bf..42f5de1b24 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -25,6 +25,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_oracle extends dbal { var $last_query_text = ''; + var $connect_error = ''; /** * Connect to server @@ -48,7 +49,33 @@ class dbal_oracle extends dbal $connect = $sqlserver . (($port) ? ':' . $port : '') . '/' . $database; } - $this->db_connect_id = ($new_link) ? @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8') : (($this->persistency) ? @ociplogon($this->user, $sqlpassword, $connect, 'UTF8') : @ocilogon($this->user, $sqlpassword, $connect, 'UTF8')); + if ($new_link) + { + if (!function_exists('ocinlogon')) + { + $this->connect_error = 'ocinlogon function does not exist, is oci extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8'); + } + else if ($this->persistency) + { + if (!function_exists('ociplogon')) + { + $this->connect_error = 'ociplogon function does not exist, is oci extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @ociplogon($this->user, $sqlpassword, $connect, 'UTF8'); + } + else + { + if (!function_exists('ocilogon')) + { + $this->connect_error = 'ocilogon function does not exist, is oci extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8')); + } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 8de72fd394..be0ad4fc8f 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -25,6 +25,8 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); */ class dbal_sqlite extends dbal { + var $connect_error = ''; + /** * Connect to server */ @@ -36,7 +38,24 @@ class dbal_sqlite extends dbal $this->dbname = $database; $error = ''; - $this->db_connect_id = ($this->persistency) ? @sqlite_popen($this->server, 0666, $error) : @sqlite_open($this->server, 0666, $error); + if ($this->persistency) + { + if (!function_exists('sqlite_popen')) + { + $this->connect_error = 'sqlite_popen function does not exist, is sqlite extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @sqlite_popen($this->server, 0666, $error); + } + else + { + if (!function_exists('sqlite_open')) + { + $this->connect_error = 'sqlite_open function does not exist, is sqlite extension installed?'; + return $this->sql_error(''); + } + $this->db_connect_id = @sqlite_open($this->server, 0666, $error); + } if ($this->db_connect_id) { From 1a7e2211c35218094e30ddc399d4aa6b45fe75f4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 04:06:30 -0500 Subject: [PATCH 205/244] [ticket/10205] Avoid calling mysqli functions when mysqli is missing. PHPBB3-10205 --- phpBB/includes/db/mysqli.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 98b659723f..cd82a12b58 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -425,10 +425,20 @@ class dbal_mysqli extends dbal { if (!$this->db_connect_id) { - return array( - 'message' => @mysqli_connect_error(), - 'code' => @mysqli_connect_errno() - ); + if (function_exists('mysqli_connect_error')) + { + return array( + 'message' => @mysqli_connect_error(), + 'code' => @mysqli_connect_errno(), + ); + } + else + { + return array( + 'message' => $this->connect_error, + 'code' => '', + ); + } } return array( From 9f549e8249acbd82b68e961a6e0a31de47d9ca32 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 04:50:41 -0500 Subject: [PATCH 206/244] [ticket/10205] Fix remaining db drivers. PHPBB3-10205 --- phpBB/includes/db/mssql.php | 58 +++++++++++++++++++------------- phpBB/includes/db/mssql_odbc.php | 18 +++++++--- phpBB/includes/db/mysql.php | 18 +++++++--- phpBB/includes/db/oracle.php | 24 +++++++++---- phpBB/includes/db/sqlite.php | 18 +++++++--- 5 files changed, 93 insertions(+), 43 deletions(-) diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index b7178593dc..bc0a870885 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -355,34 +355,44 @@ class dbal_mssql extends dbal */ function _sql_error() { - $error = array( - 'message' => @mssql_get_last_message(), - 'code' => '' - ); - - // Get error code number - $result_id = @mssql_query('SELECT @@ERROR as code', $this->db_connect_id); - if ($result_id) + if (function_exists('mssql_get_last_message')) { - $row = @mssql_fetch_assoc($result_id); - $error['code'] = $row['code']; - @mssql_free_result($result_id); - } + $error = array( + 'message' => @mssql_get_last_message(), + 'code' => '' + ); - // Get full error message if possible - $sql = 'SELECT CAST(description as varchar(255)) as message - FROM master.dbo.sysmessages - WHERE error = ' . $error['code']; - $result_id = @mssql_query($sql); - - if ($result_id) - { - $row = @mssql_fetch_assoc($result_id); - if (!empty($row['message'])) + // Get error code number + $result_id = @mssql_query('SELECT @@ERROR as code', $this->db_connect_id); + if ($result_id) { - $error['message'] .= '
        ' . $row['message']; + $row = @mssql_fetch_assoc($result_id); + $error['code'] = $row['code']; + @mssql_free_result($result_id); } - @mssql_free_result($result_id); + + // Get full error message if possible + $sql = 'SELECT CAST(description as varchar(255)) as message + FROM master.dbo.sysmessages + WHERE error = ' . $error['code']; + $result_id = @mssql_query($sql); + + if ($result_id) + { + $row = @mssql_fetch_assoc($result_id); + if (!empty($row['message'])) + { + $error['message'] .= '
        ' . $row['message']; + } + @mssql_free_result($result_id); + } + } + else + { + $error = array( + 'message' => $this->connect_error, + 'code' => '', + ); } return $error; diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index dabdbd1a44..e1234389df 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -360,10 +360,20 @@ class dbal_mssql_odbc extends dbal */ function _sql_error() { - return array( - 'message' => @odbc_errormsg(), - 'code' => @odbc_error() - ); + if (function_exists('odbc_errormsg')) + { + return array( + 'message' => @odbc_errormsg(), + 'code' => @odbc_error() + ); + } + else + { + return array( + 'message' => $this->connect_error, + 'code' => '', + ); + } } /** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index ae36fe6425..7314e92087 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -439,10 +439,20 @@ class dbal_mysql extends dbal { if (!$this->db_connect_id) { - return array( - 'message' => @mysql_error(), - 'code' => @mysql_errno() - ); + if (function_exists('mysql_error')) + { + return array( + 'message' => @mysql_error(), + 'code' => @mysql_errno() + ); + } + else + { + return array( + 'message' => $this->connect_error, + 'code' => '', + ); + } } return array( diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 42f5de1b24..b234d8b45e 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -674,17 +674,27 @@ class dbal_oracle extends dbal */ function _sql_error() { - $error = @ocierror(); - $error = (!$error) ? @ocierror($this->query_result) : $error; - $error = (!$error) ? @ocierror($this->db_connect_id) : $error; - - if ($error) + if (function_exists('ocierror')) { - $this->last_error_result = $error; + $error = @ocierror(); + $error = (!$error) ? @ocierror($this->query_result) : $error; + $error = (!$error) ? @ocierror($this->db_connect_id) : $error; + + if ($error) + { + $this->last_error_result = $error; + } + else + { + $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + } } else { - $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + $error = array( + 'message' => $this->connect_error, + 'code' => '', + ); } return $error; diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index be0ad4fc8f..3c9b2cce34 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -300,10 +300,20 @@ class dbal_sqlite extends dbal */ function _sql_error() { - return array( - 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), - 'code' => @sqlite_last_error($this->db_connect_id) - ); + if (function_exists('sqlite_error_string')) + { + return array( + 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), + 'code' => @sqlite_last_error($this->db_connect_id) + ); + } + else + { + return array( + 'message' => $this->connect_error, + 'code' => '', + ); + } } /** From 4cc81f1ffa62cdbcbb656300c7dd9fbd44cc21fc Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:44:22 -0500 Subject: [PATCH 207/244] [ticket/10103] Correct flock class documentation. PHPBB3-10103 --- phpBB/includes/lock/flock.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index e24a5f3e1c..09450644bc 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -35,9 +35,9 @@ class phpbb_lock_flock private $lock_fp; /** - * Creates an instance of the lock. + * Constructor. * - * You have to call acquire() to actually create the lock. + * You have to call acquire() to actually acquire the lock. * * @param string $path Path to the file access to which is controlled */ @@ -50,8 +50,17 @@ class phpbb_lock_flock /** * Tries to acquire the lock. * - * As a lock may only be held by one process at a time, lock - * acquisition may fail if another process is holding the lock. + * If the lock is already held by another process, this call will block + * until the other process releases the lock. If a lock is acquired and + * is not released before script finishes but the process continues to + * live (apache/fastcgi) then subsequent processes trying to acquire + * the same lock will be blocked forever. + * + * If the lock is already held by the same process via another instance + * of this class, this call will block forever. + * + * If flock function is disabled in php or fails to work, lock + * acquisition will fail and false will be returned. * * @return bool true if lock was acquired * false otherwise From 3924676f2bd1a30ff56ab1db985cf622f1fac286 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:45:02 -0500 Subject: [PATCH 208/244] [ticket/10103] $rv had too few characters. PHPBB3-10103 --- phpBB/includes/cache/driver/file.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index ee1b430451..691abe0438 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -708,16 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); - $rv = true; + $return_value = true; } else { - $rv = false; + $return_value = false; } $lock->release(); - return $rv; + return $return_value; } /** From a553cfbc30472f136f9904d97bf4d09a7187518f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:46:01 -0500 Subject: [PATCH 209/244] [ticket/10103] Inline assignment is bad? PHPBB3-10103 --- tests/lock/flock_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index bc682f9410..abcb4e79c2 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -65,7 +65,8 @@ class phpbb_lock_flock_test extends phpbb_test_case $path = __DIR__ . '/../tmp/precious'; - if ($pid = pcntl_fork()) + $pid = pcntl_fork(); + if ($pid) { // parent // wait 0.5 s, acquire the lock, note how long it took From 285feb49f82084b5b489aa1fc6765b9b02ea1b29 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:47:57 -0500 Subject: [PATCH 210/244] [ticket/10103] assertLessThan/assertGreaterThan. PHPBB3-10103 --- tests/lock/flock_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index abcb4e79c2..8bb7d0a041 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -77,7 +77,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertTrue($delta > 0.5); + $this->assertGreaterThan(0.5, $delta); $lock->release(); @@ -86,7 +86,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertTrue($delta < 0.1); + $this->assertLessThan(0.1, $delta); // reap the child $status = null; From e22dd7dfadedd951d1fd17b61fa700c572ca4d79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:50:35 -0500 Subject: [PATCH 211/244] [ticket/10103] Assert with messages. PHPBB3-10103 --- tests/lock/flock_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 8bb7d0a041..1edc96b3a4 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -77,7 +77,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertGreaterThan(0.5, $delta); + $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); $lock->release(); @@ -86,7 +86,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertLessThan(0.1, $delta); + $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); // reap the child $status = null; From 4133fae99ec4146a01c67f6a6b3020020d1c6464 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:58:14 -0500 Subject: [PATCH 212/244] [ticket/10716] Only lint on php 5.3+. PHPBB3-10716 --- tests/lint_test.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/lint_test.php b/tests/lint_test.php index 57c78ae809..1642b571dd 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -11,6 +11,11 @@ class phpbb_lint_test extends phpbb_test_case { public function test_lint() { + if (version_compare(PHP_VERSION, '5.3.0', '<')) + { + $this->markTestSkipped('phpBB uses PHP 5.3 syntax in some files, linting on PHP < 5.3 will fail'); + } + $root = dirname(__FILE__) . '/..'; $this->check($root); } From 3e093c282a63df4d16b212859fd8137fd2bbca81 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 14:05:49 -0500 Subject: [PATCH 213/244] [ticket/10103] New and improved wording. PHPBB3-10103 --- phpBB/includes/lock/flock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index 09450644bc..5c2288ce1b 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) class phpbb_lock_flock { /** - * Path to the file access to which is controlled + * Path to the file to which access is controlled * * @var string */ @@ -39,7 +39,7 @@ class phpbb_lock_flock * * You have to call acquire() to actually acquire the lock. * - * @param string $path Path to the file access to which is controlled + * @param string $path Path to the file to which access is controlled */ public function __construct($path) { From 40db60e45f3d7af01a96f9da6b36db2606b3d147 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:07:02 -0500 Subject: [PATCH 214/244] [ticket/10205] Fix a parse error in oracle driver. PHPBB3-10205 --- phpBB/includes/db/oracle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index b234d8b45e..4a7a4ecc8c 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -74,7 +74,7 @@ class dbal_oracle extends dbal $this->connect_error = 'ocilogon function does not exist, is oci extension installed?'; return $this->sql_error(''); } - $this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8')); + $this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8'); } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); From de2fe1a308b08af868f22d6d9c0b7007f66de676 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:12:31 -0500 Subject: [PATCH 215/244] [ticket/10205] Convert mssqlnative driver to the same logic. PHPBB3-10205 --- phpBB/includes/db/mssqlnative.php | 52 +++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 3ad0ff3e11..e5de30faf6 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -199,16 +199,18 @@ class dbal_mssqlnative extends dbal var $m_insert_id = NULL; var $last_query_text = ''; var $query_options = array(); + var $connect_error = ''; /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { - # Test for driver support, to avoid suppressed fatal error + // Test for driver support, to avoid suppressed fatal error if (!function_exists('sqlsrv_connect')) { - trigger_error('Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx\n', E_USER_ERROR); + $this->connect_error = 'Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx'; + return $this->sql_error(''); } //set up connection variables @@ -514,31 +516,41 @@ class dbal_mssqlnative extends dbal */ function _sql_error() { - $errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS); - $error_message = ''; - $code = 0; - - if ($errors != null) + if (function_exists('sqlsrv_errors')) { - foreach ($errors as $error) + $errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS); + $error_message = ''; + $code = 0; + + if ($errors != null) { - $error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n"; - $error_message .= "code: ".$error[ 'code']."\n"; - $code = $error['code']; - $error_message .= "message: ".$error[ 'message']."\n"; + foreach ($errors as $error) + { + $error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n"; + $error_message .= "code: ".$error[ 'code']."\n"; + $code = $error['code']; + $error_message .= "message: ".$error[ 'message']."\n"; + } + $this->last_error_result = $error_message; + $error = $this->last_error_result; } - $this->last_error_result = $error_message; - $error = $this->last_error_result; + else + { + $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + } + + return array( + 'message' => $error, + 'code' => $code, + ); } else { - $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + return array( + 'message' => $this->connect_error, + 'code' => '', + ); } - - return array( - 'message' => $error, - 'code' => $code, - ); } /** From dc521692f3c6d65b842a42f68bc727c8a36c9042 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:14:39 -0500 Subject: [PATCH 216/244] [ticket/10205] Check for function existence in mssql connect method. PHPBB3-10205 --- phpBB/includes/db/mssql.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index bc0a870885..3792e82aa0 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -25,11 +25,19 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); */ class dbal_mssql extends dbal { + var $connect_error = ''; + /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { + if (!function_exists('mssql_connect')) + { + $this->connect_error = 'mssql_connect function does not exist, is mssql extension installed?'; + return $this->sql_error(''); + } + $this->persistency = $persistency; $this->user = $sqluser; $this->dbname = $database; From f3c043a5696610ed1312a734b3f3ed1b613fc4f4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:29:37 -0500 Subject: [PATCH 217/244] [ticket/10205] Test failed connection attempts. PHPBB3-10205 --- tests/dbal/connect_test.php | 44 +++++++++++++++++++++++++++++++++++++ tests/fixtures/empty.xml | 5 +++++ 2 files changed, 49 insertions(+) create mode 100644 tests/dbal/connect_test.php create mode 100644 tests/fixtures/empty.xml diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php new file mode 100644 index 0000000000..4964f24ba2 --- /dev/null +++ b/tests/dbal/connect_test.php @@ -0,0 +1,44 @@ +createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); + } + + public function test_failing_connect() + { + global $phpbb_root_path, $phpEx; + + $config = $this->get_database_config(); + + require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php'; + $dbal = 'dbal_' . $config['dbms']; + $db = new $dbal(); + + // Failure to connect results in a trigger_error call in dbal. + // phpunit converts triggered errors to exceptions. + // In particular there should be no fatals here. + try + { + $db->sql_connect($config['dbhost'], 'phpbbogus', 'phpbbogus', 'phpbbogus', $config['dbport']); + $this->assertFalse(true); + } catch (Exception $e) + { + // should have a legitimate message + $this->assertNotEmpty($e->getMessage()); + } + + return $db; + } +} diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml new file mode 100644 index 0000000000..96eb1ab483 --- /dev/null +++ b/tests/fixtures/empty.xml @@ -0,0 +1,5 @@ + + + +
        +
        From 2d3882c4124e928dccd050da3d3ccafa54b9ff20 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:32:57 -0500 Subject: [PATCH 218/244] [ticket/10205] Delete stray return. PHPBB3-10205 --- tests/dbal/connect_test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 4964f24ba2..cefd76aa16 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -38,7 +38,5 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case // should have a legitimate message $this->assertNotEmpty($e->getMessage()); } - - return $db; } } From 8897efe087195ba31920c6b3aadbe8ea1b393c12 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:42:58 -0500 Subject: [PATCH 219/244] [ticket/10716] Exclude our dependencies from linting. PHPBB3-10716 --- tests/lint_test.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/lint_test.php b/tests/lint_test.php index 1642b571dd..67b7413cb4 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -9,6 +9,17 @@ class phpbb_lint_test extends phpbb_test_case { + static protected $exclude; + + static public function setUpBeforeClass() + { + self::$exclude = array( + // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 + // https://gist.github.com/e003913ffd493da63cbc + dirname(__FILE__) . '/../phpBB/vendor', + ); + } + public function test_lint() { if (version_compare(PHP_VERSION, '5.3.0', '<')) @@ -35,7 +46,7 @@ class phpbb_lint_test extends phpbb_test_case { continue; } - if (is_dir($path)) + if (is_dir($path) && !in_array($path, self::$exclude)) { $this->check($path); } From 8ea52b56197cc9a234d6b0ce3ddd10820feb6dd1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 17:43:36 -0500 Subject: [PATCH 220/244] [ticket/10716] Skip test if php is not in PATH. PHPBB3-10716 --- tests/lint_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lint_test.php b/tests/lint_test.php index 67b7413cb4..d73ab7fedd 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -13,6 +13,14 @@ class phpbb_lint_test extends phpbb_test_case static public function setUpBeforeClass() { + $output = array(); + $status = 1; + exec('php -v', $output, $status); + if ($status) + { + self::markTestSkipped("php is not in PATH or broken: $output"); + } + self::$exclude = array( // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 // https://gist.github.com/e003913ffd493da63cbc From fb261e19ffc3bf19477510fa3877a8d9ea251655 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 18:52:27 -0500 Subject: [PATCH 221/244] [ticket/10716] Collect standard error from executed php process. php executes everything via a shell. The standard error of this top level shell is not captured by exec/shell_exec/popen/etc. and there is no way to capture it. proc_open might work but it is a nightmare to use and without multiplexing reads from standard error and standard output it can deadlock. Thus the solution in this commit. Put the command into a subshell and redirect standard error to standard output for the subshell. PHPBB3-10716 --- tests/lint_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lint_test.php b/tests/lint_test.php index d73ab7fedd..905067072d 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -15,9 +15,10 @@ class phpbb_lint_test extends phpbb_test_case { $output = array(); $status = 1; - exec('php -v', $output, $status); + exec('(php -v) 2>&1', $output, $status); if ($status) { + $output = implode("\n", $output); self::markTestSkipped("php is not in PATH or broken: $output"); } @@ -61,7 +62,7 @@ class phpbb_lint_test extends phpbb_test_case else if (substr($filename, strlen($filename)-4) == '.php') { // assume php binary is called php and it is in PATH - $cmd = 'php -l ' . escapeshellarg($path); + $cmd = '(php -l ' . escapeshellarg($path) . ') 2>&1'; $output = array(); $status = 1; exec($cmd, $output, $status); From 29c4da6162902d3c0d766a8acb17e5a2cf02f901 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 19:00:42 -0500 Subject: [PATCH 222/244] [ticket/10205] Add some columns to the empty fixture file for mssqlnative. Supposedly it choked on the version without any columns thusly: phpbb_dbal_connect_test::test_failing_connect PDOException: SQLSTATE[HY090]: [Microsoft][ODBC Driver Manager] Invalid string or buffer length PHPBB3-10205 --- tests/fixtures/empty.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml index 96eb1ab483..195e30e38d 100644 --- a/tests/fixtures/empty.xml +++ b/tests/fixtures/empty.xml @@ -1,5 +1,9 @@ - +
        + session_id + session_user_id + session_ip + session_browser
        From 89c9c9d4b0daa7308fd015e8a6fca6386a8b8016 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 21:22:33 -0500 Subject: [PATCH 223/244] [ticket/10205] Cosmetic changes. PHPBB3-10205 --- phpBB/includes/db/mssql.php | 2 +- phpBB/includes/db/mssql_odbc.php | 2 +- phpBB/includes/db/mssqlnative.php | 6 +++--- phpBB/includes/db/mysql.php | 4 ++-- phpBB/includes/db/sqlite.php | 2 +- tests/dbal/connect_test.php | 3 ++- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 3792e82aa0..2dd95c2508 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -367,7 +367,7 @@ class dbal_mssql extends dbal { $error = array( 'message' => @mssql_get_last_message(), - 'code' => '' + 'code' => '', ); // Get error code number diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index e1234389df..47792d74ab 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -364,7 +364,7 @@ class dbal_mssql_odbc extends dbal { return array( 'message' => @odbc_errormsg(), - 'code' => @odbc_error() + 'code' => @odbc_error(), ); } else diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index e5de30faf6..41ac0a1784 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -526,10 +526,10 @@ class dbal_mssqlnative extends dbal { foreach ($errors as $error) { - $error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n"; - $error_message .= "code: ".$error[ 'code']."\n"; + $error_message .= "SQLSTATE: " . $error[ 'SQLSTATE'] . "\n"; + $error_message .= "code: " . $error[ 'code'] . "\n"; $code = $error['code']; - $error_message .= "message: ".$error[ 'message']."\n"; + $error_message .= "message: " . $error[ 'message'] . "\n"; } $this->last_error_result = $error_message; $error = $this->last_error_result; diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 7314e92087..0125be0917 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -443,7 +443,7 @@ class dbal_mysql extends dbal { return array( 'message' => @mysql_error(), - 'code' => @mysql_errno() + 'code' => @mysql_errno(), ); } else @@ -457,7 +457,7 @@ class dbal_mysql extends dbal return array( 'message' => @mysql_error($this->db_connect_id), - 'code' => @mysql_errno($this->db_connect_id) + 'code' => @mysql_errno($this->db_connect_id), ); } diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 3c9b2cce34..199b4eed23 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -304,7 +304,7 @@ class dbal_sqlite extends dbal { return array( 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), - 'code' => @sqlite_last_error($this->db_connect_id) + 'code' => @sqlite_last_error($this->db_connect_id), ); } else diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index cefd76aa16..505ce28fa1 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -33,7 +33,8 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case { $db->sql_connect($config['dbhost'], 'phpbbogus', 'phpbbogus', 'phpbbogus', $config['dbport']); $this->assertFalse(true); - } catch (Exception $e) + } + catch (Exception $e) { // should have a legitimate message $this->assertNotEmpty($e->getMessage()); From 597dea1e047b94f0a862f7f6e650771ffc780141 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 21:32:02 -0500 Subject: [PATCH 224/244] [ticket/10205] Rewrite _sql_error implementations to have a single return. PHPBB3-10205 --- phpBB/includes/db/mssql_odbc.php | 6 ++++-- phpBB/includes/db/mssqlnative.php | 6 ++++-- phpBB/includes/db/mysql.php | 18 +++++++++++------- phpBB/includes/db/mysqli.php | 18 +++++++++++------- phpBB/includes/db/sqlite.php | 6 ++++-- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 47792d74ab..04501cce8b 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -362,18 +362,20 @@ class dbal_mssql_odbc extends dbal { if (function_exists('odbc_errormsg')) { - return array( + $error = array( 'message' => @odbc_errormsg(), 'code' => @odbc_error(), ); } else { - return array( + $error = array( 'message' => $this->connect_error, 'code' => '', ); } + + return $error; } /** diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 41ac0a1784..b91372ac61 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -539,18 +539,20 @@ class dbal_mssqlnative extends dbal $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); } - return array( + $error = array( 'message' => $error, 'code' => $code, ); } else { - return array( + $error = array( 'message' => $this->connect_error, 'code' => '', ); } + + return $error; } /** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 0125be0917..e638531f51 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -437,28 +437,32 @@ class dbal_mysql extends dbal */ function _sql_error() { - if (!$this->db_connect_id) + if ($this->db_connect_id) + { + $error = array( + 'message' => @mysql_error($this->db_connect_id), + 'code' => @mysql_errno($this->db_connect_id), + ); + } + else { if (function_exists('mysql_error')) { - return array( + $error = array( 'message' => @mysql_error(), 'code' => @mysql_errno(), ); } else { - return array( + $error = array( 'message' => $this->connect_error, 'code' => '', ); } } - return array( - 'message' => @mysql_error($this->db_connect_id), - 'code' => @mysql_errno($this->db_connect_id), - ); + return $error; } /** diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index cd82a12b58..b2a43d35f9 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -423,28 +423,32 @@ class dbal_mysqli extends dbal */ function _sql_error() { - if (!$this->db_connect_id) + if ($this->db_connect_id) + { + $error = array( + 'message' => @mysqli_error($this->db_connect_id), + 'code' => @mysqli_errno($this->db_connect_id) + ); + } + else { if (function_exists('mysqli_connect_error')) { - return array( + $error = array( 'message' => @mysqli_connect_error(), 'code' => @mysqli_connect_errno(), ); } else { - return array( + $error = array( 'message' => $this->connect_error, 'code' => '', ); } } - return array( - 'message' => @mysqli_error($this->db_connect_id), - 'code' => @mysqli_errno($this->db_connect_id) - ); + return $error; } /** diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 199b4eed23..557b057cce 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -302,18 +302,20 @@ class dbal_sqlite extends dbal { if (function_exists('sqlite_error_string')) { - return array( + $error = array( 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), 'code' => @sqlite_last_error($this->db_connect_id), ); } else { - return array( + $error = array( 'message' => $this->connect_error, 'code' => '', ); } + + return $error; } /** From 5120f36a258ffcbffd5c10e9a1056d64ea794a16 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 21:33:13 -0500 Subject: [PATCH 225/244] [ticket/10205] Reduce nesting in mysql drivers. PHPBB3-10205 --- phpBB/includes/db/mysql.php | 25 +++++++++++-------------- phpBB/includes/db/mysqli.php | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index e638531f51..252cb20bd4 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -444,22 +444,19 @@ class dbal_mysql extends dbal 'code' => @mysql_errno($this->db_connect_id), ); } + else if (function_exists('mysql_error')) + { + $error = array( + 'message' => @mysql_error(), + 'code' => @mysql_errno(), + ); + } else { - if (function_exists('mysql_error')) - { - $error = array( - 'message' => @mysql_error(), - 'code' => @mysql_errno(), - ); - } - else - { - $error = array( - 'message' => $this->connect_error, - 'code' => '', - ); - } + $error = array( + 'message' => $this->connect_error, + 'code' => '', + ); } return $error; diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index b2a43d35f9..69f1d26a40 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -430,22 +430,19 @@ class dbal_mysqli extends dbal 'code' => @mysqli_errno($this->db_connect_id) ); } + else if (function_exists('mysqli_connect_error')) + { + $error = array( + 'message' => @mysqli_connect_error(), + 'code' => @mysqli_connect_errno(), + ); + } else { - if (function_exists('mysqli_connect_error')) - { - $error = array( - 'message' => @mysqli_connect_error(), - 'code' => @mysqli_connect_errno(), - ); - } - else - { - $error = array( - 'message' => $this->connect_error, - 'code' => '', - ); - } + $error = array( + 'message' => $this->connect_error, + 'code' => '', + ); } return $error; From 03f819862f15efa2ef64331b23394086746d09be Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:41:47 -0500 Subject: [PATCH 226/244] [ticket/10602] Use last_queue_run for its intended purpose. We keep the last queue run time around, therefore for determining whether enough time has passed since the last run we can simply use this config variable. When there is no queue file we consider a queue run successful. Previously queue.php ("cache file") modification time would be used for determining whether enough time has passed since last queue run. The problem was that modification time would be updated whenever anything was added to the queue, creating a situation where if queue is processed less frequently than it is added to that email would not be sent. PHPBB3-10602 --- phpBB/includes/functions_messenger.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 6549693333..ae0f7823cc 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -715,14 +715,19 @@ class queue $lock_fp = $this->lock(); - set_config('last_queue_run', time(), true); - - if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) + if (!file_exists($this->cache_file) || $config['last_queue_run'] > time() - $config['queue_interval']) { + if (!file_exists($this->cache_file)) + { + set_config('last_queue_run', time(), true); + } + $this->unlock($lock_fp); return; } + set_config('last_queue_run', time(), true); + include($this->cache_file); foreach ($this->queue_data as $object => $data_ary) From 1e50116c54ec7ffbaba4622d5481207423ef2bbe Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:57:24 -0500 Subject: [PATCH 227/244] [ticket/10602] Avoid a race condition. PHPBB3-10602 --- phpBB/includes/functions_messenger.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index ae0f7823cc..e837811c86 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -715,9 +715,11 @@ class queue $lock_fp = $this->lock(); - if (!file_exists($this->cache_file) || $config['last_queue_run'] > time() - $config['queue_interval']) + // avoid races, check file existence once + $have_cache_file = file_exists($this->cache_file); + if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) { - if (!file_exists($this->cache_file)) + if (!$have_cache_file) { set_config('last_queue_run', time(), true); } From a8d02ffc27d8cee916f267c91488276fca3606e7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 01:54:29 -0500 Subject: [PATCH 228/244] [ticket/11247] Fix wrong property reference in flock class. PHPBB3-11247 --- phpBB/includes/lock/flock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index 5c2288ce1b..97bc7dd2b9 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -67,7 +67,7 @@ class phpbb_lock_flock */ public function acquire() { - if ($this->locked) + if ($this->lock_fp) { return false; } From af064cdaad357f705fc7c80f4d018d57cffa8d33 Mon Sep 17 00:00:00 2001 From: Senky Date: Wed, 16 May 2012 23:02:20 +0200 Subject: [PATCH 229/244] [ticket/10841] Modifying style and language selectors in UCP Commit also deletes all unnecessary blank spaces at the end of the lines in both ucp_prefs_personal.html PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 30 +++++++++++++ .../template/ucp_prefs_personal.html | 42 ++++++++++--------- .../template/ucp_prefs_personal.html | 18 ++++---- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 17d7d23f02..19e1b45787 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -134,6 +134,33 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; + // check for count of installed languages + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE; + $result = $db->sql_query($sql); + if( $db->sql_affectedrows() > 1 ) + { + $s_more_languages = true; + } + else + { + $s_more_languages = false; + } + + // check for count of installed and active styles + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 1'; + $result = $db->sql_query($sql); + if( $db->sql_affectedrows() > 1 ) + { + $s_more_styles = true; + } + else + { + $s_more_styles = false; + } + $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
        ', $error) : '', @@ -155,6 +182,9 @@ class ucp_prefs 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), + 'S_MORE_LANGUAGES' => $s_more_languages, + 'S_MORE_STYLES' => $s_more_styles, + 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), 'S_TZ_OPTIONS' => tz_select($data['tz'], true), diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 9022346627..416343e57d 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -12,21 +12,21 @@
        - +
        - +

        {L_ALLOW_PM_EXPLAIN}
        - +
        @@ -34,17 +34,17 @@

        {L_HIDE_ONLINE_EXPLAIN}
        - +
        - +
        - - + +
        @@ -52,22 +52,24 @@
        - +
        - +
        -
        -
        -
        -
        - + +
        +
        +
        +
        + +
        @@ -80,7 +82,7 @@
        - +
        @@ -97,9 +99,9 @@ - +
        - {S_HIDDEN_FIELDS}  + {S_HIDDEN_FIELDS}  {S_FORM_TOKEN}
        @@ -113,9 +115,9 @@ function customDates() { var e = document.getElementById('dateoptions'); - + e.selectedIndex = e.length - 1; - + // Loop and match date_format in menu for (var i = 0; i < e.length; i++) { @@ -125,7 +127,7 @@ break; } } - + // Show/hide custom field if (e.selectedIndex == e.length - 1) { diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index e2266b7d38..c604671c5c 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -29,43 +29,45 @@
  • {ERROR}
    {L_SHOW_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_ADMIN_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_ALLOW_PM}:
    {L_ALLOW_PM_EXPLAIN}
    checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_HIDE_ONLINE}:
    {L_HIDE_ONLINE_EXPLAIN}
    checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_NOTIFY_METHOD}:
    {L_NOTIFY_METHOD_EXPLAIN}
    checked="checked" />{L_NOTIFY_METHOD_EMAIL}   checked="checked" />{L_NOTIFY_METHOD_IM}   checked="checked" />{L_NOTIFY_METHOD_BOTH}
    {L_NOTIFY_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_POPUP_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_BOARD_LANGUAGE}:
    {L_BOARD_STYLE}: {ERROR}
    {L_SHOW_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_ADMIN_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_ALLOW_PM}:
    {L_ALLOW_PM_EXPLAIN}
    checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_HIDE_ONLINE}:
    {L_HIDE_ONLINE_EXPLAIN}
    checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_NOTIFY_METHOD}:
    {L_NOTIFY_METHOD_EXPLAIN}
    checked="checked" />{L_NOTIFY_METHOD_EMAIL}   checked="checked" />{L_NOTIFY_METHOD_IM}   checked="checked" />{L_NOTIFY_METHOD_BOTH}
    {L_NOTIFY_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO}
    {L_POPUP_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO}