From 81a83e6f9ed5e697ec2f26a3ca6ad66e5b8b7748 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Feb 2014 00:13:40 +0100 Subject: [PATCH 1/3] [ticket/208] Move includes files out of portal folder into includes The includes files were inside a portal folder until now. This is no longer needed with the extension. B3P-208 --- {portal/includes => includes}/constants.php | 0 {portal/includes => includes}/functions.php | 123 ------------------ .../functions_modules.php | 0 .../functions_upload.php | 0 portal/includes/index.html | 7 - 5 files changed, 130 deletions(-) rename {portal/includes => includes}/constants.php (100%) rename {portal/includes => includes}/functions.php (85%) rename {portal/includes => includes}/functions_modules.php (100%) rename {portal/includes => includes}/functions_upload.php (100%) delete mode 100644 portal/includes/index.html diff --git a/portal/includes/constants.php b/includes/constants.php similarity index 100% rename from portal/includes/constants.php rename to includes/constants.php diff --git a/portal/includes/functions.php b/includes/functions.php similarity index 85% rename from portal/includes/functions.php rename to includes/functions.php index 79300c3b..f73f0264 100644 --- a/portal/includes/functions.php +++ b/includes/functions.php @@ -694,129 +694,6 @@ function get_portal_tracking_info($fetch_news) return $last_read; } -/** -* This function will install the basic set of portal modules -* -* only set $purge_modules to false if you already know that the table is empty -* set $u_action to where the user should be redirected after this -* note that already existing data won't be deleted from the config and portal_config -* just to make sure we don't overwrite anything, the IDs won't be reset -* !! this function should usually only be executed once upon installing the portal !! -* DO NOT set $purge_modules to false unless you want to auto-add all modules again after deleting them (i.e. if your database was corrupted) -*/ -function board3_basic_install($mode = 'install', $purge_modules = true, $u_action = '') -{ - global $db, $phpbb_root_path, $phpEx, $cache, $user, $table_prefix, $config; - - // Shouldn't happen but we should check this nonetheless - if (!defined('PORTAL_MODULES_TABLE')) - { - include($phpbb_root_path . 'portal/includes/constants.' . $phpEx); - } - - if ($mode == 'install') - { - $directory = $phpbb_root_path . 'portal/modules/'; - - if ($purge_modules) - { - $sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE; - $result = $db->sql_query($sql); - $db->sql_freeresult($result); - } - - /* - * this is a list of the basic modules that will be installed - * module_name => array(module_column, module_order) - */ - $modules_ary = array( - // left column - 'portal_main_menu' => array(1, 1), - 'portal_stylechanger' => array(1, 2), - 'portal_birthday_list' => array(1, 3), - 'portal_clock' => array(1, 4), - 'portal_search' => array(1, 5), - 'portal_attachments' => array(1, 7), - 'portal_topposters' => array(1, 8), - 'portal_latest_members' => array(1, 9), - 'portal_link_us' => array(1, 10), - - // center column - 'portal_welcome' => array(2, 1), - 'portal_recent' => array(2, 2), - 'portal_announcements' => array(2, 3), - 'portal_news' => array(2, 4), - 'portal_poll' => array(2, 5), - 'portal_whois_online' => array(2, 6), - - // right column - 'portal_user_menu' => array(3, 1), - 'portal_statistics' => array(3, 2), - 'portal_calendar' => array(3, 3), - 'portal_leaders' => array(3, 4), - 'portal_latest_bots' => array(3, 5), - 'portal_links' => array(3, 6), - ); - - foreach ($modules_ary as $module_name => $module_data) - { - $class_name = $module_name . '_module'; - if (!class_exists($class_name)) - { - include($directory . $module_name . '.' . $phpEx); - } - if (!class_exists($class_name)) - { - trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); - } - - $c_class = new $class_name(); - - $sql_ary = array( - 'module_classname' => substr($module_name, 7), - 'module_column' => $module_data[0], - 'module_order' => $module_data[1], - 'module_name' => $c_class->name, - 'module_image_src' => $c_class->image_src, - 'module_group_ids' => '', - 'module_image_width' => 16, - 'module_image_height' => 16, - 'module_status' => B3_MODULE_ENABLED, - ); - $sql = 'INSERT INTO ' . PORTAL_MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - $c_class->install($db->sql_nextid()); - } - - // Make sure we get rid of old data - $cache->destroy('portal_modules'); - - return $user->lang['PORTAL_BASIC_INSTALL']; - } - else - { - $skip_entries = array( - 'board3_right_column_width', - 'board3_left_column_width', - 'board3_forum_index', - 'board3_version_check', - 'board3_right_column', - 'board3_left_column', - 'board3_enable', - 'board3_portal_version', - 'board3_phpbb_menu', - 'board3_display_jumpbox', - ); - $sql = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE config_name ' . $db->sql_like_expression(utf8_clean_string('board3_') . $db->any_char) . ' - AND ' . $db->sql_in_set('config_name', $skip_entries, true); - $db->sql_query($sql); - - return $user->lang['PORTAL_BASIC_UNINSTALL']; - } -} - - /** * check if the entered source file actually exists */ diff --git a/portal/includes/functions_modules.php b/includes/functions_modules.php similarity index 100% rename from portal/includes/functions_modules.php rename to includes/functions_modules.php diff --git a/portal/includes/functions_upload.php b/includes/functions_upload.php similarity index 100% rename from portal/includes/functions_upload.php rename to includes/functions_upload.php diff --git a/portal/includes/index.html b/portal/includes/index.html deleted file mode 100644 index dc8f7f41..00000000 --- a/portal/includes/index.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file From c873fd768c1996296ad87ead181f21590a44eb49 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Feb 2014 00:14:59 +0100 Subject: [PATCH 2/3] [ticket/208] Fix paths after moving includes files B3P-208 --- acp/portal_module.php | 14 ++++++-------- controller/main.php | 8 ++++---- modules/announcements.php | 2 +- modules/news.php | 2 +- tests/functions/check_file_src_test.php | 2 +- tests/functions/simple_test.php | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/acp/portal_module.php b/acp/portal_module.php index 277416c8..d936b8d9 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -22,7 +22,7 @@ class portal_module public $u_action; public $new_config = array(); protected $c_class; - protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; + protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; protected $root_path, $mod_version_check, $request; /** @var \phpbb\di\service_collection Portal modules */ @@ -31,14 +31,13 @@ class portal_module public function __construct() { global $db, $user, $cache, $request, $template; - global $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpbb_container, $phpEx; + global $config, $phpbb_root_path, $phpbb_admin_path, $phpbb_container, $phpEx; $user->add_lang_ext('board3/portal', 'portal'); $this->root_path = $phpbb_root_path . 'ext/board3/portal/'; - include($this->root_path . 'portal/includes/constants.' . $phpEx); - $portal_root_path = PORTAL_ROOT_PATH; + include($this->root_path . 'includes/constants.' . $phpEx); $this->db = $db; $this->user = $user; @@ -48,7 +47,6 @@ class portal_module $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; $this->phpbb_admin_path = $phpbb_admin_path; - $this->portal_root_path = $this->root_path . 'portal/'; $this->php_ex = $phpEx; $this->phpbb_container = $phpbb_container; $this->mod_version_check = $this->phpbb_container->get('board3.version.check'); @@ -56,12 +54,12 @@ class portal_module if (!function_exists('column_string_const')) { - include($this->portal_root_path . 'includes/functions_modules.' . $this->php_ex); + include($this->root_path . 'includes/functions_modules.' . $this->php_ex); } if(!function_exists('obtain_portal_config')) { - include($this->portal_root_path . 'includes/functions.' . $this->php_ex); + include($this->root_path . 'includes/functions.' . $this->php_ex); } } @@ -722,7 +720,7 @@ class portal_module { trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } - include($this->root_path . 'portal/includes/functions_upload.' . $this->php_ex); + include($this->root_path . 'includes/functions_upload.' . $this->php_ex); // Default upload path is portal/upload/ $upload_path = $this->root_path . 'portal/upload/'; diff --git a/controller/main.php b/controller/main.php index 0f35f4ba..95037077 100644 --- a/controller/main.php +++ b/controller/main.php @@ -98,15 +98,15 @@ class main $this->php_ext = $php_ext; $this->register_modules($modules); - $this->includes_path = $phpbb_root_path . 'ext/board3/portal/portal/'; + $this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/'; $this->root_path = $phpbb_root_path . 'ext/board3/portal/'; $portal_root_path = $this->root_path; if (!function_exists('obtain_portal_config')) { - include($this->includes_path . 'includes/constants' . $this->php_ext); - include($this->includes_path . 'includes/functions_modules' . $this->php_ext); - include($this->includes_path . 'includes/functions' . $this->php_ext); + include($this->includes_path . 'constants' . $this->php_ext); + include($this->includes_path . 'functions_modules' . $this->php_ext); + include($this->includes_path . 'functions' . $this->php_ext); } } diff --git a/modules/announcements.php b/modules/announcements.php index 6ecd405c..2f8b86c6 100644 --- a/modules/announcements.php +++ b/modules/announcements.php @@ -109,7 +109,7 @@ class announcements extends module_base $start = $this->request->variable('ap', 0); $start = ($start < 0) ? 0 : $start; - // Fetch announcements from portal/includes/functions.php with check if "read full" is requested. + // Fetch announcements from porta functions.php with check if "read full" is requested. $portal_announcement_length = ($announcement < 0) ? $this->config['board3_announcements_length_' . $module_id] : 0; $fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_global_announcements_forum_' . $module_id], $this->config['board3_announcements_permissions_' . $module_id], $this->config['board3_number_of_announcements_' . $module_id], $portal_announcement_length, $this->config['board3_announcements_day_' . $module_id], 'announcements', $start, $this->config['board3_announcements_forum_exclude_' . $module_id]); diff --git a/modules/news.php b/modules/news.php index 0aeeeee4..cbf67075 100644 --- a/modules/news.php +++ b/modules/news.php @@ -110,7 +110,7 @@ class news extends module_base $start = $this->request->variable('np', 0); $start = ($start < 0) ? 0 : $start; - // Fetch news from portal/includes/functions.php with check if "read full" is requested. + // Fetch news from portal functions.php with check if "read full" is requested. $portal_news_length = ($news < 0) ? $this->config['board3_news_length_' . $module_id] : 0; $fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $start, $this->config['board3_news_exclude_' . $module_id]); diff --git a/tests/functions/check_file_src_test.php b/tests/functions/check_file_src_test.php index b122ca78..32f0e47a 100644 --- a/tests/functions/check_file_src_test.php +++ b/tests/functions/check_file_src_test.php @@ -7,7 +7,7 @@ * */ -require_once(dirname(__FILE__) . '/../../portal/includes/functions.php'); +require_once(dirname(__FILE__) . '/../../includes/functions.php'); require_once(dirname(__FILE__) . '/../../../../../includes/functions_acp.php'); class phpbb_functions_check_file_src_test extends \board3\portal\tests\testframework\database_test_case diff --git a/tests/functions/simple_test.php b/tests/functions/simple_test.php index 7eb12f24..87896847 100644 --- a/tests/functions/simple_test.php +++ b/tests/functions/simple_test.php @@ -7,7 +7,7 @@ * */ -require_once(dirname(__FILE__) . '/../../portal/includes/functions.php'); +require_once(dirname(__FILE__) . '/../../includes/functions.php'); class phpbb_functions_simple_test extends PHPUnit_Framework_TestCase { From fb7871cb8793bf1e0ec8a114346aa92d6afbc960 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Feb 2014 00:35:12 +0100 Subject: [PATCH 3/3] [ticket/208] Make sure functional tests only try to enable portal once Until now, the portal would access the acp page for enabling it every time a functional test is run. This change will make sure that this happens only once and therefore slightly speeds up functional tests. B3P-208 --- tests/testframework/functional_test_case.php | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/testframework/functional_test_case.php b/tests/testframework/functional_test_case.php index 09d3037d..dee5532f 100644 --- a/tests/testframework/functional_test_case.php +++ b/tests/testframework/functional_test_case.php @@ -17,7 +17,7 @@ abstract class functional_test_case extends \phpbb_functional_test_case { $enable_portal = false; - if ($this->portal_enabled === true) + if ($this->portal_enabled === true || $this->check_if_enabled()) { return; } @@ -39,6 +39,27 @@ abstract class functional_test_case extends \phpbb_functional_test_case $crawler = self::submit($form); $this->assertContains('The extension was enabled successfully', $crawler->text()); $this->portal_enabled = true; + $this->set_enabled(); } } + + protected function check_if_enabled() + { + $this->db = $this->get_db(); + + $sql = "SELECT config_value FROM phpbb_config WHERE config_name = 'b3p_ext_enabled'"; + $result = $this->db->sql_query($sql); + $enabled = $this->db->sql_fetchfield('config_value'); + $this->db->sql_freeresult($result); + + return $enabled; + } + + protected function set_enabled() + { + $this->db = $this->get_db(); + + $sql = "INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('b3p_ext_enabled', 1, 1)"; + $this->db->sql_query($sql); + } }