diff --git a/config/services.yml b/config/services.yml index 629f6656..9e3a7aab 100644 --- a/config/services.yml +++ b/config/services.yml @@ -103,5 +103,11 @@ services: - @dbal.conn - @board3.portal.columns - @board3.portal.helper + - @board.portal.modules.database_handler - @request - @user + + board.portal.modules.database_handler: + class: board3\portal\portal\modules\database_handler + arguments: + - @dbal.conn diff --git a/portal/modules/database_handler.php b/portal/modules/database_handler.php new file mode 100644 index 00000000..3cada002 --- /dev/null +++ b/portal/modules/database_handler.php @@ -0,0 +1,47 @@ +db = $db; + } + + /** + * Get module data from database + * + * @param int $module_id Module ID + * @return array Module data array + */ + public function get_module_data($module_id) + { + $sql = 'SELECT * + FROM ' . PORTAL_MODULES_TABLE . ' + WHERE module_id = ' . (int) $module_id; + $result = $this->db->sql_query_limit($sql, 1); + $module_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return $module_data; + } +} diff --git a/portal/modules/manager.php b/portal/modules/manager.php index bb89a672..210f11c1 100644 --- a/portal/modules/manager.php +++ b/portal/modules/manager.php @@ -25,6 +25,9 @@ class manager /** @var \board3\portal\includes\helper */ protected $portal_helper; + /** @var \board3\portal\portal\modules\database_handler */ + protected $database_handler; + /** @var \phpbb\db\driver\driver_interface */ protected $db; @@ -53,15 +56,17 @@ class manager * @param \phpbb\db\driver\driver_interface $db Database driver * @param \board3\portal\portal\columns $portal_columns Portal columns helper * @param \board3\portal\includes\helper $portal_helper Portal helper + * @param \board3\portal\portal\modules\database_handler $database_handler Modules database handler * @param \phpbb\request\request_interface $request phpBB request * @param \phpbb\user $user phpBB user */ - public function __construct($cache, driver_interface $db, columns $portal_columns, helper $portal_helper, request_interface $request, $user) + public function __construct($cache, driver_interface $db, columns $portal_columns, helper $portal_helper, database_handler $database_handler, request_interface $request, $user) { $this->cache = $cache; $this->db = $db; $this->portal_columns = $portal_columns; $this->portal_helper = $portal_helper; + $this->database_handler = $database_handler; $this->request = $request; $this->user = $user; } @@ -176,14 +181,7 @@ class manager */ public function get_move_module_data($module_id) { - $sql = 'SELECT * - FROM ' . PORTAL_MODULES_TABLE . ' - WHERE module_id = ' . (int) $module_id; - $result = $this->db->sql_query_limit($sql, 1); - $module_data = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - return $module_data; + return $this->database_handler->get_module_data($module_id); } /** diff --git a/tests/unit/acp/move_module_test.php b/tests/unit/acp/move_module_test.php index cdda6afd..28a1e074 100644 --- a/tests/unit/acp/move_module_test.php +++ b/tests/unit/acp/move_module_test.php @@ -71,7 +71,8 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', )); - $this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $request, $user); + $this->database_handler = new \board3\portal\portal\modules\database_handler($db); + $this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $this->database_handler, $request, $user); $phpbb_container->set('board3.portal.modules.manager', $this->modules_manager); $this->portal_module = new \board3\portal\acp\portal_module(); $this->update_portal_modules();